简体   繁体   中英

Attempting to redirect is not working as expected

When I go to https://www.something.org:8443 It redirects from my Nginx proxy server to my Proxmox server using the following location settings:

ProxMox Nginx Settings Site

location / {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass https://10.10.0.10:8006/;
    proxy_buffering off;
    client_max_body_size 0;
    proxy_connect_timeout 3600s;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
    sent_timeout 3600s;
}

The problem is I use my reverse proxy for other paths for other services, so I want it to work when I use the following URL:

https://www.something.org:8443/pve01

But I can't seem to make the location work. I've done three different proxy_pass versions, as shown below.

I get a blank page on all three attempts, but all the scripts and CSS are 404

location /pve01/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    
    1.
    proxy_pass https://10.10.0.10:8006/;
    
    2.
    proxy_pass https://10.10.0.10:8006/$request_uri;
    
    3.
    proxy_pass https://10.10.0.10:8006/;
    rewrite ^/pve01(.*)$ $1 break;
    
    
    proxy_buffering off;
    client_max_body_size 0;
    proxy_connect_timeout 3600s;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
    sent_timeout 3600s;
}

Any ideas/tips that can help this problem? Thanks

I believe the issue lies with the trailing slash, which doesn't pass on the rest of the URL, removing it should do the trick:

location / {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass https://10.10.0.10:8006;
    proxy_buffering off;
    client_max_body_size 0;
    proxy_connect_timeout 3600s;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
    sent_timeout 3600s;
}

Edit: And if you want only a specific location to be redirected, you could do something like:

location /pve01 {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass https://10.10.0.10:8006;
    proxy_buffering off;
    client_max_body_size 0;
    proxy_connect_timeout 3600s;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
    sent_timeout 3600s;
}

Removing the trailing slash from both the location and the proxy_pass statement should match any URL starting with the location specified, and should pass the entire URL to the specified proxy_pass IP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM