Reputation: 143
i want to run django with nginx i followed this instructions and in
/etc/nginx/sites-available/cartoview_one
upstream django {
server unix:///root/cartoview_project/mysite.sock; # for a file socket }
server {
listen 80;
server_name xx.xx.xx.xx;
charset utf-8;
# max upload size
client_max_body_size 2048M; # adjust to taste
# Django media
location /media {
alias /root/cartoview_project/uploaded;
}
location /static {
alias /root/cartoview_project/static;
}
location / {
uwsgi_pass django;
include /root/cartoview_project/uwsgi_params; # the uwsgi_params file you installed
}
}
then created symlink using:
sudo ln -s /etc/nginx/sites-available/cartoview_one /etc/nginx/sites-enabled
and in project folder mysite_uwsgi.ini
:
[uwsgi]
project = cartoview_project
chdir = /root/cartoview_project
module = %(project).wsgi:application
home = /root/env
master = true
processes = 10
socket = /root/cartoview_project/mysite.sock
chmod-socket = 666
vacuum = true
http-socket = 0.0.0.0:80
project structure :
. |-- apps |-- cartoview_project | |-- __init__.py | |-- __init__.pyc | |-- local_settings.py | |-- local_settings.pyc | |-- local_settings.py.sample | |-- settings.py | |-- settings.pyc | |-- urls.py | |-- wsgi.py | `-- wsgi.pyc |-- default_oauth_apps.json |-- initial_data.json |-- manage.py |-- mysite_uwsgi.ini `-- uwsgi_params
when i try to access website with myip this message appear :
502 Bad Gateway
nginx/1.10.0 (Ubuntu)
error.log :
2017/02/06 09:46:41 [crit] 6867#6867: *1 connect() to unix:///root/cartoview_project/mysite.sock failed (13: Permission denied) while connecting to upstream, client: xx.xx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///root/cartoview_project/mysite.sock:", host: "xxx.xxx.xxx.xxx"
Update :
i removed http-socket
and run the following command /root/env/bin/uwsgi --ini mysite_uwsgi.ini
and mysite.sock
appeared in project then restart nginx but nothing changed.
:~/cartoview_project# stat mysite.sock
File: 'mysite.sock'
Size: 0 Blocks: 0 IO Block: 4096 socket
Device: 802h/2050d Inode: 17172079 Links: 1
Access: (0666/srw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-02-06 10:44:56.188168371 +0100
Modify: 2017-02-06 10:44:56.188168371 +0100
Change: 2017-02-06 10:44:56.188168371 +0100
Birth: -
Machine : vps(Ubuntu 16.04) User: root
Solved :
by changing include /root/cartoview_project/uwsgi_params
to include /etc/nginx/uwsgi_params;
Upvotes: 2
Views: 11361
Reputation: 3178
From the description, it looks like you haven't run your uwsgi process - a 502 error at this point means that nginx is passing the response through correctly, but there's nothing for it to connect to, or it's not getting the correct response.
which uwsgi
will give you the path for the appropriate uwsgi (do this inside your virtualenv if you're running one).
e.g.
/root/cartoview_project/uwsgi --ini mysite_uwsgi.ini
You should take the http-socket
config variable out of uwsgi though - nginx is listening on port 80, and passing it through to your .sock
file created by your uwsgi app.
Upvotes: 1