0
在我的站点2 Django应用程序Apache wsgi没有对/ var/www/site2中文件的写入访问权限,即使: centos 7 Apache wsgi写入文件权限被拒绝
以下是发布会状态:
[[email protected] www]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13
[[email protected] www]# ls -l
total 4
drwxr-xr-x. 2 root root 6 Nov 19 23:43 cgi-bin
drwxr-xr-x. 2 root root 6 Apr 2 15:02 html
drwxrwxrwx. 6 apache apache 4096 Apr 3 16:14 site2
[[email protected] site2]# ls -l
...
drwxrwxrwx. 5 apache apache 4096 Apr 2 15:23 blog
-rwxrwxrwx. 1 apache apache 95232 Apr 3 16:09 db.sqlite3
drwxrwxrwx. 5 apache apache 4096 Apr 2 16:54 home
-rwxrwxrwx. 1 apache apache 248 Mar 19 13:56 manage.py
drwxrwxrwx. 5 apache apache 4096 Apr 3 16:13 pock
drwxrwxrwx. 2 apache apache 4096 Apr 3 14:45 site2
[[email protected] www]# sestatus
SELinux status: disabled
httpd.conf ...
#-------------------------------------------------
WSGIScriptAlias//var/www/site2/site2/wsgi.py
WSGIPythonPath /var/www/site2/
Alias /static/ /var/www/site2/blog/static/
Alias /static2/ /var/www/site2/home/static/
Alias /static3/ /var/www/site2/pock/static/
<Directory /var/www/site2/blog/static/>
Require all granted
</Directory>
<Directory /var/www/site2/home/static/>
Require all granted
</Directory>
<Directory /var/www/site2/pock/static/>
Require all granted
</Directory>
<Directory /var/www/site2/site2/>
<Files wsgi.py>
#Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
#-------------------------------------------------
并且仍然在/ var /日志/的httpd/error_log中:
[Sun Apr 03 13:43:17.389404 2016] [:error] [pid 4753] /var/www/site2
[Sun Apr 03 13:43:17.390560 2016] [:error] [pid 4753] Internal Server Error: /pock/test/
[Sun Apr 03 13:43:17.390593 2016] [:error] [pid 4753] Traceback (most recent call last):
[Sun Apr 03 13:43:17.390602 2016] [:error] [pid 4753] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
[Sun Apr 03 13:43:17.390609 2016] [:error] [pid 4753] response = self.process_exception_by_middleware(e, request)
[Sun Apr 03 13:43:17.390634 2016] [:error] [pid 4753] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
[Sun Apr 03 13:43:17.390643 2016] [:error] [pid 4753] response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Sun Apr 03 13:43:17.390650 2016] [:error] [pid 4753] File "/var/www/site2/pock/views.py", line 57, in test
[Sun Apr 03 13:43:17.390656 2016] [:error] [pid 4753] f = open('test.txt', 'w')
[Sun Apr 03 13:43:17.390662 2016] [:error] [pid 4753] IOError: [Errno 13] Permission denied: 'test.txt'
解决
感谢我做了更多弗拉基米尔的建议挖掘,我发现finnaly的方式。
在/ home目录中移动项目不适用于我:从Apache获取“Forbidden”。
的文件,我想写需要绝对路径:
f = open('/var/www/site2/test.txt', 'w')
否则WSGI蟒蛇会尽量把它写在“/”根文件系统,所以上面的错误解释
在结束我做了CH - R 744/var/www/site2和它的工作,写入文件和数据库。
似乎我已经做了其他错误,但无论如何,它现在起作用。
在此线程中无法看到Volodymyr,因此不确定这些建议是什么。如果你回答自己的问题,最好把这个答案。 – intotecho