Nextcloud on Docker behind nginx reverse proxy - cannot access installation page


Before explaining the issue, I need to preface with a little config info.

So, I have Nginx in a Docker container. It acts as a reverse proxy, proxying requests to other containers. In one container, I have Jellyfin (a media server). I can access Jellyfin by navigating to http://host-ip:8080/jellyfin/. I would like to do the same with Nextcloud, navigating to http://host-ip:8080/nextcloud/.

Unfortunately, even though I’ve configured both Nextcloud and Jellyfin similarly, the Nextcloud instance doesn’t work - it throws “502 Bad Gateway” when I attempt to access it.

Any help would be appreciated!


For anyone else experiencing this issue, add the following to your Nginx configuration:

location /nextcloud/ {
            proxy_pass http://nextcloud/; # DO NOT add a port here
            proxy_pass_request_headers on;

            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            # proxy_set_header X-Forwarded-Host $http_host;
            # proxy_set_header Upgrade $http_upgrade;
            # proxy_set_header Connection $http_connection;

            proxy_buffering off;

And in Docker, don’t change the ports - just forward 80 to 80 and 443 to 443.

I was trying to map 80 to 3480 and 443 to 3443, and had 3480 at the end of my proxy_pass line - but this doesn’t work. I don’t know why. I frankly don’t care. It’s working now, and it doesn’t interfere with anything else, so I’m happy!