【问题标题】:Error 403: Forbidden You don't have permission to access / on this server with apache, mod-wsgi and django错误 403:禁止您无权使用 apache、mod-wsgi 和 django 访问此服务器上的 /
【发布时间】:2019-08-23 12:16:19
【问题描述】:

我是 django 和 apache 的新手。我想通过 apache 和 mod-wsgi 发布我的 django 网站。 当我启动 httpd.exe 时,我在浏览器中收到 403 禁止错误。 我的 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 服务用户可以访问我的应用程序目录。 我研究了许多类似的问题,但问题没有解决。任何建议将不胜感激。

【问题讨论】:

    标签: django apache mod-wsgi wampserver http-status-code-403


    【解决方案1】:

    这是一个在 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
    

    【讨论】:

    • 非常感谢,我更换了你的配置代码,问题解决了
    猜你喜欢
    • 2018-07-12
    • 2013-05-15
    • 2019-10-17
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 2019-02-16
    • 2013-10-23
    • 2011-04-16
    相关资源
    最近更新 更多