我正在設置一個web/app/db堆棧,並且nginx代理配置不按照我認爲的方式工作。nginx代理重定向使用代理的端口號,而不是主機
所以這裏是堆棧的示範...的應用程序的網址是: https://testapp.com
這裏是nginx的配置:
server {
listen 8886;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
#ELB
if ($http_user_agent = 'ELB-HealthChecker/2.0') {
return 200 working;
}
#HTTP to HTTPS
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
}
location/{
set $proxy_upstream_name "testapp.com";
port_in_redirect off;
proxy_pass http://internal-alb.amazonaws.com:8083/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Access-Control-Allow-Origin $http_origin;}
該應用程序被代理到內部AWS ALB ,並將其轉發給單個(此時)的應用程序服務器。
我可以讓網站投放。但是,應用程序會在登錄時創建一個重定向,並得到以下響應。
Request URL:https://testapp.com/login
Request Method:POST
Status Code:302
Remote Address:34.192.444.29:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
content-language:en-US
content-length:0
date:Mon, 11 Sep 2017 18:35:34 GMT
location:http://testapp.com:8083/testCode
server:openresty/1.11.2.5
status:302
,因爲它正在服務於443,而不是8083.
出於某種原因,應用程序或代理未更新,因爲它做的反向代理的事情端口重定向失敗,從而使重定向有代理端口不是實際的應用程序端口443.
我需要用nginx config來做些什麼來使其正確重定向。
謝謝。 myles。
這是一個AJAX調用或普通帖子的呼叫? –
嘗試添加'proxy_redirect http://internal-alb.amazonaws.com:8083/ https://testapp.com;' –