I'm trying to host a Shiny server on the /shiny/ subpath of my website. Using the config below I can reach my demo app via www.example.com/shiny/demo/.
However, when I exclude the last slash from the URI I end up at www.example.com/demo/ instead, which does not exist. I do not know which part of my config leads to this redirect: although I have rewrite_log on
I see nothing in error.log. If I remove the rewrite or drop the trailing slash from the proxy_pass everything stops working. The trailing slash in the location directive is not strictly needed (I think?) but I would rather keep it in, removing it seems to make no difference either. I am not sure if I need the proxy_redirect, but removing it does not fix the issue.
Any suggestions on how I can fix my configuration so that the redirect from /shiny/demo to /demo/ goes to /shiny/demo/ instead?
My config, with the relevant location at the bottom:
# Redirect to HTTPS
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
# Redirect to www subdomain
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /path/to/cert;
ssl_certificate_key /path/to/key;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
# Main server
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
root /path/to/root;
index index.php;
server_name www.example.com;
ssl_certificate /path/to/cert;
ssl_certificate_key /path/to/key;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
ssl_session_tickets off;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
location / {
if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; }
try_files $uri /$uri $uri.html $uri.php$is_args$query_string;
}
location ~ \.php$ {
if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1$is_args$query_string; }
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ^~ /shiny/ {
rewrite_log on;
rewrite ^/shiny/(.*)$ /$1 break;
proxy_pass http://localhost:1234/;
proxy_redirect http://localhost:1234/ $scheme://$server_name/shiny/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
}
}