Answer the question
In order to leave comments, you need to log in
Docker, Django, Nginx, Gunicorn sometimes showing 502 Bad gateway error, how to fix?
Goodnight. I deployed the project, fixed a couple of errors that I didn’t find locally, received an ssl certificate, everything became relatively normal, only now I began to notice that after 1-5 reloads of the site I get a 502 error page (the server is behind cloudflare)
A lot of sites clambered on info, more than 30 links with different options for fixing the problem, but nothing helped, everything is the same, either the page is loaded, or the error.
Due to the fact that I can’t even understand where to dig, I won’t upload the source files initially, tell me which ones you need to provide - I’ll publish it. I ask to help, who faced and solved the problem. I do not understand why SOMETIMES the error gets out. If I always climbed out, then perhaps it would be easier to decide.
nginx.conf:
upstream hello_server {
server web:8000;
}
server {
listen 443 ssl;
listen [::]:443;
listen 80;
listen [::]:80;
charset utf-8;
#ssl on;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
#error_page 497 https://$host:$server_port$request_uri;
location / {
proxy_pass http://hello_server;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://hello_server;
break;
}
}
location /staticfiles/ {
alias /usr/src/app/staticfiles/;
}
location /mediafiles/ {
alias /usr/src/app/mediafiles/;
}
}
server {
listen 443 ssl;
listen [::]:443;
listen 80;
listen [::]:80;
charset utf-8;
#ssl on;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
#error_page 497 https://$host:$server_port$request_uri;
location / {
proxy_pass http://web:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
location /staticfiles/ {
alias /usr/src/app/staticfiles/;
}
location /mediafiles/ {
alias /usr/src/app/mediafiles/;
}
}
LOG: invalid length of startup packet
LOG: invalid length of startup packet
Why the error disappeared is unknown. Although I did a lot of things with the database, and other connections, and other versions, but in the past this did not fix the problem in any way.
Answer the question
In order to leave comments, you need to log in
here in the first config it goes into if (!-f $request_filename) {...} sometimes. and throws an error. I need to replace it with something, I don't know what. here you go - and there will be no errors with timeouts, check
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question