【发布时间】:2018-11-23 23:02:01
【问题描述】:
我在 /home/toto/Desktop 下创建了一个名为 dash_test 的 django 项目,我想使用 Apache2 和 mod_wsgi 为我的 Django 应用程序提供服务。
我使用此命令sudo apt-get install python-pip apache2 libapache2-mod-wsgi 安装了 Apache Web 服务器、mod_wsgi 和 pip。我在名为developer的项目目录中创建了一个python虚拟环境。
settings.py 中的 allowed_hosts 如下所示:
ALLOWED_HOSTS = ['xxx.xxx.xxx.xxx', 'localhost', '127.0.0.1']`
我添加了 static_url 和 static_root:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
我确实运行了collectstatic
我通过编辑000-default.conf 配置了apache:
<VirtualHost *:80>
Alias /static /home/toto/Desktop/dash_test/static
<Directory /home/toto/Desktop/dash_test/static>
Require all granted
</Directory>
<Directory /home/toto/Desktop/dash_test/dash_test>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess dash_test python-home=/home/toto/Desktop/dash_test/developer python-path=/home/toto/Desktop/dash_test
WSGIProcessGroup dash_test
WSGIScriptAlias / /home/toto/Desktop/dash_test/dash_test/wsgi.py
</VirtualHost>
当我尝试访问 localhost 时出现此错误:
内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。 请通过 [no address given] 联系服务器管理员,告知他们此错误发生的时间,以及您在此错误之前执行的操作。 服务器错误日志中可能提供有关此错误的更多信息。 Apache/2.4.18 (Ubuntu) 服务器在 localhost 端口 80
这里是apache2error.log的内容:
[Thu Jun 14 13:25:48.134132 2018] [wsgi:error] [pid 21611] [remote 127.0.0.1:15106] mod_wsgi (pid=21611): Target WSGI script '/home/toto/Desktop/dash_test/dash_test/wsgi.py' cannot be loaded as Python module.
[Thu Jun 14 13:25:48.134152 2018] [wsgi:error] [pid 21611] [remote 127.0.0.1:15106] mod_wsgi (pid=21611): Exception occurred processing WSGI script '/home/toto/Desktop/dash_test/dash_test/wsgi.py'.
[Thu Jun 14 13:25:48.134167 2018] [wsgi:error] [pid 21611] [remote 127.0.0.1:15106] Traceback (most recent call last):
[Thu Jun 14 13:25:48.134182 2018] [wsgi:error] [pid 21611] [remote 127.0.0.1:15106] File "/home/toto/Desktop/dash_test/dash_test/wsgi.py", line 11, in <module>
[Thu Jun 14 13:25:48.134203 2018] [wsgi:error] [pid 21611] [remote 127.0.0.1:15106] from django.core.wsgi import get_wsgi_application
[Thu Jun 14 13:25:48.134216 2018] [wsgi:error] [pid 21611] [remote 127.0.0.1:15106] ImportError: No module named django.core.wsgi
我正在使用 MySQL 和 phpMyAdmin 而不是 db.sqlite3
非常感谢。
【问题讨论】:
-
尝试运行
sudo chmod -R 777 /home/toto/Desktop/dash_test并重新加载 apache -
谢谢我确实运行了命令,但我仍然有同样的错误
-
您是否在编辑配置后重新加载了 Apache?
-
是的,我做了 /etc/init.d/apache2 restart
标签: django python-2.7 ubuntu apache2 mod-wsgi