如何在 apache Centos 7 上设置 django 项目



我在 Centos7 上创建了一个 django 项目,现在我正在尝试让它在 apache Web 服务器上工作。但是在 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/

我没有更改 wsgi.py 文件的默认/he/django/myshop/myshop/,因此它看起来像这样:

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">

您可以从此链接手动安装 Python 35U-mod_wsgi

最新更新