A
A
Alexander Semenenko2020-11-23 13:10:48
Nginx
Alexander Semenenko, 2020-11-23 13:10:48

Why does nginx reverse proxy not work if the last / is not put at the end of the browser?

Here is such a setup on nginx reverse proxy:

location /UNDVXE5A/ {
         proxy_pass https://10.15.0.109/UNDVXE5A/;
         proxy_set_header Host $proxy_host;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Real-IP $remote_addr;
        }


Port 7323 to local 443 is forwarded to the external interface for nginx.

If I access it like this in the browser: https://domen:7323/UNDVXE5A/ then everything works
And like this: https://domen:7323/UNDVXE5A - then it transfers to https:/ /domen/UNDVXE5A/

What could be the reason?

It may be important that nginx reverse proxy works on https, as a backend apache also works on https (but the certificate is self-written).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2020-11-23
@semenenko88

https://nginx.org/ru/docs/http/ngx_http_core_modul...

If location is prefixed with a trailing slash and requests are processed using proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, memcached_pass, or grpc_pass, special processing occurs. A request with a URI equal to this string but without a trailing slash will return a permanent 301 redirect to a URI with a trailing slash.

Since you change the port from 7323 to 443 on the router, nginx does not know anything about port 7323 and redirects to the address with the port specified in its config, i.e. 443. It's easier to tell nginx not to do an absolute redirect .
absolute_redirect off;

V
vreitech, 2020-11-23
@fzfx

since your location is specified /UNDVXE5A/, then this location will only work for /UNDVXE5A/.
but it redirects https://domen:7323/UNDVXE5Ato https://domen/UNDVXE5A/because, as I wrote above, your URL does not fall under the above rule, but somewhere in the config there is a rule or a set of rules responsible for redirecting from https://domen:7323/UNDVXE5Ato https://domen/UNDVXE5A/.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question