之前的配置是这样的
location / {
proxy_pass http://backend_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
## for keepalive set
proxy_http_version 1.1;
proxy_set_header Connection "";
}
后来因为location比较多,单个nginx里面server也不少,觉得每个地方都写很麻烦,就把
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
这3行写到了 http标签里。但是后端server获取到的IP就是nginx的IP了,配置到location里的时候是能正确获取客户端IP的。
请教一下,这个是作用域的问题吗?
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 shlug+un...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 shlug+un...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
include确实是一个好方法。
还有一点想确认一下,原本的想法是在http设置了默认的proxy_set_header,在location里如果修改的话,会把对应的key值覆盖,其他key值还是取http里面的设置,最后发现是不行的。
如果用include的方法,在location里重复设置一次,会引起重叠吗,就是出现2次key值在http head。
发件人: sh...@googlegroups.com
[mailto:sh...@googlegroups.com] 代表 Perry
发送时间: 2013年12月24日 15:22
收件人: sh...@googlegroups.com
主题: Re: [shlug] Re: 请教一个Nginx proxy_set_header作用域的问题
您收到此邮件是因为您订阅了 Google 网上论坛“Shanghai
Linux User Group”中的主题。
要退订此主题,请访问 https://groups.google.com/d/topic/shlug/0UGgkyWMLk4/unsubscribe。
要退订此论坛及其所有主题,请发送电子邮件到
shlug+un...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
| syntax: |
proxy_set_header |
| default: | proxy_set_header Host $proxy_host; proxy_set_header Connection close; |
| context: |
http, server, location |
Allows redefining or appending fields to the request header passed to the proxied server. A value can contain text, variables, and their combinations. These directives are inherited from the previous level if and only if there are no proxy_set_header directives defined on the current level. By default, only two fields are redefined:
就是这个。
发件人: sh...@googlegroups.com
[mailto:sh...@googlegroups.com] 代表 李晓岚
发送时间: 2013年12月25日 15:49
收件人:
sh...@googlegroups.com
主题: Re: 答复: [shlug] Re: 请教一个Nginx proxy_set_header作用域的问题