I am using post request to load a big amount of data from user input (textarea) to the database(18k lines)
And I get the 502 Bad Gateway error
When I print sudo nano /var/log/nginx/error.log
I get this:
2018/09/06 10:21:04 [alert] 19688#19688: *3 open socket #22 left in connection 4
2018/09/06 10:21:04 [alert] 19688#19688: aborting
2018/09/06 11:04:32 [error] 20076#20076: *14 upstream prematurely closed connection while reading response header from upstream, client: 95.1$
This is only on my production server (nginx + gunicorn + postgres), on my dev server it works great.
What do I do?
I have also
Increasing timeout in gunicorn helped to solve the issue
Related
I'm learning to deploy my Flask app onto an Ubuntu AWS EC2 instance and am following the Digital Ocean tutorial. I'm and am encountering one final issue: I'm got my Gunicorn booted up and working using this command: gunicorn --workers 3 --bind unix:project.sock -m 007 wsgi:app to create 3 worker threads and a socket called project.sock.
[2018-02-23 17:14:49 +0000] [INFO] Booting worker with pid: X
[2018-02-23 17:14:49 +0000] [INFO] Booting worker with pid: X
[2018-02-23 17:14:49 +0000] [INFO] Booting worker with pid: X
Connection initialized.
Connection initialized.
Connection initialized.
But I'm encountering errors when attempting to have Nginx connect to my project.sock from Gunicorn- a 502 Bad Gateway error.
Here's my /etc/nginx/sites-available/project configurations:
server {
listen 80;
server_name MY_SERVER_DNS;
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/flaskapp_dev/my_project/project.sock;
}
}
A check of the Nginx error logs shows that it's getting a Permission denied error attempting to connect to my project.sock:
2018/02/23 17:26:46 [crit] 10822#10822: *4 connect() to unix:/home/ubuntu/myproject/myproject/myproject.sock failed
(13: Permission denied) while connecting to upstream,
client: CLIENT_IP, server: MY_SERVER_DNS,
request: "GET / HTTP/1.1",
upstream: "http://unix:/home/ubuntu/myproject/myproject/project.sock:/", host: "MY_SERVER_DNS"
I know there's been plenty of SO posts on this question, but I'm noticing that most of them revolve around uwsgi, which I'm not using here. I suspect that it's obviously a permission issue, so I tried chmod 711 /home/ubuntu/myproject/project and restarting nginx, but that results in the same 502 Bad Gateway error.
The closest SO post to my issue appears to be this one, but it has no answers or comments.
This is just a permissions issue. Nginx that's running under one user cannot get access to unix socket that's owned by another user. I recommend to run nginx server and gunicorn under the same user so unix socket created by gunicron will be accessed by nginx without any problems. chmod 777 is a temporal solution that can show that there is only permission issue if after executing this command the described problem has gone, but it's better to initially run nginx and gunicorn under the same user. Also it's better to specify full path to unix socket to avoid "no such file or directory" possible issue: gunicorn --workers 3 --bind <full_path_to_unix_socket_to_be_created>
I'm trying to run my Django app using Nginx and uWSGI. When I try to go to
127.0.0.1:8001/media/media.png
Nginx properly shows the image, but when I go to
127.0.0.1:8000/CMS/users
Django is supposed to call a view. Instead, Nginx returns a 504 Gateway Time-out. When I view the Nginx error log, it says
*6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 127.0.0.1, server: 192.168.174.131, request: "GET /CMS/users HTTP/1.1", upstream: "uwsgi://127.0.0.1:8001", host: "127.0.0.1:8000"
Does a uWSGI error log file exist? If yes, where can I find it? (I'm searching for it because I think it might help debug the issue).
Note: I installed uwsgi using pip.
I've installed gunicorn, django and nginx as described in this tutorial.
I've developed a function in django that adds a user in my database and it works perfectly!!
Now I've installed CSF (Config Server Firewall) and if I run it csf -r, the same function for adding a user doesn't work.
I see, in the error log of Nginx, this raw:
*2014/06/25 10:11:04 [error] 5396#0: *19 upstream prematurely closed connection while reading response header from upstream, client: 79.35.50.121, server: [MY_SERVER_NAME], request: POST /django/registerClient HTTP/1.1, upstream: [MY_IP_SERVER]:8001/django/registerClient, host: [MY_IP_SERVER]*
I underline that the function work without star csf.
Can anyone can explain to me why I get this problem?
After restarting my django app: supervisorctl restart [process] I've got Bad Request(400) error when visiting my site. The app is under nginx with gunicorn and supervisor.
I remember to had the same problem some time ago and restarting supervisor from some specific folder on the server had helped. I've tried to restart supervisor from different locations, however it doesn't help.
nginx-error.log
2014/04/08 06:45:23 [error] 9635#0: *9 connect() to
unix:/webapps/filmyposlowie/run/gunicorn.sock failed (111: Connection
refused) while connecting to upstream, client: 78.10.91.212, server:
filmyposlowie.pl, request: "GET / HTTP/1.1", upstream:
"http://unix:/webapps/filmyposlowie/run/gunicorn.sock:/", host:
"filmyposlowie.pl"
I have the same issue, I solved it by adding these two lines in my nginx's server config file
proxy_set_header Host $http_host;
proxy_redirect off;
When you change DEBUG setting to False, you must also set ALLOWED_HOSTS.
You may simply make Django accept requests by allowing localhost:
ALLOWED_HOSTS = ['127.0.0.1']
This will work if gunicorn is running on same machine and it is bound to 127.0.0.1
Ref: DEBUG
Finally, if DEBUG is False, you also need to properly set the
ALLOWED_HOSTS setting. Failing to do so will result in all requests
being returned as “Bad Request (400)”.
I've changed DEBUG to True in settings.py of my django project and it works fine now.
I am trying to add an application to an existing Django project, but once I have done it I get a 502 error.The server is running Ubuntu. I don't think it has to do with the applications code because I got it running on the django development server. It goes away when I take out the app's name from settings.py and restart gunicorn.
Here's a part of the log
2011/07/15 01:24:45 [error] 16136#0: *75593 connect() failed (111: Connection refused) while connecting to upstream, client: 24.17.8.152, server: staging.site.org, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8020/", host: "staging.site.org"
Here's the nginx config file.
Nginx Config File
I'm not sure what other information is needed. Not sure where the gunicorn logs are located. My server admin skills are kind of lacking.
Nginx isn't able to connect to your backend (gunicorn) or gunicorn is refusing the connection. You provided no details about the configuration so that's all the help you'll get. You are correct that the application code has nothing to do with it. It's a configuration error on your part.