如何将Web服务器堆叠到Nginx代理反向位置?

时间:2019-12-17 09:20:51

标签: nginx reverse-proxy nginx-location nginx-reverse-proxy

我在Web服务器和服务器上的不同端口上使用了不同的应用程序。

现在我想将我的子域重定向到这样的应用程序:

application.domain.com/application-1/...
application.domain.com/application-2/...
application.domain.com/application-3/...

现在问题出在打开application.domain.com/application-2时,我被重定向到了预期的Web服务器。

但是,如果我单击任何链接(例如,登录名),则uri将被重写为application.domain.com/login,然后离开Web服务器,但是我希望这样的uri:application.domain.com/application-2/login

这是我实际的nginx网站可用的默认文件:

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        listen 80;
        listen [::]:80;

        server_name application.domain.com;

        ssl_certificate /etc/letsencrypt/live/application.domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/application.domain.com/privkey.pem;
        ssl_stapling on;
        ssl_stapling_verify on;
        add_header Strict-Transport-Security "max-age=31536000";
        access_log /var/log/nginx/sub.log combined;
        error_log /var/log/nginx/error.log debug;

        location /application-3 {
                proxy_pass https://localhost:5002;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

        location /application-2 {
                proxy_pass https://localhost:5001;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

        location /application-1 {
                proxy_pass https://localhost:5000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

        location / {
                proxy_pass https://localhost:5000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

要实现此目标,我需要更改什么?

0 个答案:

没有答案