vts动态配置
1.依赖模块
njet_ctrl.conf:
load_module modules/njt_http_vtsc_module.so;
njet.conf:
load_module modules/njt_http_vtsd_module.so;
2.指令说明
动态配置无特殊的指令。
3.配置说明
主要配置示例
load_module modules/njt_http_vtsc_module.so;
helper ctrl modules/njt_helper_ctrl_module.so conf/njet_ctrl.conf;
helper broker modules/njt_helper_broker_module.so conf/mqtt.conf;
worker_processes 1;
error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
dyn_kv_conf conf/iot.conf;
access_log logs/access.log combined;
variables_hash_max_size 2048;
proxy_cache_path cache levels=1:2 keys_zone=cache:20m max_size=1g inactive=30d use_temp_path=off;
proxy_cache_valid any 10m ;
proxy_cache_revalidate on;
proxy_cache_lock on;
proxy_cache_key $scheme$host$request_uri$slice_range;
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_set_key "$request_uri" "$server_name";
upstream backgroup {
zone backcenter 128k;
server 192.168.30.222:80;
}
upstream errgroup {
zone backcenter 128k;
server 192.168.40.108:28000;
}
server {
listen 8081;
server_name server1;
server_name server11;
location / {
add_header x-Cache-Status $upstream_cache_status;
add_header x-Cache-Key $scheme$host$request_uri$slice_range;
proxy_cache cache;
proxy_pass http://backgroup;
}
location /a {
return 200 "welcome to 8081 http server a\n";
}
}
server {
listen 8082;
server_name server2;
location / {
proxy_pass http://errgroup;
}
location /c {
root html;
index index.html;
}
location /d {
root html;
index index.html;
}
}
server {
listen 8083;
server_name server3;
location / {
root html;
index index.html;
}
location /a {
root html;
index index.html;
}
location /b {
root html;
index index.html;
}
}
}
4.API
4.1 API 列表
查询接口
curl -X GET http://IP+port/api/v1/config/http_vts
修改接口
curl PUT http://IP+port/api/v1/config/http_vts
4.2 调用样例
4.2.1 GET 查询vts 当前配置
使用GET方法获取当前VTS模块的设置,使用PUT 方法更新VTS模块的设置。 PUT时使用的报文格式与GET获取到的报文格式一致。
查询当前VTS模块的配置:
curl -X GET http://127.0.0.1:8443/api/v1/config/http_vts
返回:
{
"vhost_traffic_status_filter_by_set_key": "\"$request_uri\" \"$server_name\"",
"servers": [
{
"listens": [
"0.0.0.0:8081"
],
"serverNames": [
"server1",
"server11"
],
"locations": [
{
"location": "/",
"vhost_traffic_status": true
},
{
"location": "/a",
"vhost_traffic_status": true
}
]
},
{
"listens": [
"0.0.0.0:8082"
],
"serverNames": [
"server2"
],
"locations": [
{
"location": "/",
"vhost_traffic_status": true
},
{
"location": "/c",
"vhost_traffic_status": true
},
{
"location": "/d",
"vhost_traffic_status": true
}
]
},
{
"listens": [
"0.0.0.0:8083"
],
"serverNames": [
"server3"
],
"locations": [
{
"location": "/",
"vhost_traffic_status": true
},
{
"location": "/a",
"vhost_traffic_status": true
},
{
"location": "/b",
"vhost_traffic_status": true
}
]
}
]
}
4.2.2 更新当前的配置:
PUT http://127.0.0.1/api/v1/config/http_vts HTTP/1.1
content-type: application/json
{
"vhost_traffic_status_filter_by_set_key": "\"$status\" \"$server_name::$request_uri\"",
"servers": [
{
"listens": [
"0.0.0.0:8081"
],
"serverNames": [
"server1",
"server11"
],
"locations": [
{
"location": "/",
"vhost_traffic_status": true
},
{
"location": "/a",
"vhost_traffic_status": false
}
]
},
{
"listens": [
"0.0.0.0:8082"
],
"serverNames": [
"server2"
],
"locations": [
{
"location": "/",
"vhost_traffic_status": true
},
{
"location": "/c",
"vhost_traffic_status": true
},
{
"location": "/d",
"vhost_traffic_status": true
}
]
},
{
"listens": [
"0.0.0.0:8083"
],
"serverNames": [
"server3"
],
"locations": [
{
"location": "/",
"vhost_traffic_status": true
},
{
"location": "/a",
"vhost_traffic_status": true
},
{
"location": "/b",
"vhost_traffic_status": true
}
]
}
]
}