Apache说错误打开文件进行读取:权限被拒绝

时间:2014-01-14 13:05:01

标签: python django apache

我正在尝试使用apache(2.2.22)和mod_wsgi(3.4)运行django(1.6)项目。我的python是2.7.3,默认是ubuntu 12.04。我已将所有内容从/ var / www设置为chmod 777向下。不幸的是它给了我

打开文件进行读取时出错:权限被拒绝 然后 脚本标题过早结束:wsgi.py

任何人都可以告诉我我做错了什么吗? 我在这里发布我的error.log

root@whq-4:/var/www/Imse_dev2/Imse/Imse# tail -f /var/log/apache2/error.log 
[Tue Jan 14 14:16:04 2014] [notice] caught SIGTERM, shutting down
[Tue Jan 14 14:16:08 2014] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.4 Python/2.7.3      configured -- resuming normal operations
[Tue Jan 14 14:16:28 2014] [error] /var/www/Imse_dev2/Imse
Error opening file for reading: Permission denied
[Tue Jan 14 14:21:32 2014] [error] [client 127.0.0.1] Premature end of script headers:   wsgi.py
[Tue Jan 14 14:29:13 2014] [notice] caught SIGTERM, shutting down
[Tue Jan 14 14:29:13 2014] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.4 Python/2.7.3  configured -- resuming normal operations
[Tue Jan 14 14:29:17 2014] [error] /var/www/Imse_dev2/Imse
Error opening file for reading: Permission denied
[Tue Jan 14 14:34:21 2014] [error] [client 127.0.0.1] Premature end of script headers:  wsgi.py

还有我的httpd.conf文件

#LimitRequestLine 200475
#LimitRequestFieldSize 200475

WSGIDaemonProcess imse_dev2_wsgi python-path=/var/www/Imse_dev2/Imse/Imse


#LoadModule deflate_module modules/mod_deflate.so
#LoadModule headers_module modules/mod_headers.so

<VirtualHost *:80>
    ServerName whq-4
    DocumentRoot /var/www/
    #Header set Access-Control-Allow-Origin "*"
    Alias /static /var/www/Imse_dev2/Imse/static
    Alias /favicon.ico /var/www/favicon.ico
#       Header set Access-Control-Allow-Origin "*"


    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>


    WSGIScriptAlias /imse_dev2 /var/www/Imse_dev2/Imse/Imse/wsgi.py
    <Directory /var/www/Imse_dev2/Imse/Imse>
            WSGIProcessGroup imse_dev2_wsgi
            <Files wsgi.py>
                    Order deny,allow
                    Allow from all
            </Files>
    </Directory>

    <IfModule mod_headers.c>
             Header set Access-Control-Allow-Origin "*"
    </IfModule>

</VirtualHost>

2 个答案:

答案 0 :(得分:0)

问题是,Django不允许您访问应用程序所在目录之外的文件。因此,例如,如果您的应用程序在/var/www/project运行且您要访问的文件位于/var/www/foo,则Django将引发您获得的异常。

解决方案是在项目目录中移动您尝试访问的目录。

答案 1 :(得分:0)

查看你的httpd.conf和相应的错误信息,看起来像目录

/var/www/Imse_dev2/Imse/Imse

要么可由apache用户读取(“拥有'apache进程),或者该目录不能由apache用户执行。使该目录对所有用户可见,可以这样做:

chmod 755 /var/www/Imse_dev2/Imse/Imse

但是我怀疑你的apache文档根目录下还有其他目录也是不可读的。我可能会让你的文档根目录下的apache用户拥有所有文件和目录,除非你有特殊的理由不这样做:

chown -R apache /var/www/Imse_dev2