nginx代理转发说明

1、nginx 默认转发header,个别字段除外

说明:

(1)proxy_hide_header

语法:proxy_hide_header field;
默认值:
上下文:httpserverlocation

nginx默认不会将“Date”、“Server”、“X-Pad”,和“X-Accel-...”响应头发送给客户端。proxy_hide_header指令则可以设置额外的响应头,这些响应头也不会发送给客户端。相反的,如果希望允许传递某些响应头给客户端,可以使用proxy_pass_header指令。

(2)proxy_pass_header(其功能与proxy_hide_header相反,会将原来不允许转发的改为允许转发)

语法:proxy_pass_header field;
默认值:
上下文:httpserverlocation

允许传送被屏蔽的后端服务器响应头到客户端。

(3)proxy_set_header

语法:proxy_set_header field value;
默认值:
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
上下文:httpserverlocation

允许重新定义或者添加发往后端服务器的请求头。value可以包含文本、变量或者它们的组合。 当且仅当当前配置级别中没有定义proxy_set_header指令时,会从上面的级别继承配置。 默认情况下,只有两个请求头会被重新定义:

proxy_set_header Host       $proxy_host;
proxy_set_header Connection close;

如果不想改变请求头“Host”的值,可以这样来设置:

proxy_set_header Host       $http_host;

但是,如果客户端请求头中没有携带这个头部,那么传递到后端服务器的请求也不含这个头部。 这种情况下,更好的方式是使用$host变量——它的值在请求包含“Host”请求头时为“Host”字段的值,在请求未携带“Host”请求头时为虚拟主机的主域名:

proxy_set_header Host       $host;

此外,服务器名可以和后端服务器的端口一起传送:

proxy_set_header Host       $host:$proxy_port;

如果某个请求头的值为空,那么这个请求头将不会传送给后端服务器:

proxy_set_header Accept-Encoding "";

2、nginx 默认转发body

说明:

proxy_pass_request_body(默认是打开的)

Syntax:proxy_pass_request_body on | off;
Default:
proxy_pass_request_body on;
Context:httpserverlocation

Indicates whether the original request body is passed to the proxied server.

location /x-accel-redirect-here/ {
    proxy_method GET;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";

    proxy_pass ...
}

See also the proxy_set_header and proxy_pass_request_headers directives.

参考:

(1)Nginx基础入门之proxy反向代理常用配置项说明:https://blog.51cto.com/blief/1739178

(2)Nginx中文手册:http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_proxy_module.html#proxy_hide_header

(3)Nginx英文手册:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass_header

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值