Took days to troubleshoot this issue, yet couldn't find solution googling with my noob knowledge base.
What I'm trying to do: Accessing url/nextcloud reverse proxy to localhost but keeping /nextcloud/ in user's view. i.e. url/nextcloud/login would internally be localhost/login in nextcloud configuration file.
Expectation: As 'nextcloud' config file change root from /var/www/ to /var/www/nextcloud, url/nextcloud/login would proxy-ed to localhost/login, in effect /var/www/nextcloud/login.
Result I always get: url/nextcloud returns url/login, aka url/var/www/login in effect rather than url/var/www/nextcloud/login
Below is my nginx reverse proxy code, and nextcloud code uses config in Nextcloud documentation. Reverse-proxy passes nextcloud to 127.0.0.1:5141 and Nextcloud configuration listens on 127.0.0.1:5141. Sorry I can't provide exact nextcloud config since my server went down today.
server {
listen 80;
listen [::]:80;
server_name MY_DOMAIN_HERE;
# enforece https
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name MY_DOMAIN_HERE;
ssl_certificate /etc/letsencrypt/live/MY_DOMAIN_HERE/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/MY_DOMAIN_HERE/privkey.pem;
root /var/www/;
location /nextcloud/ {
# rewrite ^/nextcloud/(.*)$ $1 break;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:5141/;
proxy_set_header Host MY_DOMAIN_HERE;
}
location /noVNC/ {
proxy_pass http://127.0.0.1:5142;
}
location /shell/ {
proxy_pass http://127.0.0.1:4200;
}
location /files/ {
return 301 /;
proxy_pass http://127.0.0.1:5143;
}
#location / {
# proxy_pass http://127.0.0.1:5143;
#}
}