zoukankan      html  css  js  c++  java
  • Nginx 返回响应过滤响应内容

    94 过滤模块 从下到上顺序

     

     

    server {

      listen 30004;
      server_name shop***s.com.cn;

            location /{
                   proxy_pass http://test;
                   proxy_hide_header aaa; #启动某个头部隐藏 则不会返回给客户端
                   proxy_pass_header server;
                   proxy_ignore_headers X-Accel-Limit-Rate;
                   proxy_http_version 1.1;
                   proxy_set_header Connection "";
                   proxy_method POST;
            }
    
    }
    upstream test {
            server 192.168.0.51:8890 weight=1 ;
    
    }

    上游服务器代码

     server { listen 8890; location / { add_header aaa 'aaa value'; #这里加了个头 } } 

    测试代码

    [root@3 webserver]# curl sh****s.com.cn:30004 -I
    HTTP/1.1 200 OK
    Server: openresty/1.13.6.2
    Date: Sun, 12 May 2019 03:30:57 GMT
    Content-Type: text/html
    Content-Length: 612
    Connection: keep-alive
    Last-Modified: Sat, 23 Mar 2019 08:55:05 GMT
    ETag: "5c95f469-264"
    aaa: aaa value  //如果我们不隐藏指定头部则响应给客户端
    Accept-Ranges: bytes

    ngx_http_proxy_module 模块

    Syntax: proxy_ignore_headers field ...;
    Default:
    Context: httpserverlocation

    功能 :某些行为可能会改变nginx行为,使用proxy_ignore_hreades可以禁止他们生效

    可以禁用的头部:

    1. X-Accel_Redirect : 由上游服务指定nginx内部重定向 控制请求的执行
    2. X-Accel-Limit-Rate: 由上游设置发往客户端速度限制 等同于limit_rate指令
    3. X-Accel-Buffering:由上游控制是否缓存上游的响应
    4. X-Accel-Charset:由上游控制 Content-Type中的Charset

    缓存相关:

    1.   X-Accel-Expires:设置响应在nginx中的缓存时间 单位秒 ;@开头表示一天内的某时刻
    2.   Expires:控制nginx缓存时间 优先级低于 X-Accel-Expires
    3.   Cache-Control: 控制nginx缓存时间 优先级低于 X-accel-Expires
    4.   Set-Cookie:响应出现Set-Cookie则不缓存  可以通过proxy_ignore_headers 禁止生效
    5.   Vary 响应中出现Vary:* 则不缓存 可以禁止生效

    proxy_hide_header 指令是指对于上游响应中的某些头部,设置不向客户端转发 默认不转发

    1. Date:由nginx_http_header_filter_module过滤模块填写,值为nginx发送响应头部的时间
    2. Server:由nginx_http_header_filter_module过滤模块填写 ,值为nginx版本
    3. X-Pad:通常是Apache为避免浏览器BUG生成头部,默认忽略
    4. X-Accel-:用于控制nginx行为的响应,不需要向客户端转发
    Syntax: proxy_hide_header field;
    Default:
    Context: httpserverlocation


    proxy_pass_header 对于被已经被proxy_hide_header的头部,设置向上游转发

    Syntax: proxy_pass_header field;
    Default:
    Context: httpserverlocation

    proxy_cookie_domain 指令是指修改域名 如:域名是A 则修改成 B

    Syntax: proxy_cookie_domain off;
    proxy_cookie_domain domain replacement;
    Default:
    proxy_cookie_domain off;
    Context: httpserverlocation
    proxy_cookie_domain localhost example.org; #用于域名替换
    Syntax: proxy_cookie_path off;
    proxy_cookie_path path replacement;
    Default:
    proxy_cookie_path off;
    Context: httpserverlocation
    proxy_cookie_path off;
    proxy_cookie_path /two/ /; #用于uri替换
    proxy_cookie_path ~*^/user/([^/]+) /u/$1;

    Syntax:proxy_redirect default;
        proxy_redirect off;
        proxy_redirect redirect replacement;
    Default:proxy_redirect default;

    Context:httpserverlocation

    proxy_redirect http://localhost:8000/two/ http://frontend/one/;
  • 相关阅读:
    Blank page instead of the SharePoint Central Administration site
    BizTalk 2010 BAM Configure
    Use ODBA with Visio 2007
    Handling SOAP Exceptions in BizTalk Orchestrations
    BizTalk与WebMethods之间的EDI交换
    Append messages in BizTalk
    FTP protocol commands
    Using Dynamic Maps in BizTalk(From CodeProject)
    Synchronous To Asynchronous Flows Without An Orchestration的简单实现
    WSE3 and "Action for ultimate recipient is required but not present in the message."
  • 原文地址:https://www.cnblogs.com/jackey2015/p/10438123.html
Copyright © 2011-2022 走看看