2013-08-31 184 views
1

我想用uwsgi和nginx爲django 1.5應用程序提供服務。以下是我的ini文件用uwsgi和nginx設置django

[uwsgi] 
# variables 
projectname = mysite 
projectdomain = mysite.in 
base = /home/shwetanka/projects/me/mysite 

# config 
plugins = python 
master = true 
protocol = uwsgi 
env = DJANGO_SETTINGS_MODULE=%(base)/%(projectname).settings 
#pythonpath = %(base)/src/%(projectname) 
module = %(base)/mysite/wsgi.py 
socket = 127.0.0.1:8889 
logto = %(base)/logs/uwsgi.log 
#below line runs it as a daemon in background 
daemonize = /var/log/uwsgi/mysite.log 

我越來越日誌中這個錯誤 -

Sat Aug 31 14:05:35 2013 - *** Starting uWSGI 1.2.3-debian (64bit) on [Sat Aug 31 14:05:35 2013] *** 
Sat Aug 31 14:05:35 2013 - compiled with version: 4.7.2 on 07 November 2012 03:49:52 
Sat Aug 31 14:05:35 2013 - detected number of CPU cores: 4 
Sat Aug 31 14:05:35 2013 - current working directory:/
Sat Aug 31 14:05:35 2013 - detected binary path: /usr/bin/uwsgi-core 
Sat Aug 31 14:05:35 2013 - your memory page size is 4096 bytes 
Sat Aug 31 14:05:35 2013 - detected max file descriptor number: 1024 
Sat Aug 31 14:05:35 2013 - lock engine: pthread robust mutexes 
Sat Aug 31 14:05:35 2013 - uwsgi socket 0 inherited UNIX address /run/uwsgi/app/mysite/socket fd 3 
Sat Aug 31 14:05:35 2013 - uwsgi socket 1 inherited INET address 127.0.0.1:8889 fd 5 
Sat Aug 31 14:05:35 2013 - Python version: 2.7.4 (default, Apr 19 2013, 18:30:41) [GCC 4.7.3] 
Sat Aug 31 14:05:35 2013 - *** Python threads support is disabled. You can enable it with --enable-threads *** 
Sat Aug 31 14:05:35 2013 - Python main interpreter initialized at 0xd36dc0 
Sat Aug 31 14:05:35 2013 - your server socket listen backlog is limited to 100 connections 
Sat Aug 31 14:05:35 2013 - *** Operational MODE: preforking *** 
ImportError: Import by filename is not supported. 
Sat Aug 31 14:05:35 2013 - unable to load app 0 (mountpoint='') (callable not found or import error) 
Sat Aug 31 14:05:35 2013 - *** no app loaded. going in full dynamic mode *** 
Sat Aug 31 14:05:35 2013 - *** uWSGI is running in multiple interpreter mode *** 
Sat Aug 31 14:05:35 2013 - gracefully (RE)spawned uWSGI master process (pid: 6093) 
Sat Aug 31 14:05:35 2013 - spawned uWSGI worker 1 (pid: 6245, cores: 1) 
Sat Aug 31 14:05:35 2013 - spawned uWSGI worker 2 (pid: 6246, cores: 1) 

我如何得到它的工作?

回答

19

ImportError: Import by filename is not supported.

--module指令期望一個模塊,而不是文件。您應該使用--wsgi-file

2

您需要致電與Django的模塊:--module mysite.wsgi:application

而且不要忘了補充:--env DJANGO_SETTINGS_MODULE=mysite.settings

例如,工作命令行(前提是您的當前目錄是項目主頁):

uwsgi --socket mysite/zohosel.sock --module mysite.wsgi:application --env DJANGO_SETTINGS_MODULE=mysite.settings --home=/path/to/your/venv --chmod-socket=666 

一些額外的信息和參數可以在the django docs website找到。
順便說一句,這tutorial on readthedocs幫了我很多。