【发布时间】:2018-04-05 01:20:25
【问题描述】:
我在 Nginx.conf 上有以下配置
<b>
http {
log_format my_upstream '$remote_addr [$time_local] "$request" $status'
'"$upstream_addr" $upstream_response_time $upstream_http_etag $host $http_host';
access_log /var/log/nginx/upstream.log my_upstream;
upstream myapp{
ip_hash;
server x.x.x.174:8001;
server x.x.x.96:8001;
}
server {
listen 9000;
#websocket
location /jms {
proxy_pass http://myapp/jms;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $upstream_addr;
}
location / {
proxy_pass http://myapp;
}
}
}
</b>
我尝试将主机设置为 $upstream_addr,但不幸的是,我在请求中收到了 null。 谁能帮我将主机设置为 $upstream_addr。 谢谢, 巴斯卡。
【问题讨论】:
-
proxy_set_header在proxy_pass之前执行,即使你放在proxy_pass之后,并且在进入负载均衡之前,$upstream_addr为null
标签: nginx nginx-location nginx-reverse-proxy