I have setup a Nginx server as proxy for a back-end. If the back-end is down, Nginx serves from a backup of the back-end. The proxy works when the URL ends with a trailing slash. If I omit the trailing slash, the URL shown becomes the name of the upstream block plus the port of the backup back-end.
- What works:
www.chingu.asia
,www.chingu.asia/
, andwww.chingu.asia/wiki/
. - What doesn't work:
www.chingu.asia/wiki
(no trailing slash), my browser is redirected tohttp://chingu.servers:8111/wiki/
, which cannot be found (of course).
Here is my configuration:
upstream chingu.servers { server 192.168.0.12 fail_timeout=300s max_fails=1; server 192.168.0.10:8111 backup; } server { listen 80; server_name www.chingu.asia; location / { proxy_pass http://chingu.servers/; } } server { listen 192.168.0.10:8111; server_name _; root /...some path.../Chingu; index index.html index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php7.3-fpm.sock; fastcgi_param FQDN true; } }
I have tried using regexes to match any URI with the location blocks. I also tried port_in_redirect off;
and absolute_redirect off;
.
I could add location block for wiki
and others but it seems to defeat the purpose of a proxy if I must add manually every possible sub-directories.
What is it that I'm missing?
/
but breaks your reverse proxy. You can redirect to/
ending URLs proactively in your nginx config to avoid redirection from upstream.