网络架构:
pc->14.23:7050(nginx)->14.22:8081(nginx)->14.22:8080(web服务)
23 nginx 配置:
server {
listen 7050;
location /{
proxy_pass http://xx.xx.14.22:8081/TestServer;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
22 nginx 配置:
server {
listen 8081;
listen [::]:8081 ipv6only=on;
location / {
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://xx.xx.14.22:8080;
}
}
web 服务请求头参数
String ips = request.getHeader("X-Forwarded-For");
odoo 服务请求头参数设置
def application(environ, start_response):
if config['proxy_mode'] and 'HTTP_X_FORWARDED_HOST' in environ:
werkzeug.serving.WSGIRequestHandler.address_string = lambda self: self.headers.get('X-Forwarded-For', self.client_address[0])
return werkzeug.contrib.fixers.ProxyFix(application_unproxied)(environ, start_response)
else:
return application_unproxied(environ, start_response)
效果图
会显示两个IP地址,使用逗号隔开