2017-03-20 136 views
0

我一直對使用Ubuntu 16.04部署在Apache服務器上的應用程序感到頭疼。我想可能是它在我的網站配置不當的問題,所以只部署一個測試應用程序test_app和繼Django documentation非常基本的說明和這裏就是我在/etc/apache2/sites-available/000-default.conf插入:在Ubuntu上使用Apache部署Django應用程序16.04

WSGIScriptAlias//var/www/html/python/test_app/test_app/wsgi.py 

#WSGIPythonHome /var/www/html/python/test_app/venv 
#WSGIPythonPath /var/www/html/python/test_app 

Alias /static/ /var/www/html/python/test_app/static/ 

<Directory /var/www/html/python/test_app/static> 
Order allow,deny 
Allow from all 
Require all granted 
</Directory> 


<Directory /var/www/html/python/test_app/test_app> 
<Files wsgi.py> 
Order allow,deny 
Allow from all 
Require all granted 
</Files> 
</Directory> 

而且,我看不到任何關於localhost。我的配置是否正確?

下面是在日誌中產生的錯誤:

[Mon Mar 20 14:19:16.518151 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] mod_wsgi (pid=12272): Target WSGI script '/var/www/html/python/test_app/test_app/wsgi.py' cannot be loaded as Python module. 
[Mon Mar 20 14:19:16.518215 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] mod_wsgi (pid=12272): Exception occurred processing WSGI script '/var/www/html/python/test_app/test_app/wsgi.py'. 
[Mon Mar 20 14:19:16.518241 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] Traceback (most recent call last): 
[Mon Mar 20 14:19:16.518278 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] File "/var/www/html/python/test_app/test_app/wsgi.py", line 17, in <module> 
[Mon Mar 20 14:19:16.518351 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998]  application = get_wsgi_application() 
[Mon Mar 20 14:19:16.518366 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application 
[Mon Mar 20 14:19:16.518406 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998]  django.setup(set_prefix=False) 
[Mon Mar 20 14:19:16.518421 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 22, in setup 
[Mon Mar 20 14:19:16.518462 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998]  configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) 
[Mon Mar 20 14:19:16.518476 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__ 
[Mon Mar 20 14:19:16.518571 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998]  self._setup(name) 
[Mon Mar 20 14:19:16.518586 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup 
[Mon Mar 20 14:19:16.518605 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998]  self._wrapped = Settings(settings_module) 
[Mon Mar 20 14:19:16.518618 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 97, in __init__ 
[Mon Mar 20 14:19:16.518634 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998]  mod = importlib.import_module(self.SETTINGS_MODULE) 
[Mon Mar 20 14:19:16.518648 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module 
[Mon Mar 20 14:19:16.518694 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998]  __import__(name) 
[Mon Mar 20 14:19:16.518719 2017] [wsgi:error] [pid 12272:tid 140248747980544] [client 127.0.0.1:50998] ImportError: No module named test_app.settings 
+0

您是否嘗試過使用WSGI hello world應用程序,而不是Django? http://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html –

+0

@GrahamDumpleton看起來像我必須先嚐試一下。 –

+0

@FaizanAli上面'要求所有授予',添加這一行 - '命令拒絕,允許'。看看它是否有效。 – xyres

回答

0

所以,最後..我想通了!謝謝你們的幫助。

正如我在錯誤日誌中第一行說:

'/var/www/html/python/test_app/test_app/wsgi.py' cannot be loaded as Python module.

這意味着wsgi.py是不是到Apache模塊訪問。我在這裏搜索並獲得了solution

所以,在我wsgi.py,我加了這一點:

import os, sys 
from django.core.wsgi import get_wsgi_application 
sys.path.append('/var/www/html/python/test_app') 

和它的工作。

+1

建議您閱讀http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html使用守護進程模式,並使用「python-home」設置Python虛擬環境以及您的位置項目使用''python-path''。 –

相關問題