0
我目前使用nginx 1.9.11。我有一種情況,我的應用程序是通過負載平衡器從動態端口提供的,但應用程序本身的端口已設置。它看起來像這樣nginx:我如何進行相對重寫(重定向)? (即不要混淆端口號!)
Port [4000-4999] on load balancer -> instances of nginx all on port 80
我需要/myapp
重定向到/myapp/
不失端口信息。但我不知道應用程序級別的端口,因爲這些應用程序是動態創建和銷燬的!
下面是我重寫規則的語法:
rewrite ^/myapp /myapp/
我得到的是:
http://example.com:4000/myapp -> http://example.com/myapp # no port 4000!
我不能硬編碼端口......因爲有一千個可能性,他們改變每時每刻!我需要留在同一個港口,但我不知道我們進來的港口是什麼。我如何讓nginx離開這個端口?
我已經嘗試過...
在http
,server
,並location
部分:
port_in_redirect off;
在server
部分:
proxy_set_header Host $host:$server_port;
也在t他server
部分以及:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;