I configured my Nginx docker instance to pass all requests made to https://my.public.domain/nextcloud to the nextcloud docker instance in the background.
When I call the url described above (of course by using the real domain name), I get an 502 Bad Gateway status.
The logs of nextcloud, retrieved using docker logs nextcloud-server
, show nothing at all that seems to be related to the request. It seems like nextcloud does not react at all.
The logs of nginx, retrieved using docker logs nginx
show these lines:
2019/12/26 19:05:59 [error] 6#6: *80 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xxx.xxx.xx, server: my.public.domain, request: "GET /nextcloud/ HTTP/2.0", upstream: "http://127.0.0.1:9001/", host: "my.public.domain"
xx.xxx.xxx.xx - - [26/Dec/2019:19:05:59 +0000] "GET /nextcloud/ HTTP/2.0" 502 552 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/79.0.3945.79 Chrome/79.0.3945.79 Safari/537.36" "-"
Expected Behaviour: Be able to reach the web interface of nextcloud. (See login page etc.)
Technical Details:
Nextcloud version: 17.0.2.1
Operating system and version: Ubuntu Server 18.04.3 LTS
Apache or nginx version: latest
PHP version: PHP/7.3.13
Is this the first time you’ve seen this error? : Yes
Steps to replicate it:
- Install Nextcloud as described in “Installation” section further below.
- Set up Nginx as docker container on same host as nextcloud with valid SSL certificates, using the configuration file provided further below in “Nginx-Configuration”.
- Configure Nextcloud as shown in “config.php”.
The output of your Nextcloud log in Admin > Logging: (currently not accessible, will be provided as soon as needed)
The output of your config.php file in /path/to/nextcloud
<?php
$CONFIG = array (
'htaccess.RewriteBase' => '/',
'memcache.local' => '\\OC\\Memcache\\APCu',
'apps_paths' =>
array (
0 =>
array (
'path' => '/var/www/html/apps',
'url' => '/apps',
'writable' => false,
),
1 =>
array (
'path' => '/var/www/html/custom_apps',
'url' => '/custom_apps',
'writable' => true,
),
),
'instanceid' => 'whatever',
'passwordsalt' => 'whatever',
'secret' => 'whatever',
'trusted_domains' =>
array (
0 => '192.168.xxx.xxx',
1 => '127.0.0.1',
2 => 'my.public.domain',
),
'trusted_proxies' => ['127.0.0.1', 'localhost'],
'datadirectory' => '/var/www/html/data',
'dbtype' => 'pgsql',
'version' => '17.0.2.1',
'overwrite.cli.url' => 'http://127.0.0.1:9001',
'overwritewebroot' => '/',
//'overwriteprotocol' => 'https',
//'overwritehost' => 'my.public.domain',
'dbname' => 'nextcloud',
'dbhost' => 'database',
'dbport' => '',
'dbtableprefix' => 'oc_',
'dbuser' => 'oc_ncadmin',
'dbpassword' => 'whatever',
'installed' => true,
);
Nginx-Configuration:
server {
listen 80;
listen [::]:80;
server_name my.public.domain;
location / {
rewrite ^ https://$host$request_uri? permanent;
}
#for certbot challenges (renewal process)
location ~ /.well-known/acme-challenge {
allow all;
root /data/letsencrypt;
}
}
#https://my.public.domain
server {
server_name my.public.domain;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_tokens off;
ssl_buffer_size 8k;
ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
ssl_ecdh_curve secp384r1;
ssl_session_tickets off;
# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4;
ssl_certificate /etc/letsencrypt/live/my.public.domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/my.public.domain/privkey.pem;
root /usr/share/nginx/html;
index index.html;
location /nextcloud/ {
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_pass http://127.0.0.1:9001/;
}
}
Installation:
I have Nextcloud running in a docker container with PostgreSQL database (in a seperate container). For installation I followed the guide provided on the docker hub page of Nextcloud.
For nextcloud I created an own Dockerfile, which installs some depedencies. This Dockerfile is used in the docker-compose.yml. The created docker image is tagged “xxxx/nextcloud”.
I set up my nextcloud server using ssh while being within the LAN of the server, which is located at my home.
Docker setup:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c41eacea755 nginx:latest "nginx -g 'daemon of…" About an hour ago Up 59 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx
108f037f2f47 xxxx/nextcloud "/entrypoint.sh apac…" About an hour ago Up About an hour 127.0.0.1:9001->80/tcp nextcloud-server
992102960b40 postgres "docker-entrypoint.s…" About an hour ago Up About an hour 5432/tcp nextcloud-database