不同位置的Nginx反向代理不起作用

时间:2019-12-16 09:51:57

标签: nginx reverse-proxy

我试图在不同位置使用我的nginx反向代理。

我想像这样生根:

URL:my.domain.com-> https://localhost:5000

URL:my.domain.com/test-1-> https://localhost:5000

URL:my.domain.com/test-2-> https://localhost:5001

我的默认文件如下:

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

        server_name my.domain.com;

        ssl_certificate /etc/letsencrypt/live/my.domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/my.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;

        location ~* /test-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 ~* /test-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;
        }
}
URL : my.domain.com -> https://localhost:5000
URL : my.domain.com/test-1 -> https://localhost:5000
URL : my.domain.com/test-2 -> https://localhost:5000

我认为'test-1'和'test-2'超越了'location /'

当我注释掉“位置/”时:

URL : my.domain.com -> Nginx default page
URL : my.domain.com/test-1 -> Nginx default page
URL : my.domain.com/test-2 -> Nginx default page

编辑:

这是我卷曲的结果:

root@server:/home/me# curl -I my.domain.com/test-2
HTTP/1.1 302 Found
Server: nginx/1.10.3
Date: Mon, 16 Dec 2019 11:57:07 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 34
Connection: keep-alive
X-Powered-By: Express
Location: /#/test-2
Vary: Accept
Strict-Transport-Security: max-age=31536000

我将位置更改为“ /#/ test-2”并获得了相同的结果

错误在哪里,或者我必须更改什么才能使我能够按指定的方向生根?

0 个答案:

没有答案