我在
我使用以下命令安装了Apache Web服务器、mod_wsgi和pip:
我添加了 static_url 和 static_root:
我运行了
当我尝试访问本地主机时,出现以下错误:
服务器内部错误 服务器遇到了内部错误或配置错误,并且无法完成您的请求。 请联系服务器管理员 [未提供地址],告知他们出现此错误的时间以及在此错误之前执行的操作。 有关此错误的更多信息可能会在服务器错误日志中提供。 Apache/2.4.18 (Ubuntu) 服务器位于本地主机端口80。
下面是apache2错误日志的内容:
我正在使用MySQL和phpMyAdmin代替db.sqlite3。非常感谢。
/home/toto/Desktop
下创建了一个名为dash_test
的django项目,并希望使用Apache2和mod_wsgi来服务我的Django应用程序。我使用以下命令安装了Apache Web服务器、mod_wsgi和pip:
sudo apt-get install python-pip apache2 libapache2-mod-wsgi
,并在项目目录中创建了一个名为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>
当我尝试访问本地主机时,出现以下错误:
服务器内部错误 服务器遇到了内部错误或配置错误,并且无法完成您的请求。 请联系服务器管理员 [未提供地址],告知他们出现此错误的时间以及在此错误之前执行的操作。 有关此错误的更多信息可能会在服务器错误日志中提供。 Apache/2.4.18 (Ubuntu) 服务器位于本地主机端口80。
下面是apache2错误日志的内容:
[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。 - Ykh