Nginx proxy_set_header设置Host为$proxy_host,$host与$local_host的区别
来源:互联网 发布:抓绒衣里面穿什么 知乎 编辑:程序博客网 时间:2024/06/06 02:12
proxy_set_header设置Host为$proxy_host,$host与$local_host的区别
先来看下proxy_set_header的语法
语法:
proxy_set_header field
value
;
默认值:proxy_set_header Host $proxy_host;
proxy_set_header Connection close;上下文:
http
, server
, location
允许重新定义或者添加发往后端服务器的请求头。value
可以包含文本、变量或者它们的组合。 当且仅当当前配置级别中没有定义proxy_set_header
指令时,会从上面的级别继承配置。 默认情况下,只有两个请求头会被重新定义:
proxy_set_header Host $proxy_host;proxy_set_header Connection close;
nginx对于upstream默认使用的是基于IP的转发,因此对于以下配置:
- upstream backend {
- server 127.0.0.1:8080;
- }
- upstream crmtest {
- server crmtest.aty.sohuno.com;
- }
- server {
- listen 80;
- server_name chuan.aty.sohuno.com;
- proxy_set_header Host $http_host;
- proxy_set_header x-forwarded-for $remote_addr;
- proxy_buffer_size 64k;
- proxy_buffers 32 64k;
- charset utf-8;
- access_log logs/host.access.log main;
- location = /50x.html {
- root html;
- }
- location / {
- proxy_pass backend ;
- }
- location = /customer/straightcustomer/download {
- proxy_pass http://crmtest;
- proxy_set_header Host $proxy_host;
- }
- }
当匹配到/customer/straightcustomer/download时,使用crmtest处理,到upstream就匹配到crmtest.aty.sohuno.com,这里直接转换成IP进行转发了。假如crmtest.aty.sohuno.com是在另一台nginx下配置的,ip为10.22.10.116,则$proxy_host则对应为10.22.10.116。此时相当于设置了Host为10.22.10.116。如果想让Host是crmtest.aty.sohuno.com,则进行如下设置:
proxy_set_header Host crmtest.aty.sohuno.com;
如果不想改变请求头“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 "";
阅读全文
0 0
- proxy_set_header设置Host为$proxy_host,$host与$local_host的区别
- Nginx proxy_set_header设置Host为$proxy_host,$host与$local_host的区别
- Nginx proxy_set_header中$proxy_host,$host,$http_host的区别
- nginx中proxy_set_header Host $host的作用
- nginx中proxy_set_header Host $host;的作用
- nginx中proxy_set_header Host $host的作用
- nigix proxy_set_header Host $host:$server_port 与 $host:proxy_port 区别
- DNS host区别与设置
- 关于nginx中proxy_set_header的设置
- ngxin proxy_set_header Host X-Forwarded-For
- location.host 与 location.hostname 的区别
- Client server host 的定义与区别
- host-only 与bridge方式的区别
- nginx proxy_set_header设置、自定义header
- nginx proxy_set_header设置、自定义header
- nginx proxy_set_header设置、自定义header
- nginx proxy_set_header设置、自定义header
- 设置Windows Script Host为Cscript
- c语言验证哥德巴赫猜想
- VS2010怎么用Dumpbin来查看DLL导出函数
- ./configure,make,make install的作用
- NotePad 打开文件 出现中文汉字乱码 解决办法
- Java体系结构图
- Nginx proxy_set_header设置Host为$proxy_host,$host与$local_host的区别
- 重建索引的标准
- LAMP、MySQL、MariaDB介绍与安装
- 马尔可夫决策过程(MDP)
- 简单的web分享
- 常用类
- Vue.js 子组件更新视图
- JS编写一个函数,实现传入一个不定长度字符串,查找出重复次数前n名的字符并分别统计其次数
- 三种方法实现斐波那契数列