location /test/ { proxy_pass http://127.0.0.1:8088/test/; #proxy_set_header Host $proxy_host; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_ssl_session_reuse off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
location ^~ /test/static/web/ {
root /web/test;#映射到本地/web/test/test/static/web/目录
}
proxy_set_header X-Forwarded-For 配置说明:
proxy_set_header X-Forwarded-For $remote_addr;
#如上配置只增加负载均衡ip地址,隐藏了客户端真实ip和任意中间代理ip
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#如上配置不隐藏真实ip
将某个服务的请求都转向维护的图片
location /testpage/ { proxy_set_header REMOTE_ADDR $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:80/wh/logo.jpg?i=66; } location /wh/ { root /opt/webapps; }
将图片放到/opt/webapps/wh/logo.jpg下,然后再将/testpage/的请求都转向这个地址即可。