docker で nginx-proxy と letsencrypt を使用して nginx コンテナーを実行しています。
2 つのアプリを別々のサブドメインで実行したい:
- jenkins.mydomain.de
- wekan.mydomain.de
プロキシを使用して nginx 構成ファイルを開始し、これら 2 つのアプリとは別に letencrypt を使用します。
一度に1つだけ実行すると、両方のアプリをnginxで実行できます。
しかし、両方を同時に実行すると、最後のものだけにアクセスできます
.2番目は完全に正常に動作し、最初は502「Bad Gateway」を返します。
bash 経由で nginx コンテナに入ると -> /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;
}
}
これらの構成は、nginx-proxy conatiner によって自動的に作成されます。
ファイルと構成に問題が見つかりません..
これは私が始めたい私の docker-compose.yml です:
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
ここでは wekan だけが正しく実行されています。Jenkins は 502 "Bad Gateway" を返しています。手伝ってくれませんか?
編集:これらはnginxのログのエントリです:
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"