nginx 定义:响应头和请求头

1) 响应头

add_header

例如:

        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
        add_header X-Proxy-Cache $upstream_cache_status;

 要小心Nginx的add_header指令详解:

当当前层级中没有add_header指令才会继承父级设置。所以我的疑问就清晰了:location中有add_header,nginx.conf中的配置被丢弃了。

例如你在 location层添加了一个add_header 信息,在server 层也添加了一个add_header信息,

那么server 层的add_header会被丢弃,所以要小心添加

2) 请求头

proxy_set_header

例如:

    proxy_set_header Accept-Encoding "";
    proxy_set_header Host $http_host;
    proxy_cookie_domain $host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

猜你喜欢

转载自www.cnblogs.com/faberbeta/p/nginx-configure002.html