zoukankan      html  css  js  c++  java
  • 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";
  • 相关阅读:
    Git 使用记录
    AngularJS $http返回的数据类型
    angularJS 使用$http 出现 $http.get(...).success is not a function
    JS数组及其方法(slice,contact...)
    HTML5的localStorage和sessionStorage
    promise async await 结合 demo2
    promise async await 结合 demo1
    git 命令
    git
    new 优先级的题目
  • 原文地址:https://www.cnblogs.com/faberbeta/p/nginx-configure002.html
Copyright © 2011-2022 走看看