繁体   English   中英

502错误的网关通过套接字将Nginx连接到Django

[英]502 Bad Gateway connecting Nginx to django via socket

我正在尝试按照http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html上的教程进行操作。 我已经将所有内容整理http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#running-the-django-application-with-uwsgi-and-nginx 我正在使用Amazon EC2上的Ubuntu 14.4实例:

我的django项目称为tp。 这是屏幕截图:

在此处输入图片说明

按照说明我已经完成:

(env1)ubuntu@ip-172-31-28-196:~$ uwsgi --socket /tmp/mysite.sock --module /home/ubuntu/tproxy/tp/tp
/wsgi.py --chmod-socket=664
*** Starting uWSGI 2.0.9 (64bit) on [Thu Mar  5 16:50:02 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-28-196
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7862
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/mysite.sock fd 3
Python version: 3.4.0 (default, Apr 11 2014, 13:08:40)  [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1fe5320
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named '/home/ubuntu/tproxy/tp/tp/wsgi'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 24393, cores: 1)

显然您可以看到:

ImportError: No module named '/home/ubuntu/tproxy/tp/tp/wsgi'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***

如何设置wsgi.py文件的路径?

编辑1:这是我的ini文件:

# mysite_uwsgi.ini file
 [uwsgi]
 # Django-related settings
 # the base directory (full path)
 chdir           = /home/ubuntu/tproxy/tp
 # Django's wsgi file
 module          = uwsgi
 # the virtualenv (full path)
 home            = /home/ubuntu/.virtualenvs/env1
 wsgi-file       = /home/ubuntu/tproxy/tp/tp/wsgi.py
 # process-related settings
 # master
 master          = true
 # maximum number of worker processes
 processes       = 3
 # the socket (use the full path to be safe
 socket          = /tmp/mysite.sock
 # ... with appropriate permissions - may be needed
 chmod-socket    = 664 
 # clear environment on exit
 vacuum          = true

我跑了:

(env1)ubuntu @ ip-172-31-28-196:〜$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini

但仍然出现502错误。

日志:

2015/03/05 18:10:00 [crit] 1828#0: *51 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 107.0.193.131, server: 52.10.**-**, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.**-**:8000"

编辑2:home是virtualenv的目录吗? 我设置:

home            = /home/ubuntu/tproxy/

现在:

(env1)ubuntu@ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Thu Mar  5 18:59:27 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-28-196
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/ubuntu/tproxy/tp
your processes number limit is 7862
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/mysite.sock fd 3
Python version: 3.4.0 (default, Apr 11 2014, 13:08:40)  [GCC 4.8.2]
Set PythonHome to /home/ubuntu/tproxy/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Aborted (core dumped)

在此处输入图片说明

您将其放在uwsgi ini文件中。 这是一个示例:

 [uwsgi]
 # Django-related settings
 # the base directory (full path)
 chdir           = /var/www/virtualenv/project
 # Django's wsgi file
 module          = uwsgi
 # the virtualenv (full path)
 home            = /var/www/virtualenv/
 wsgi-file       = /var/www/virtualenv/project/projectsettings/wsgi.py
 # process-related settings
 # master
 master          = true
 # maximum number of worker processes
 processes       = 10
 # the socket (use the full path to be safe
 socket          = /tmp/mysite.sock
 # ... with appropriate permissions - may be needed
 chmod-socket    = 664 
 # clear environment on exit
 vacuum          = true

这是我的ini文件,减去我到项目的路径。 我自己安装时也遇到了同样的问题,但通过查看Google上的其他配置可以找到适当的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM