指点成金-最美分享吧

登录

nginx 定义:响应头和请求头

佚名 举报

篇首语:本文由小编为大家整理,主要介绍了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;

 

以上是关于nginx 定义:响应头和请求头的主要内容,如果未能解决你的问题,请参考以下文章