2017-03-20 62 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''。 –

相关问题