Search code examples
dockernginxflaskdeploymentuwsgi

Nginx+uwsgi. Works fine on localhost, but not on remote machine. WHY


Case: In docker network is created with:

docker network create --attachable --subnet 1.1.1.0/29 some-network

1st container is Flask+uwsgi and is launched like:

docker run -d --rm --net some-network --ip 1.1.1.4 \
-p 8080:8080 --name my-flask my-flask-image

uwsgi ini looks like:

[uwsgi]
module = app:app
master = true
processes = 2
socket = :8080

2nd container is nginx and is launched like:

docker run -d --rm --net some-network --ip 1.1.1.2 \
-p 80:80 --name my-nginx my-nginx-image

config only adds next server config

upstream app_dev {
    server  1.1.1.4:8080;
}
server {
    listen 80;
    server_name develop.localhost;

    location / {
        include uwsgi_params;
        uwsgi_pass app_dev;
    }
}

I run containers and i access develop.localhost without any problem.

However when I run containers on remote machine with domain_name(surely with added A record I can access server through ssh by domain_name) I can't access not nginx, not uwsgi: docker logs show no requests.

I can only access(from browser) by ip address but then nginx respond with 502. nginx config slightly changes from local only ssl stuff(and ssl) with domain_name added

server {
    listen 80;
    listen 443 ssl;
    server_name develop.domainname.com;
    ssl_certificate /etc/nginx/ssl/CERTIFICATE.crt;
    ssl_certificate_key /etc/nginx/ssl/KEY.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    
    location / {
        include uwsgi_params;
        uwsgi_pass app_dev;
    }
}

I have no idea how to diagnose problem - I don't understand why logs are empty.


Solution

  • While i was typing this case i realized problem.
    I did not exposed 443 port for nginx. I added port to run command and it kinda works.

    -p 443:443
    

    "kinda" - because after that firefox started screaming that i have bad ssl certificate. Apparently godaddy gave me ssl-certificate for www.domain.com and domain.com, but not for wildcard domains.