2016-02-05 80 views
0

我不知道我到底錯過了什麼。下面是我至今:錯誤:在wsgi文件中部署Flask應用程序時導入錯誤

WSGI

/opt/tools/apps/scheduler/scheduler.wsgi

其內容

from scheduler import app as application 

init.py

/opt/tools/apps/scheduler/scheduler/__init__.py

在Apache日誌錯誤

[Thu Feb 04 21:54:30 2016] [error] [client 10.57.136.99] mod_wsgi (pid=45485): Target WSGI script '/opt/tools/apps/scheduler/scheduler.wsgi' cannot be loaded as Python module. 
[Thu Feb 04 21:54:30 2016] [error] [client 10.57.136.99] mod_wsgi (pid=45485): Exception occurred processing WSGI script '/opt/tools/apps/scheduler/scheduler.wsgi'. 
[Thu Feb 04 21:54:30 2016] [error] [client 10.57.136.99] Traceback (most recent call last): 
[Thu Feb 04 21:54:30 2016] [error] [client 10.57.136.99] File "/opt/tools/apps/scheduler/scheduler.wsgi", line 1, in <module> 
[Thu Feb 04 21:54:30 2016] [error] [client 10.57.136.99]  from scheduler import app as application 
[Thu Feb 04 21:54:30 2016] [error] [client 10.57.136.99] ImportError: No module named scheduler 

wsgi.conf

/etc/httpd/conf.d

LoadModule wsgi_module modules/mod_wsgi.so 
WSGIPythonHome /opt/tools 
WSGISocketPrefix run/wsgi 

WSGIDaemonProcess scheduler user=abcd group=efgh processes=4 
WSGIScriptAlias /scheduler /opt/tools/apps/scheduler/scheduler.wsgi 
<Directory /opt/tools/apps/scheduler> 
    WSGIProcessGroup scheduler 
    WSGIApplicationGroup %{RESOURCE} 
    Order deny,allow 
    Allow from all 
</Directory> 

我跟着Link1 & Link2但沒有運氣。這個應用程序在一臺主機上正常工作(比如host-1),我試圖將它部署在host-2上。

回答

1

由於您的應用程序將作爲守護程序運行,因此根目錄將設置爲/

確保您的項目目錄已添加到python PATH或讓wsgi以正確的路徑運行應用程序。

scheduler.wsgi應該是這樣的:

# insert application path in python path 
import sys 
sys.path.insert(0, "/opt/tools/apps/scheduler") 

# launch app 
from scheduler import app as application 

還要確保Apache用戶/組(www-data)訪問項目:

chown -R www-data:www-data /opt/tools/apps/scheduler 
+0

更改'scheduler.wsgi'如上和權限類似於'host-1'上的內容。 :(但它沒有工作,你想要更多的信息嗎? –

+2

把一個'import os; print(os.getcwd())'放在你的wsgi腳本的頂部,並顯示apache日誌返回的內容。 – Cyrbil