簡體   English   中英

用於django項目的uWSGI + nginx,使用strting uwsgi時出錯

[英]uWSGI + nginx for django project, error with strting uwsgi

我嘗試在nginx + uwsgi上運行django的webserver,os - debian(3.1.0-1-amd64 x86_64)nginx 1.1.8-1,uwsgi 0.9.8.3-1配置:

<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-enabled/webapp.xml nginx配置中

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,網址等。 在/data/web/webapp/webapp/webapp.py中

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()

uid和gid 33它是www-data用戶嘗試運行uwsgi as

root#uwsgi -s /var/run/uwsgi.sock -x /etc/uwsgi/apps-enabled/webapp.xml

[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作為root錯誤消失了,我明白了

 *** 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日志中的權限錯誤:

 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: "****.****.**"

如果在運行時(www-data)將/tmp/uwsgi.sock的所有者更改為nginix用戶,他寫了其他日志

[error] 20739#0: *21 upstream prematurely closed connection while reading response header from upstream,

但仍然是錯誤502(

怎么解決這個問題? 有人可以幫助我..真的想用nginx + uwsgi而不是apache。 謝謝


但是,解決方案就在附近:)我現在使用tcp socket以及更多,更改uwsgi配置並安裝了更多的軟件包。 是一個重要的選擇--autoload。 現在uwsgi有這樣的配置:

<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版本> _ <

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模塊,因此日志中出現了很多錯誤 - 重復嘗試導入不存在的,這是許多典型錯誤之一:

  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版本?

unix套接字必須遵守文件權限方案。 所以/ var / run必須可以通過www-data寫入,而nginx必須能夠讀/寫/var/run/uwsgi.sock

如果你不熟悉這類東西,你應該使用tcp套接字(選擇一個端口,你准備好了)

如何設置uwsgi的python版本?

在uwsgi設置中設置選項插件

[uwsgi]
...
plugins = python27
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM