我正在学习在 python 上使用 cgi 包,为此我创建了以下脚本:
#!/usr/bin/env python
import cgi
print("<html><head><title>HeyHey</title></head>")
print("<body>")
print("<p>This is an example web server.</p>")
print("</body></html>")
脚本在 server.py
中保存为 /var/www/cgi-bin
。
ls -l
的输出如下:
-rwxr-xr-x 1 vagrant vagrant 170 Apr 21 08:18 server.py
然后我使用以下命令启动我的服务器:
sudo python3 -m http.server --cgi
当我通过转到 0.0.0.0:8000/server.py
打开页面时,代码并未被执行,而是仅显示出来。
任何想法我做错了什么?
P.S:我在 Debian 上工作。
答案 0 :(得分:0)
您确定您已正确配置 httpd.conf
文件以便执行 CGI 使其看起来像这样吗?
<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
<Directory "/var/www/cgi-bin">
Options All
</Directory>
您也可以按照此处提到的步骤操作 -> https://www.knowledgehut.com/tutorials/python-tutorial/python-cgi