如何在apache Centos 7上设置django项目
How to set django project on apache Centos 7
我已经在 Centos7 上创建了一个 django 项目,现在我正试图让它在 apache 网络服务器上运行。但是在 apache 错误日志中我看到了这个错误:
[Mon Apr 23 07:01:02.930780 2018] [:error] mod_wsgi (pid=26121): Target WSGI script '/he/django/myshop/myshop/wsgi.py' cannot be loaded as Python module.
[Mon Apr 23 07:01:02.930821 2018] [:error] mod_wsgi (pid=26121): Exception occurred processing WSGI script '/he/django/myshop/myshop/wsgi.py'.
[Mon Apr 23 07:01:02.930842 2018] [:error] Traceback (most recent call last):
[Mon Apr 23 07:01:02.930864 2018] [:error] File "/he/django/myshop/myshop/wsgi.py", line 28, in <module>
[Mon Apr 23 07:01:02.930922 2018] [:error] from django.core.wsgi import get_wsgi_application
[Mon Apr 23 07:01:02.930947 2018] [:error] ImportError: No module named django.core.wsgi
我的项目路径是/he/django/myshop/
.
我没有更改我的默认 /he/django/myshop/myshop/
wsgi.py 文件,所以它看起来像这样:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myshop.settings")
application = get_wsgi_application()
我的 /etc/httpd/conf.d/htmltest.psina.com.conf
看起来像这样:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName 185.201.8.84
ServerAlias www.example.com
DocumentRoot /he/sites/htmltest.psina.com/htdocs/
LogLevel warn
ErrorLog /var/log/httpd/htmltest.psina.com-error.log
CustomLog /var/log/httpd/htmltest.psina.com-access.log combined
WSGIScriptAlias / /he/django/myshop/myshop/wsgi.py
</VirtualHost>
WSGIPythonPath /he/django/myshop
<Directory "/he/sites/htmltest.psina.com/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "/he/django/myshop/myshop">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
首先,我为简单的 html 页面创建了 .conf 文件,以检查 apache 是否正常工作并且一切正常(这就是为什么我的配置中有 /he/sites/htmltest.psina.com/htdocs/
)。
我想我在不同 python 版本上遇到了问题,因为我已经为 python3.4 安装了 django,但我不确定这是错误的主要原因。
嗨,上面的错误需要"python35u-mod_wsgi"
你能从这里手动安装吗linkinstall python35u-mod_wsgi
我已经在 Centos7 上创建了一个 django 项目,现在我正试图让它在 apache 网络服务器上运行。但是在 apache 错误日志中我看到了这个错误:
[Mon Apr 23 07:01:02.930780 2018] [:error] mod_wsgi (pid=26121): Target WSGI script '/he/django/myshop/myshop/wsgi.py' cannot be loaded as Python module.
[Mon Apr 23 07:01:02.930821 2018] [:error] mod_wsgi (pid=26121): Exception occurred processing WSGI script '/he/django/myshop/myshop/wsgi.py'.
[Mon Apr 23 07:01:02.930842 2018] [:error] Traceback (most recent call last):
[Mon Apr 23 07:01:02.930864 2018] [:error] File "/he/django/myshop/myshop/wsgi.py", line 28, in <module>
[Mon Apr 23 07:01:02.930922 2018] [:error] from django.core.wsgi import get_wsgi_application
[Mon Apr 23 07:01:02.930947 2018] [:error] ImportError: No module named django.core.wsgi
我的项目路径是/he/django/myshop/
.
我没有更改我的默认 /he/django/myshop/myshop/
wsgi.py 文件,所以它看起来像这样:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myshop.settings")
application = get_wsgi_application()
我的 /etc/httpd/conf.d/htmltest.psina.com.conf
看起来像这样:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName 185.201.8.84
ServerAlias www.example.com
DocumentRoot /he/sites/htmltest.psina.com/htdocs/
LogLevel warn
ErrorLog /var/log/httpd/htmltest.psina.com-error.log
CustomLog /var/log/httpd/htmltest.psina.com-access.log combined
WSGIScriptAlias / /he/django/myshop/myshop/wsgi.py
</VirtualHost>
WSGIPythonPath /he/django/myshop
<Directory "/he/sites/htmltest.psina.com/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "/he/django/myshop/myshop">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
首先,我为简单的 html 页面创建了 .conf 文件,以检查 apache 是否正常工作并且一切正常(这就是为什么我的配置中有 /he/sites/htmltest.psina.com/htdocs/
)。
我想我在不同 python 版本上遇到了问题,因为我已经为 python3.4 安装了 django,但我不确定这是错误的主要原因。
嗨,上面的错误需要"python35u-mod_wsgi"
你能从这里手动安装吗linkinstall python35u-mod_wsgi