Nextcloud in docker over Nginx reverse proxy

I have searched this forum for a solution, but wasn’t been able to get it to work. I’m running NextCloud in a docker container. My host machine is running a few webservers with an nginx reverse proxy, on my.server/sonarr, my.server/transmission, etc.

I would like to have my nextcloud on my.server/nextcloud.

So far I’ve been following this document, but have been getting a 502 bad gateway error.

My config files are as follows:

Nextcloud config.php

Nginx reverse_proxy

Anybody got a clue what is going wrong?

Hello Elmardus,
I’m having similar environment as you. I’m using nginx as proxy to redirect to apache virtual hosts and all this on raspberry pi 4 :slight_smile: and for DNS
I also want to run NC in docker but I get the same error as you bad gateway 502.
I’m curious, did you setup docker network for NC ? Also as I understand I proxypass nginx to docker container with NC, and adding the port, because I’m using ports, as far as I remember for NC you need 4443, 443 and 80. Actually I’m using this and command docker run -d -p 4443:4443 -p <custom_port>:443 -p <custom_port>:80 -v ncdata:/data --name nextcloudpi ownyourbits/nextcloudpi $DOMAIN. Any ideas are very welcome, especially nginx proxy config :slight_smile: And why we need 4443 port btw ?

why do you expose these ports?

if your nginx reverse proxy is running in a docker container you set
proxy_pass http://nextcloudpi:80;.

Hi Reiner_Nippes, no my nginx-proxy is running directly on raspbian (debian buster 10).

can you access nextcloudpi without proxy via the custom ports?
is it up&running? docker logs nextcloudpi ?

btw: 4443 is the admin panel of nextcloupi.

nginx config
`server {

    location / {
       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-Remote-Port        $remote_port;
       proxy_set_header        X-Forwarded-Proto    $scheme;
       proxy_redirect          off;

    index index.html index.htm index.nginx-debian.html;


in browser
You don't have permission to access / on this server.

tested this, btw works fine, locally and with noip dns
docker run -d -p custom_port:80 nextcloud