我得到一个404错误,而试图打开我的python文件使用apache cgi

lf3rwulv  于 11个月前  发布在  Apache
关注(0)|答案(2)|浏览(108)

我是python后端开发的新手,我试图设置一个apache来使用cgi-bin和一个简单的python文件。
这是我的apache2.conf(我添加了以下内容):

<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options ExecCGI
   Order allow,deny
   Allow from all
   AddHandler cgi-script .py
</Directory>

<Directory "/var/www/cgi-bin">
Options All
</Directory>

字符串
这是我的python文件,名为hello.py,位于**/var/www/cgi-bin**中:

#!/usr/bin/python3

print ("Content-type:text/html\r\n\r\n")
print ('<html>')
print ('<head>')
print ('<title>Hello Word - First CGI Program</title>')
print ('</head>')
print ('<body>')
print ('<h2>Hello Word! This is my first CGI program</h2>')
print ('</body>')
print ('</html>')


我的apache已经启动并运行了,但是当我转到:http://localhost/cgi-bin/hello.py时,我得到以下错误:
无法找到请求的页面“/item/channels”。
36846服务器类型Apache/2.4.54(Ubuntu)
我已经反弹Apache,停止它,并从头开始,没有任何错误时,回来了。

ws51t4hk

ws51t4hk1#

/etc/apache2/apache2.conf**

#########     Adding capaility to run CGI-scripts #################
ServerName localhost
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
Options +ExecCGI
AddHandler cgi-script .cgi .pl .py

字符串

/etc/apache 2/conf-available/serve-cgi-bin.conf更改自:

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Require all granted
</Directory>


ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin/">
    AllowOverride None
    Options +ExecCGI
</Directory>

b1payxdu

b1payxdu2#

您的Apache服务器似乎配置不正确,因此不允许执行CGI脚本。请务必检查您的错误日志,文件权限并检查您的目录路径是否存在。此外,如果您使用虚拟主机,请检查虚拟主机的配置是否允许使用CGI脚本

相关问题