首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >uWSGI + nginx for django项目,与strting uwsgi错误

uWSGI + nginx for django项目,与strting uwsgi错误
EN

Stack Overflow用户
提问于 2011-12-14 15:24:22
回答 2查看 19.7K关注 0票数 7

我尝试在nginx+uwsgi,os - debian (3.1.0-1-AMD 64 x86_64) nginx 1.1.8-1,uwsgi 0.9.8.3-1配置上为django安装try服务器:

代码语言:javascript
复制
<uwsgi>
<socket>/tmp/uwsgi.sock</socket>
<process>1</process>
<master/>
<enable-threads/>
<uid>33</uid>
<gid>33</gid>
<pidfile>/tmp/uwsgi.pid</pidfile>
</uwsgi>

文件/etc/uwsgi/apps启用/webapp.xml nginx配置

代码语言:javascript
复制
location / {
        uwsgi_pass unix:///tmp/uwsgi.sock;
        include uwsgi_params;
        uwsgi_param UWSGI_SCRIPT webapp;
        uwsgi_param UWSGI_CHDIR  /data/web/webapp/webapp;
    }

所有projet在/data/web/webapp/webapp/,这里是setting.py,urls等等。in /data/web/webapp/webapp/webapp.py

代码语言:javascript
复制
import sys, os
import django.core.handlers.wsgi
sys.path.insert(0, '/data/web/webapp/webapp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()

是www-数据用户尝试运行uwsgi

root#uwsgi -s /var/run/uwsgi.ock -x /etc/uwsgi/apps启用/webapp.xml

代码语言:javascript
复制
[uWSGI] parsing config file /etc/uwsgi/apps-enabled/webapp.xml
*** Starting uWSGI 0.9.8.3-debian (64bit) on [Wed Dec 14 21:42:02 2011] ***
compiled with version: 4.6.1 on 27 July 2011 18:25:51
writing pidfile to /tmp/uwsgi.pid
uWSGI running as root, you can use --uid/--gid/--chroot options
setgid() to 33
setuid() to 33
your memory page size is 4096 bytes
unlink(): Permission denied [socket.c line 38]
bind(): Address already in use [socket.c line 70]

他们想要什么许可?有什么问题..。如果我以根错误的形式运行uwsgi,我会看到

代码语言:javascript
复制
 *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your memory page size is 4096 bytes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi.sock fd 3
uwsgi socket 1 bound to UNIX address /tmp/uwsgi.sock fd 4
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 20732)
spawned uWSGI worker 1 (pid: 20733, cores: 1)

但是当我试图访问服务器时,ngix返回502错误页。更多信息: nginx日志中的权限错误:

代码语言:javascript
复制
 2011/12/14 21:57:17 [crit] 20739#0: *1 connect() to unix:///tmp/uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: 10.10.3.111, server: ******, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "****.****.**"

如果在运行时将/tmp/uwsgi.sock的所有者更改为nginix用户(www-data),他会编写其他日志。

代码语言:javascript
复制
[error] 20739#0: *21 upstream prematurely closed connection while reading response header from upstream,

但仍然错误502 (

如何解决这个问题?有人能帮我..。真的想使用nginx+uwsgi而不是apache。谢谢

但是,解决方案已经接近:)我现在更多地使用tcp套接字,更改uwsgi配置,并安装了更多的软件包。是个很重要的选择现在,uwsgi具有这样的配置:

代码语言:javascript
复制
<uwsgi>
<module>webapp</module>
<socket>127.0.0.1:5080</socket>
<pythonpath>/data/web/webapp/webapp</pythonpath>
<autoload/>
<daemonize>/var/log/uwsgi_webapp.log</daemonize>
<processes>1</processes>
<uid>33</uid>
<gid>33</gid>
<enable-threads/>
<master/>
<harakiri>120</harakiri>
<max-requests>5000</max-requests>
</uwsgi>

仍然需要解决其他问题..。uwsgi使用的不是主要系统python版本>_<。

代码语言:javascript
复制
option "pythonpath" found in plugin python26_plugin.so
*** Starting uWSGI 0.9.8.3-debian (64bit) on [Thu Dec 15 22:52:23 2011] ***
compiled with version: 4.6.1 on 27 July 2011 18:25:51
uWSGI running as root, you can use --uid/--gid/--chroot options
setgid() to 33
setuid() to 33
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** 
uwsgi socket 0 bound to TCP address 127.0.0.1:5080 fd 4
Python version: 2.6.7 (r267:88850, Aug  3 2011, 12:02:14)  [GCC 4.6.1]
Python main interpreter initialized at 0xc47df0
threads support enabled
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
added /data/web/webapp/webapp/ to pythonpath.
WSGI application 0 (SCRIPT_NAME=) ready on interpreter 0xc47df0 pid: 22983 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 22983)
spawned uWSGI worker 1 (pid: 22984, cores: 1)

他使用python 2.6.7,但主要系统版本是2.7.2,并且为此安装了所有python模块,因此在日志重复尝试中出现了许多错误,不存在导入,这是许多典型错误之一:

代码语言:javascript
复制
  File "/usr/lib/python2.6/dist-packages/django/db/__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "/usr/lib/python2.6/dist-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/lib/python2.6/dist-packages/django/db/utils.py", line 51, in load_backend
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend. 
Try using django.db.backends.XXX, where XXX is one of:
    'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named django_mongodb_engine.base

所以..。如何为uwsgi设置python版本?

EN

回答 2

Stack Overflow用户

发布于 2011-12-15 02:24:20

unix套接字必须服从文件权限方案。所以/var/run必须是www-data可写的,nginx必须能够读/写/var/run/uwsgi.sock

如果您不熟悉这类事情,应该使用tcp套接字(选择一个端口,您就准备好了)

票数 7
EN

Stack Overflow用户

发布于 2012-10-27 06:33:32

如何为uwsgi设置python版本?

在uwsgi设置中设置选项插件:

代码语言:javascript
复制
[uwsgi]
...
plugins = python27
...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8507027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档