[英]I'm having issues with mod_wsgi + Django + Apache
We deployed a Python 3 application in Django 2.1.2 in a Debian Stretch server. 我们在Debian Stretch服务器中在Django 2.1.2中部署了一个Python 3应用程序。 If we run
/usr/bin/python3 manage.py runserver 0:8000
into the application directory, it works correctly. 如果我们将
/usr/bin/python3 manage.py runserver 0:8000
到应用程序目录中,它可以正常工作。
Then, we are trying to serve the application using mod_wsgi for Apache. 然后,我们尝试使用mod_wsgi为Apache提供应用程序。 We aren't using a virtualenv.
我们没有使用virtualenv。 The version of mod_wsgi we are using is 4.6.5 and the version of Apache is 2.4.
我们使用的mod_wsgi版本是4.6.5,Apache的版本是2.4。 But mod_wsgi + Apache is not using Django, so the index.html seems to be like this:
但是mod_wsgi + Apache没有使用Django,所以index.html似乎是这样的:
{% if user.is_authenticated %} Hello {{ user.first_name }}
instead of the page with css styles, images and so on {% if user.is_authenticated %} Hello {{ user.first_name }}
而不是包含css样式,图像等的页面
My /etc/apache2/sites-available/myapp.conf
content is: 我的
/etc/apache2/sites-available/myapp.conf
内容是:
<VirtualHost *:80>
Servername myapp
DocumentRoot /home/project/myapp/myapp/templates/myapp
WSGIScriptAlias /myapp /home/project/myapp/myapp/wsgi.py
WSGIDaemonProcess myapp
WSGIProcessGroup myapp
<Directory /home/project/myapp>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
There are a couple of errors here. 这里有几个错误。
Firstly, you should absolutely not set your DocumentRoot to the templates directory. 首先,您绝对不应将DocumentRoot设置为templates目录。 In fact, you should not set it at all;
事实上,你根本不应该设置它; delete that line.
删除该行。
Secondly, you have set your app to serve on the prefix "myapp". 其次,您已将应用设置为以“myapp”前缀提供服务。 I doubt you wanted to do that;
我怀疑你想这样做; it sounds like you just want your app to serve on the root.
听起来你只是希望你的应用程序在根目录上提供服务。 So remove that from the alias:
所以从别名中删除它:
WSGIScriptAlias / /home/project/myapp/myapp/wsgi.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.