Django on apache wtih mod_wsgi (Linux) - 403 Forbidden

早过忘川 提交于 2019-12-01 19:27:41
Anup

If this is exactly your config file then i doubt the path that you're using is wrong. Please fix that first.

Set WSGIScriptAlias this to correct path.

Then your WSGI file must look something like:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

A things to start with:

WSGIScriptAlias / /home/nick/Mysite/mysite.wsgi

For this, you do not have a corresponding:

<Directory/home/nick/Mysite>
<Files mysite.wsgi>
Require all granted
</Files>
</Directory>

Also, a home directory such as /home/nick is usually not readable to other users and so Apache wouldn't be able to read stuff in that directory anyway.

Next is:

Alias /static /var/www/mysite/static/

You shouldn't have a trailing slash on final path. Not having them matched when for a sub URL can cause issues, although usually when the trailing slash is on the URL and missing for the file system path. Better just to have them match as far as whether a trailing slash is used or not.

I had the same problem.

your .wsgi script should be located in the /var/www/mysite/ folder and then your config files should be adjusted as necessary.

Also delete the leading / in :

.. Alias /static /var/www/mysite/static ..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!