2015-05-10 60 views
5

我對Python非常陌生,並且正在處理我的第一個django項目。我跟着this教程。我設法配置所有的東西,但django應用程序本身。它可以工作,如果我單獨運行django服務器,但它由uwsgi啓動時不起作用。Django,uwsgi和nginx - 內部服務器錯誤

這是我的uwsgi的conf:

import os 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings") 

application = get_wsgi_application() 

誤差和從uwsgi登錄:

--- no python application found, check your startup logs for errors --- 

於是我擡起頭來啓動錯誤:

Traceback (most recent call last): 
    File "./wsgi.py", line 16, in <module> 
    application = get_wsgi_application() 
    File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application 
    django.setup() 
    File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup 
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) 
    File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__ 
    self._setup(name) 
    File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup 
    self._wrapped = Settings(settings_module) 
    File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__ 
    mod = importlib.import_module(self.SETTINGS_MODULE) 
    File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module 
    __import__(name) 
ImportError: No module named api.settings 

我的項目的dirtree:

. 
|-- api 
| |-- __init__.py 
| |-- __init__.pyc 
| |-- media 
| | `-- sample-media.jpg 
| |-- settings.py 
| |-- settings.pyc 
| |-- urls.py 
| |-- urls.pyc 
| |-- wsgi.py 
| `-- wsgi.pyc 
|-- db.sqlite3 
|-- manage.py 
|-- static 
| `-- admin 
|  ... ... ... ... 
|-- uwsgi_conf.ini 
`-- uwsgi_params 

我希望我提供了足夠的信息,但我可以告訴你更多 - 問題是我實際上不知道在哪裏尋找。

感謝提前:)

回答

10

你可能缺乏chdir線在你uwsgi_conf.ini。或者,您可能有chdir一行,但這是錯誤的。

這是由您回溯證實:

File "./wsgi.py", line 16, in <module> 

這裏你應該看到./api/wsgi.py,不./wsgi.py

顯然,uWSGI的工作目錄是api/目錄,而它應該是父目錄。

一般情況下,你的uWSGI配置文件應該是這樣的:

 
[uwsgi] 
chdir=/path/to/your/project 
module=mysite.wsgi:application 
... 

又見Django documentation on uWSGI

+0

好的,謝謝@Andrea COrbellini。它幫助我進入下一個階段:現在我在uwsgi log中得到這個錯誤:'ImportError:沒有名爲py \ n 的模塊無法加載應用程序0(mountpoint ='')(callable not found or import error) –

+1

@ŽigaPatačkoKoderman:你有一個尾隨的'py'的地方。也許,你是不是編寫'api.wsgi.py'而不是'api.wsgi'? –

+0

謝謝@Andrea Corbellini。誠然,我將wsgi文件命名爲wsgi.py而不是api.wsgi。非常感謝你:),你能編輯你的文章,並添加你在這個評論中告訴我的內容,這樣其他人可以很容易地看到它嗎? –