'Nexcloud + Reverse proxy ERR_TOO_MANY_REDIRECTS when trying to access my subdomain
In order to host multiple websites I'am trying to reproduce the following schema diagram
The redirection works correctly with the following sites and without having to indicate the port: https://git.domain.tld and https://portainer.domain.tld but does not work for: https://test.domain.tld (The page is not redirected correctly => I'm getting this ERR_TOO_MANY_REDIRECTS)
here is my docker-compose :
version: '2'
services:
proxy:
image: jwilder/nginx-proxy
container_name: proxy
restart: unless-stopped
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- certs:/etc/nginx/certs:rw
- vhost.d:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- ./uploadsize.conf:/etc/nginx/conf.d/uploadsize.conf:ro
ports:
- "80:80"
- "443:443"
networks:
- "default"
- "proxy-tier"
proxy-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt
restart: unless-stopped
environment:
- NGINX_PROXY_CONTAINER=proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes_from:
- "proxy"
depends_on:
- "proxy"
networks:
- "default"
- "proxy-tier"
portainer:
image: portainer/portainer
container_name: portainer
restart: always
environment:
- VIRTUAL_HOST=portainer.domain.tld
- LETSENCRYPT_HOST=portainer.domain.tld
- [email protected]
- LETSENCRYPT_TEST=false
volumes:
- ./portainer/:/data
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "9000:9000"
networks:
- "default"
- "proxy-tier"
gitea:
image: gitea/gitea:latest
container_name: gitea
restart: unless-stopped
environment:
- VIRTUAL_HOST=git.domain.tld
- LETSENCRYPT_HOST=git.domain.tld
- [email protected]
- LETSENCRYPT_TEST=false
- VIRTUAL_PORT=3000
- ROOT_URL=https://git.domain.tld
- DOMAIN=git.domain.tld
- PROTOCOL=http
- USER_UID=1000
- USER_GID=1000
- POSTGRES_USER=xxxxx
- POSTGRES_PASSWORD=xxxxxxx
- POSTGRESS_DB=xxxxx
volumes:
- ./gitea:/data
ports:
- "9001:3000"
- "9002:22"
networks:
- "default"
- "proxy-tier"
nextcloud:
image: lscr.io/linuxserver/nextcloud
container_name: drive
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Paris
- VIRTUAL_HOST=test.domain.tld
- LETSENCRYPT_HOST=test.domain.tld
- [email protected]
- LETSENCRYPT_TEST=true
- DEBUG=true
ports:
- "9005:443"
- "9006:80"
volumes:
- ./drive/appdata:/config
- ./drive/data:/data
networks:
- "default"
- "proxy-tier"
restart: unless-stopped
volumes:
certs:
vhost.d:
html:
nextcloud:
db:
networks:
proxy-tier:
Thank you in advance for your help, I've been stuck on this problem for a few days
EDIT :
Some lines from proxy logs when I enter test.domain.tld:
nginx.1 | test.domain.tld 91.182.X.X - - [28/Apr/2022:04:21:27 +0000] "GET / HTTP/2.0" 301 162 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0" "172.29.0.6:80"
nginx.1 | test.domain.tld 91.182.X.X - - [28/Apr/2022:04:21:27 +0000] "GET / HTTP/2.0" 301 162 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0" "172.28.0.3:80"
nginx.1 | test.domain.tld 91.182.X.X - - [28/Apr/2022:04:21:28 +0000] "GET / HTTP/2.0" 301 162 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0" "172.29.0.6:80"
...
AND this is from nexcloud :
Exception: Not installed in /config/www/nextcloud/lib/base.php:277
Stack trace:
#0 /config/www/nextcloud/lib/base.php(649): OC::checkInstalled()
#1 /config/www/nextcloud/lib/base.php(1087): OC::init()
#2 /config/www/nextcloud/cron.php(43): require_once('/config /www/nex...')
}
Exception: Not installed in /config/www/nextcloud/lib/base.php:277
Stack trace:
#0 /config/www/nextcloud/lib/base.php(649): OC::checkInstalled()
#1 /config/www/nextcloud/lib/base.php(1087): OC::init()
#2 /config/www/nextcloud/cron.php(43): require_once('/config/www/nex...')
}
Exception: Not installed in /config/www/nextcloud/lib/base.php:277
Stack trace:
#0 /config/www/nextcloud/lib/base.php(649): OC::checkInstalled()
#1 /config/www/nextcloud/lib/base.php(1087): OC::init()
#2 /config/www/nextcloud/cron.php(43): require_once('/config/www/nex...')
}
...
And this is my ngnix config /etc/nginx/conf.d/default.conf
# test.domain.tld
upstream test.domain.tld {
# Exposed ports: [{ 443 9005 tcp 0.0.0.0} { 80 9006 tcp 0.0.0.0}]
# Default virtual port: 80
# VIRTUAL_PORT: <no value>
## Can be connected with "proxy_default" network
# drive
server 172.28.0.3:80;
# Cannot connect to network 'proxy_proxy-tier' of this container
# Cannot connect to network 'proxy_default' of this container
## Can be connected with "proxy_proxy-tier" network
# drive
server 172.29.0.6:80;
}
server {
server_name test.domain.tld;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
# Do not HTTPS redirect Let'sEncrypt ACME challenge
location ^~ /.well-known/acme-challenge/ {
auth_basic off;
auth_request off;
allow all;
root /usr/share/nginx/html;
try_files $uri =404;
break;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
server_name test.domain.tld;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/test.domain.tld.crt;
ssl_certificate_key /etc/nginx/certs/test.domain.tld.key;
ssl_dhparam /etc/nginx/certs/test.domain.tld.dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/certs/test.domain.tld.chain.pem;
add_header Strict-Transport-Security "max-age=31536000" always;
include /etc/nginx/vhost.d/default;
location / {
proxy_pass http://test.domain.tld;
}
}
Solution 1:[1]
The answer is in the question itself - yes, it is possible and you already doing it.
You say the page test.domain.tld is not redirected correctly - what exactly happens?
Without knowing what happens exactly with the redirection when you enter the test.domain.tld, I would suggest some experiments with the nextcloud image, but in the first place I would ensure if in the exact configuration you have, there is no typo in the VIRTUAL_HOST environment variable. In the example it looks good, but in the actual compose file you use there might be a typo that would cause it to fail.
The other services work, so the nextcloud setup might need something yet to work with nginx-proxy.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tymik |
