nginx代理重定向使用代理的端口号,而不是主机

nginx代理重定向使用代理的端口号,而不是主机,nginx,proxy,Nginx,Proxy,我正在设置一个web/app/db堆栈,而nginx代理配置的工作方式与我想象的不一样 下面是一个堆栈示例…应用程序的url为: 以下是nginx配置: server { listen 8886; server_name _; root /usr/share/nginx/html; include /etc/nginx/default.d/*.conf; #ELB if ($http_user_agent = 'ELB-

我正在设置一个web/app/db堆栈,而nginx代理配置的工作方式与我想象的不一样

下面是一个堆栈示例…应用程序的url为:

以下是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.

nginx的正常行为是将上游地址重写为提供页面的地址。看起来您的应用程序不是使用上游地址(),而是混合使用两种地址()进行响应。您可以更改应用程序行为,也可以使用


我有理由相信解决这个问题的指令是
proxy\u redirecthttp://testapp.com:8083/ https://testapp.com/;

nginx的正常行为是将上游地址重写为提供页面的地址。看起来您的应用程序不是使用上游地址(),而是混合使用两种地址()进行响应。您可以更改应用程序行为,也可以使用


我有理由相信解决这个问题的指令是
proxy\u redirecthttp://testapp.com:8083/ https://testapp.com/;

这是一个AJAX调用或正常的post调用?请尝试添加
代理\u重定向http://internal-alb.amazonaws.com:8083/ https://testapp.com;这是一个AJAX调用还是一个普通的post调用?请尝试添加
proxy\u重定向http://internal-alb.amazonaws.com:8083/ https://testapp.com;