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 和  set

區別,

proxy_set_header定義頭,在方向代理服務器的源點日志中可以看到相關記錄(日志需要定義相關字段的名字,如$http_host, $http_X-Forwarded-For)

但是在代理服務器中無法看到改值

 

set 頭,在源點日志中無法看到信息,但是在方向代理的日志中可以看到(日志的自定義字段是 $position, $age)

參考鏈接:https://blog.51cto.com/wenxi123/2325667

例如:

    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;

 

       set $position "Manager";
       set $age "21";

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM