Can't register more than one subdomain this nginx and nginx-proxy with docker container


I am running an nginx container with nginx-proxy and letencrypt in docker.
I want two applications to run on separate subdomains:

  • jenkins.mydomain.de
  • wekan.mydomain.de

I run my nginx compose file with proxy and disconnect from these two applications. Both applications can run on nginx if I just run one of them at a time.
But if I run them both at the same time, then only the last one can be accessed.
Seconds works fine and the first one returns 502 "Bad Gateway".
When I go to my nginx container via bash -> /etc/nginx/config.d/default.config

# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  default $http_x_forwarded_proto;
  ''      $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
  default $http_x_forwarded_port;
  ''      $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
  default upgrade;
  '' close;
}
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
  default off;
  https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application$
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';
access_log off;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
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 $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
        server_name _; # This is just an invalid value which will never trigger on a real hostname.
        listen 80;
        access_log /var/log/nginx/access.log vhost;
        return 503;
}
# jenkins.mydomain.de
upstream jenkins.mydomain.de {
                                ## Can be connect with "nginx_default" network
                        # nginxapps_jenkins_1
                        server 172.19.0.5:8080;
}
server {
        server_name jenkins.mydomain.de;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        return 301 https://$host$request_uri;
}
server {
        server_name jenkins.mydomain.de;
        listen 443 ssl http2 ;
        access_log /var/log/nginx/access.log vhost;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-R$
        ssl_prefer_server_ciphers on;
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;
        ssl_certificate /etc/nginx/certs/jenkins.mydomain.de.crt;
        ssl_certificate_key /etc/nginx/certs/jenkins.mydomain.de.key;
        ssl_dhparam /etc/nginx/certs/jenkins.mydomain.de.dhparam.pem;
        add_header Strict-Transport-Security "max-age=31536000";
        include /etc/nginx/vhost.d/default;
        location / {
                proxy_pass http://jenkins.mydomain.de;
        }
}
# wekan.mydomain.de
upstream wekan.mydomain.de {
                                ## Can be connect with "nginx_default" network
                        # nginxapps_wekan_1
                        server 172.19.0.7:80;
}
server {
        server_name wekan.mydomain.de;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        return 301 https://$host$request_uri;
}
server {
        server_name wekan.mydomain.de;
        listen 443 ssl http2 ;
        access_log /var/log/nginx/access.log vhost;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-R$
        ssl_prefer_server_ciphers on;
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;
        ssl_certificate /etc/nginx/certs/wekan.mydomain.de.crt;
        ssl_certificate_key /etc/nginx/certs/wekan.mydomain.de.key;
        ssl_dhparam /etc/nginx/certs/wekan.mydomain.de.dhparam.pem;
        add_header Strict-Transport-Security "max-age=31536000";
        include /etc/nginx/vhost.d/default;
        location / {
                proxy_pass http://wekan.mydomain.de;
        }
}

      

These configurations are created automatically by nginx-proxy conatiner.
I cannot find any problem with my file and configuration.

This is my docker-compose.yml I want to start:

version: "3"
services:
   jenkins:
     image: jenkins
     volumes:
       - /etc/jenkins:/var/jenkins_home
     ports:
       - "50000:50000"
     networks:
       - default
     environment:
       - VIRTUAL_HOST=jenkins.mydomain.de
       - VIRTUAL_PORT=8080
       - LETSENCRYPT_HOST=jenkins.mydomain.de
       - LETSENCRYPT_EMAIL=jenkins@mydomain.de
   wekan:
    image: wekanteam/wekan:meteor-1.4
    links:
       - wekandb
    networks:
        - default
    environment:
       - MONGO_URL=mongodb://wekandb/wekan
       - ROOT_URL=http://mytodo.org
       - MAIL_URL=smtp://user:pass@mailserver.example.com:25/
       - MAIL_FROM=wekan-admin@example.com
       - VIRTUAL_HOST=wekan.mydomain.de
       - VIRTUAL_PORT=80
       - LETSENCRYPT_HOST=wekan.mydomain.de
       - LETSENCRYPT_EMAIL=wekan@mydomain.de
   wekandb:
     image: mongo
     volumes:
       - /home/wekan/data:/data/db
networks:
  default:
    external:
      name: nginx_default

      

Here wekan just works correctly. Jenkins returns 502 "Bad Gateway". Can you help me?

Edit: These are the nginx log entries:

jenkins.mydomain.de 46.5.2.115 - - [01/May/2017:14:58:43 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"
2017/05/01 14:58:43 [error] 6#6: *290 connect() failed (111: Connection refused) while connecting to upstream, client: 46.5.2.115, server: jenkins.mydomain.de, request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.19.0.6:8080/favicon.ico", host: "jenkins.mydomain.de", referrer: "https://jenkins.mydomain.de/"
jenkins.mydomain.de 46.5.2.115 - - [01/May/2017:14:58:43 +0000] "GET /favicon.ico HTTP/1.1" 502 576 "https://jenkins.mydomain.de/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"

      

+3


source to share





All Articles