错误 403:禁止访问 您没有权限使用 apache、mod-wsgi 和 django 访问此服务器上的 /

Error 403: Forbidden You don't have permission to access / on this server with apache, mod-wsgi and django

我是 django 和 apache 的新手。我想通过 apache 和 mod-wsgi 发布我的 django 网站。 当我启动 httpd.exe 时,我在浏览器中收到 403 forbidden 错误。 我的 Apache 配置在这里

LoadFile "c:/users/zharf/appdata/local/continuum/anaconda3/envs/django/python36.dll"
LoadModule wsgi_module "c:/users/zharf/appdata/local/continuum/anaconda3/envs/django/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIPythonHome "c:/users/zharf/appdata/local/continuum/anaconda3/envs/django"



Alias /static/ /D:/user/JarfaSys/static/
<Directory D:/user/JarfaSys/static/>
    AllowOverride none
    Require all granted
</Directory>


WSGIScriptAlias / /D:/user/JarfaSys/JarfaSys/wsgi.py
WSGIPythonPath /D:/user/JarfaSys/
WSGIPassAuthorization On



<VirtualHost 127.0.0.1:443>
DocumentRoot D:/user/JarfaSys
    Alias /favicon.ico D:/user/JarfaSys/JarfaSys/favicon.ico
    Alias / /D:/user/JarfaSys/JarfaSys/wsgi.py

    ServerName 127.0.0.1
    SSLEngine on
    SSLCertificateKeyFile C:/Users/zharf/TibiFiles/host.key
    SSLCertificateFile  C:/Users/zharf/TibiFiles/host.cert
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

    <Directory D:/user/JarfaSys/JarfaSys/>
    <Files wsgi.py>
      Require all granted
    </Files>
    </Directory>             

</VirtualHost>


WSGIScriptAlias / /D:/user/JarfaSys/JarfaSys/wsgi.py
WSGIPythonPath /D:/user/JarfaSys/
WSGIPassAuthorization On


<Directory D:/user/JarfaSys/JarfaSys/>
<Files wsgi.py>
  Require all granted
</Files>
</Directory>

wsgi.py 是:

import os
import sys

path = "D:/Ghanbari/JarfaSys/JarfaSys"
    if path not in sys.path:
        sys.path.append(path)

os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "JarfaSys.settings")

#print os.getenv("DJANGO_SETTINGS_MODULE")
#print os.getenv("PYTHON_EGG_CACHE")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

错误日志文件在这里


[Fri Aug 23 16:29:26.827875 2019] [core:error] [pid 10784:tid 1092] (20024)The given path is misformatted or contained invalid characters: [client ::1:50025] AH00036: access to / failed (filesystem path 'C:/D:')
[Fri Aug 23 16:29:26.848875 2019] [core:error] [pid 10784:tid 1092] (20024)The given path is misformatted or contained invalid characters: [client ::1:50025] AH00036: access to /favicon.ico failed (filesystem path 'C:/D:'), referer: http://localhost/

Apache 服务用户可以访问我的应用程序目录。 我研究了很多类似的问题,但问题没有解决。如有任何建议,我们将不胜感激。

这里是一个在 apache 中设置项目的例子。您的 vhosts 文件有一些错误

Listen 443

<VirtualHost *:443>
    ServerName localhost

    ErrorLog "logs/logname-error.log"
    CustomLog "logs/logname-access.log" common

    WSGIScriptAlias / "C:\workspace\your_project_path\wsgi.py"
    Alias /static/ C:/workspace/static/

    <Directory C:\your_project_path>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>
</VirtualHost>

删除 /D:/... 之前使用上面的作为模式。

和 wsgi.py

的示例
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

activate_env = r"C:\your_virtual_environment_path\Scripts\activate_this.py"
with open(activate_env) as f:
    exec(f.read(), {"__file__": activate_env})

from your_main import app as application