I am running a django app with nginx in a docker container and everything was running perfectly fine up until I rebuild the container. Suddenly I get a 502 (Bad Gateway) error and the logs say
(111: Connection refused) while connecting to upstream, client: 216.245.221.82
I have no idea what changed to be honest and I am a new with nginx. The django/python code should not have changed. I am pulling the latest nginx image so maybe there was a change which doesn't work well with my config. But I tried wit older versions too and get the same error. Maybe my app crashes since there is no port it is listening to? (see screenshot)
I tried adjusting the ALLOWED_HOSTS to ['*']
, setting SSL_NO_VERIFY to True and False, still same error. I am out of options.... I don't know how to debug it better. Locally the app works well, so setting debug to True didn't help me.
I just don't know. I am deploying my app on an EC2 instance with nginx in a docker container.
Here are my configs and my compose file:
server {
listen 443 ssl;
server_name mywebsite.de;
client_max_body_size 0;
charset utf-8;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/mywebsite.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.de/privkey.pem;
set $my_host $http_host;
if ($http_host = "mywebsite.de") {
set $my_host "mywebsite.de";
}
location / {
proxy_pass http://django:5000;
proxy_set_header Host $my_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80 ;
server_name mywebsite.de;
return 301 https://mywebsite.de$request_uri;
}
server {
listen 80 ;
server_name www.mywebsite.de;
return 301 https://mywebsite.de$request_uri;
}
server {
listen 443 ;
server_name www.mywebsite.de;
return 301 https://mywebsite.de$request_uri;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/mywebsite.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.de/privkey.pem;
}
version: '3'
services:
django:
build:
context: .
dockerfile: ./compose/production/django/Dockerfile
image: my_website_production_django
env_file:
- ./.envs/.production/.django
- ./.envs/.production/.postgres
command: /start
nginx:
container_name: 'nginx'
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes: ##The following files are found on AWS EC2 instance.
- /home/ubuntu/nginx-conf/my.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt/live/mydomain.de/fullchain.pem:/etc/letsencrypt/live/mydomain.de/fullchain.pem
- /etc/letsencrypt/live/mydomain.de/privkey.pem:/etc/letsencrypt/live/mydomain.de/privkey.pem
depends_on:
- django
redis:
image: redis:5.0
Happily providing more info or code if needed. Truly desperate and grateful for help. Thank you.
0 Answers