访问被拒绝,在Apache2上运行.py尝试从Apache2上的/opt打开文件

2024-04-25 11:58:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我在许可方面有问题。我正在Apache2/var/www/html/project上运行带有CGI的.py程序,在.py程序上我试图在/opt/image.png中打开文件,我得到:

PermissionError: [Errno 13] Permission denied: '/opt/image.png

Apache2配置:

<VirtualHost *:80>
        ServerName localhost

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        <Directory /var/www/html/project>
            Order Allow,Deny
            Allow from all
            Options +ExecCGI
            AddHandler cgi-script .py
        </Directory>

<Directory "/opt">
                Order allow,deny
                Allow from all
        </Directory>


</VirtualHost>

代码中,我从外部获取了POST的路径:

#!/usr/bin/python3

# -*- coding: UTF-8 -*-# enable debugging

print("Content-Type: text/html;charset=utf-8")
print()

import cgitb, cgi
cgitb.enable()

import PIL

form = cgi.FieldStorage()

file = form.getvalue('file')

imopen = Image.open(file)

我已经尝试将修饰符改为777,所有者改为root,我仍然无法访问,权限被拒绝。我想问题是我无法从/var访问/opt?有线索吗?多谢各位


Tags: pyimage程序projectpngvarhtmlwww