django - Django - Apache2 内部服务器错误
问题描述
/home/toto/Desktop
我在命名下创建了一个 django 项目dash_test
,我想用 Apache2 和 mod_wsgi 为我的 Django 应用程序提供服务。
我使用此命令安装了 Apache Web 服务器、mod_wsgi 和 pip sudo apt-get install python-pip apache2 libapache2-mod-wsgi
。我在项目目录中创建了一个名为developer
.
中的 allowed_hostssettings.py
如下所示:
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
我apache
通过编辑配置000-default.conf
:
<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>
当我尝试访问本地主机时,出现此错误:
内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。请通过 [no address given] 联系服务器管理员,告知他们此错误发生的时间,以及您在此错误之前执行的操作。服务器错误日志中可能提供有关此错误的更多信息。Apache/2.4.18 (Ubuntu) 服务器在 localhost 端口 80
这是 apache2 的内容error.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
非常感谢。
解决方案
代替:
<Directory /home/toto/Desktop/dash_test/dash_test>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
利用:
<Directory /home/toto/Desktop/dash_test>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
您使用了错误的目录。
那或者你有:
WSGIScriptAlias / /home/toto/Desktop/dash_test/wsgi.py
错误的,它的意思是:
WSGIScriptAlias / /home/toto/Desktop/dash_test/dash_test/wsgi.py
如果这是一个 Django 应用程序,它的位置wsgi.py
实际上看起来不太正确。
文件的实际路径是什么wsgi.py
。
上面的目录参数应该是它所在的目录。
推荐阅读
- python - 使用正则表达式隔离长标题的相关部分
- asp.net-core - 处理数据之前的表单重定向
- c++ - 在类型化的 std::array 中放置 new 和 std::destroy_at 的安全性?
- google-kubernetes-engine - GKE 主节点在哪里运行
- python - 在我的基于文本的游戏中,Ascii 文本打印乱序?
- excel - 计算多个日期范围内的天数而不计算重叠
- node.js - 添加索引后,MongoDB .toArray() 使用 node.js 驱动程序异常缓慢
- python-3.x - 转义格式函数中的一行
- c# - 读取 serilog 的 appconfig 文件
- java - Resteasy 3.6.3.Final on NoSuchFieldError SERVER_SENT_EVENTS_TYPE