Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy using wrong certificate #74

Closed
auchri opened this issue Jun 23, 2016 · 12 comments
Closed

Proxy using wrong certificate #74

auchri opened this issue Jun 23, 2016 · 12 comments

Comments

@auchri
Copy link

auchri commented Jun 23, 2016

I have multiple containers and if I open piwik.example.com, the certificate for pma.example.com is used.

But all other containers work correctly.

I start the containers like the following:

nginx-proxy

docker run -d -p 80:80 -p 443:443 \
    -v /srv/certs:/etc/nginx/certs:ro \
    -v /etc/nginx/vhost.d \
    -v /usr/share/nginx/html \
    -v /var/run/docker.sock:/tmp/docker.sock:ro \
    --name proxy --restart always jwilder/nginx-proxy

letsencrypt-nginx-proxy-companion

docker run -d \
    -v /srv/certs:/etc/nginx/certs:rw \
    -v /var/run/docker.sock:/var/run/docker.sock:ro \
    --volumes-from proxy \
    --name letsencrypt --restart always jrcs/letsencrypt-nginx-proxy-companion

piwik.example.com

docker run -d -e VIRTUAL_HOST=piwik.example.com -h piwik.example.com \
    -e LETSENCRYPT_HOST=piwik.example.com -e LETSENCRYPT_EMAIL=info@example.com \
    -v /srv/web/piwik/public:/var/www/html \
    --name site1 --restart always richarvey/nginx-php-fpm

pma.example.com

docker run -d -e VIRTUAL_HOST=pma.example.com -h pma.example.com \
    -e LETSENCRYPT_HOST=pma.example.com -e LETSENCRYPT_EMAIL=info@example.com \
    -v /srv/web/pma/public:/var/www/html \
    --name asd --restart always richarvey/nginx-php-fpm

If I open piwik.example.com in a browser, the certificate for pma.example.com is used, even if the container for site1 is not started 😟:

Images

image

image

Output of docker ps:

image

@JrCs
Copy link
Collaborator

JrCs commented Jun 23, 2016

This must works.
Perhaps is a bad nginx.tmpl in nginx-proxy.
Try to look at the generated /etc/nginx/conf.d/default.conf nginx file.

@auchri
Copy link
Author

auchri commented Jun 23, 2016

I copied the file from the container to the host and it looks like this:

# 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 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;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';
access_log off;
# HTTP 1.1 support
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;
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;
}
upstream pma.example.com {
                                ## Can be connect with "bridge" network
                        # pma
                        server 172.17.0.5:80;
}
server {
        server_name pma.example.com;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        return 301 https://$host$request_uri;
}
server {
        server_name pma.example.com;
        listen 443 ssl http2 ;
        access_log /var/log/nginx/access.log vhost;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:EC$
        ssl_prefer_server_ciphers on;
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_certificate /etc/nginx/certs/pma.example.com.crt;
        ssl_certificate_key /etc/nginx/certs/pma.example.com.key;
        ssl_dhparam /etc/nginx/certs/pma.example.com.dhparam.pem;
        add_header Strict-Transport-Security "max-age=31536000";
        include /etc/nginx/vhost.d/default;
        location / {
                proxy_pass http://pma.example.com;
        }
}

The host which gets the wrong certificate is not even mentioned 😳

@auchri
Copy link
Author

auchri commented Jun 23, 2016

It happens in all browser and even at http://web-sniffer.net/

@JrCs
Copy link
Collaborator

JrCs commented Jun 23, 2016

The piwik container is not in the default.conf file.
So check your docker run to see if you are not done a mistake.
VIRTUAL_HOST is only use in this case.
After you start the piwik container IT MUST APPEAR in the default.conf file.

@auchri
Copy link
Author

auchri commented Jun 23, 2016

I edited the first comment. The piwik container is not started and still gets the wrong certificate from pma.example.com. After I accept the wrong certificate, I can see the site from pma.example.com at piwik.example.com

@auchri
Copy link
Author

auchri commented Jun 23, 2016

I stopped and removed all containers and deleted the content of the certs folder. Now I restarted all containers and now it's working.

@JrCs JrCs closed this as completed Jun 24, 2016
@auchri
Copy link
Author

auchri commented Jun 25, 2016

The same issue happened again today.

@TLATER
Copy link

TLATER commented Oct 13, 2016

Would it be difficult to prevent serving the wrong certificate in this case? It's hard to realize that the container is actually down if you get a certificate error instead of a 404.

Though granted, when a container is down unnoticed you have other issues...

@JulianKingman
Copy link

@auchri did you solve this?

@guoxiangke
Copy link

the same error!

@psytron
Copy link

psytron commented Jul 13, 2018

Same error here

@buchdag
Copy link
Member

buchdag commented Jul 14, 2018

@psytron is it the same issue as #373 and #411 ? It seems to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants