Add_more_header

1 功能说明

可以通过一条指令设定多个header值。

2 依赖模块

add_more_header功能依赖模块:

load_module modules/njt_http_multi_header_module.so;

3. 指令说明

Syntax add_more_header name value1 value2 value…. [always]
Default -
Context http,server,location

参数介绍:

参数 取值 说明
name Header 名字。例如:Set-Cookie value1 value2…字段值。 例如:“key=$uri” “key2=2” “key3=3” “key4”;

4. 配置说明

njet.conf

helper broker modules/njt_helper_broker_module.so conf/mqtt.conf;
helper ctrl modules/njt_helper_ctrl_module.so conf/ctrl.conf;

load_module modules/njt_http_multi_header_module.so;

user  root;
worker_processes 2;

cluster_name helper;
node_name node-u01;

error_log  logs/error.log info;
pid        logs/njet.pid;

events {
    worker_connections  1024;
}


http {
    dyn_kv_conf conf/iot-work.conf;
    include       mime.types;
    default_type  application/octet-stream;
    variables_hash_max_size   4096;
    access_log  logs/access.log;
    
    upstream backend1 {
         zone backend1_zone 128k;
         server 127.0.0.1:5888;
    }

   server {
          listen  0.0.0.0:5555;
          server_name  localhost;
          location / {
          
                add_more_header Set-Cookie "key=$uri" "key2=2" "key3=3" "key4";
                default_type text/html;
                proxy_pass http://backend1;
                
          }
        }
        
   server {
         listen  0.0.0.0:5888;
         
         location / {
         
                default_type text/html;
                return 200 "5888 $request_uri";
                
         }
      }
}

5. 调用样例

发送

curl -v http://127.0.0.1:5555/

返回

* processing: http://127.0.0.1:5555/
*   Trying 127.0.0.1:5555...
* Connected to 127.0.0.1 (127.0.0.1) port 5555
> GET / HTTP/1.1
> Host: 127.0.0.1:5555
> User-Agent: curl/8.2.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: njet/3.1.0
< Date: Tue, 14 Jan 202506:53:10 GMT
< Content-Type: text/plain
< Content-Length: 0
< Connection: keep-alive
< Set-Cookie: key=/
< Set-Cookie: key2=2
< Set-Cookie: key3=3
< Set-Cookie: key4
< 
* Connection #0 to host 127.0.0.1 left intact