好吧,我正在学习这个教程。 当我尝试访问我的网站通过我的本地服务器时,我得到这个奇怪的错误:
Forbidden You don't have permission to access / on this server. Apache/2.4.6 (Ubuntu) Server at mysite.com Port 80
Forbidden You don't have permission to access / on this server. Apache/2.4.6 (Ubuntu) Server at mysite.com Port 80
。
就我而言,我已经做了一切正确的(我实施了两次提出的方法),这可能很容易是一个操作系统错误(我运行Mint 16和错误(Ubuntu)
),但我没有经验,因此我需要一些帮助。
我做了一些研究,但没有一个( 1,2 )和其他问题,似乎没有回答我的情况。
所以这里是mysite.conf
文件:
<VirtualHost *:80> WSGIScriptAlias / /home/nick/Mysite/mysite.wsgi ServerName mysite.com Alias /static /var/www/mysite/static/ <Directory /var/www/mysite/> Options All AllowOverride All Require all granted </Directory> </VirtualHost>
和我的hosts
文件显示如何将IP地址redirect到我的本地主机:
127.0.0.1 localhost 127.0.1.1 nick-HP-Notebook-PC 192.168.1.2 mysite.com 192.168.1.2 mysite2.com # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
那么你认为问题是什么? 这可能只是一个Linux相关的错误? 并请让我知道如果您需要有关该项目或任何其他信息。
万分感谢。
更新:
这是我的.wsgi
文件:
import os import sys sys.path = ['/var/www/mysite'] + sys.path os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
当我重新启动服务器时,我也会得到这个消息。
Restarting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message [ OK ]
也许这有帮助?
如果这正是你的配置文件,那么我怀疑你使用的路径是错误的。 请先解决。
将WSGIScriptAlias设置为更正路径。
那么你的WSGI文件必须如下所示:
import os import sys os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
一开始的事情:
WSGIScriptAlias / /home/nick/Mysite/mysite.wsgi
为此,你没有相应的:
<Directory/home/nick/Mysite> <Files mysite.wsgi> Require all granted </Files> </Directory>
另外,像/ home / nick这样的主目录通常对其他用户不可读,所以Apache无法读取该目录中的东西。
接下来是:
Alias /static /var/www/mysite/static/
最终路径上不应该有斜线。 虽然通常当URL上的尾部斜线和文件系统路径缺失时,没有匹配的子URL可能会导致问题。 更好的是让他们匹配是否使用尾部斜线。
我有同样的问题。
您的.wsgi脚本应位于/ var / www / mysite /文件夹中,然后根据需要调整您的配置文件。
同时删除领先的/ in:
.. Alias /static /var/www/mysite/static ..