You don't have permission to access / on this server.
本帖最后由 污妖王 于 2018-9-26 09:29 编辑我使用的是Ubuntu10.04系统,在/home/wong2/Code/python/django2/创建了名为atest的django工程,并在同一目录下创建了wsgi配置文件,Wsgi配置文件的内容如下
import os
import sys
path = '/home/wong2/Code/python/django2'
if path not in sys.path:
sys.path.append(path)
os.environ["DJANGO_SETTINGS_MODULE"] = "atest.settings"
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
我的httpd.conf配置文件:
<VirtualHost *:80>
ServerName localhost
WSGIScriptAlias / /home/wong2/Code/python/django2/setting.wsgi
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory "/home/wong2/Code/python/django2/atest">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
当我访问http://localhost,显示被禁止了,没有权限访问这个服务器 第二个目录块与安装WSGI脚本文件的位置不匹配。不过,将WSGI脚本文件粘贴到存在源代码或其他敏感文件的位置是非常糟糕的做法。相反,您应该将它放在它自己的子目录中。因此:
WSGIScriptAlias / /home/wong2/Code/python/django2/atest/apache/setting.wsgi
<Directory "/home/wong2/Code/python/django2/atest/apache">
Order allow,deny
Allow from all
</Directory>
在“atest”下创建“apache”子目录,将wsgi'转换到“apache”子目录中,并将配置更改为上面的。您的问题也可能是由于主目录的限制,因为Apache不能看到内部。
去看:http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6 # Conference_Presentations
正如它解释的那样,这些权限问题以及诸如将代码和WSGI脚本文件粘贴到哪里之类的问题。还可以读
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango 对于Django 1.5+,你应该使用文档中描述的建议方法:WSGIScriptAlias / /path/to/ mysite.com/mysite.pywsgi.pywsgipythonpath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/
由于文件权限受到限制,我遇到了同样的问题。默认情况下,主文件夹用户有以下设置:
ls -l /home/
drwx------ 36 user user 12288 Nov 28 20:56 user
这意味着除了你自己,没有人能浏览那个文件夹。添加执行选项到文件夹修复了我的问题
chmod o+x /home/user/
ls -l /home/
drwx-----x 36 user user 12288 Nov 28 20:56 user
您可能会惊奇地发现您的WSGI有它的主目录!在我的wsgi_mod安装中,我不得不编写这个脚本来确保:
import os
def application(environ, start_response):
status = '200 OK'; e=os.listdir(os.getcwd())
output = '''WSGI %s<hr>'''%(e)
response_headers = [('Content-type', 'text/html'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return
这意味着导入的应用程序需要找到完整的路径,例如:
sys.path.append('/home/foo/www/Forms')
这是谷歌推荐的方法
import sys; path='/home/foo/www/Forms';
if path not in sys.path: sys.path.append(path)
from DataCommon import page
试试http://localhost/index。html会显示apache页面吗?如果wsgi在root上配置正确,它就不会。您会得到错误消息,因为您可能正在向webserver询问www文件夹的目录列表
我的项目在
/var/pyproj//pysrc/ and server files i put in /var/py_proj//server/
我的wsgi脚本
import os, sys
import logging
logger =logging.getLogger("")
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)-8s %(messages)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
sys.stdout = sys.stderr
from os.path import abspath, dirname, join
import site
PROJECT_ROOT = abspath(join(dirname(__file__), "../pysrc"))
SETTINGS_LOC = abspath(join(PROJECT_ROOT, ''))
site.addsitedir(SETTINGS_LOC)
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
from django.core.management import setup_environ
import settings
setup_environ(settings)
sys.path.insert(0, join(PROJECT_ROOT, "apps"))
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
我用的是vhost.conf
WSGIDaemonProcess pinax_demo user=www-data group=www-data threads=10 python-path=/var/.virtualenvs/pinax_demo/lib/python2.6/site-packages
<Directory /var/py_proj/pinax_demo/server/>
Order deny,allow
Allow from all
</Directory>
Alias /pinax_demo /var/py_proj/pinax_demo/server/pinax_demo.wsgi
<Location /pinax_demo/>
#WSGIProcessGroup must match the WSGIDaemonProcess
WSGIProcessGroup pinax_demo
SetHandler wsgi-script
Options +ExecCGI
</Location>
which i include in the sites-available folder in a file that looks like this
<VirtualHost *:8080>
DocumentRoot /var/www/
<Directory /var/www/>
Order deny,allow
Allow from all
Options -Indexes FollowSymLinks
DirectoryIndex index.php
AllowOverride None
</Directory>
LogLevel error
ErrorLog/var/srv_logs/apache_error.log
CustomLog/var/srv_logs/apache_access.log combined
#insert
Include /var/py_proj/pinax_demo/server/vhost.conf
Include /var/py_proj/<other>/server/vhost.conf
Include /var/py_proj/<other>/server/vhost.conf
</VirtualHost>
httpd.conf 是空的,Apache在发送静态文件方面也很糟糕,所以我在端口8080上有Apache设置,在端口80上有nginx设置,它转发给Apache。你应该可以在我的网站上更改端口,在没有nginx的情况下运行它,但我不会那样做
页:
[1]