我无法访问我用 python 编写的一个非常简单的 cgi 脚本,并且在找到解决方案时遇到了太多麻烦。我有一种感觉,这将是一个很容易解决的问题,但我自己无法弄清楚。
url: localhost/cgi-bin/test.cgi (我也尝试将其命名为 test.py) 我得到的错误是一个简单的 404,我认为下面的 ScriptAlias 会解决这个问题。此外,如果我尝试访问 localhost/cgi-bin/,我会得到 403:拒绝访问。我尝试将权限(我知道这很愚蠢)重置为 777,但没有更好的结果。
/etc/apache2/httpd.conf(对默认 /etc/apache2/apache2.conf 没有特殊编辑):
ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
<Directory /usr/local/apache2/cgi-bin/>
Options +ExecCGI
AddHandler cgi-script .cgi .py
</Directory>
/usr/local/apache2/cgi-bin:
.
└── test.cgi
测试.cgi:
#!/usr/bin/python
import cgi
#cgi.test()
print 'Content-type: text/html\n\n'
print 'test'
此外,在更改 httpd.conf 文件后,我还重新启动了 apache2。除了我已经看过的内容之外,我想不出任何其他内容: ScriptAlias configuration not working in apache2 但我不明白作者引用的是什么全局的。我非常强烈地认为这是我的一个配置中的错误,但看起来代码非常简单。
如果有人能帮助我解决这个愚蠢的问题,我将不胜感激。
编辑:
错误日志:
--clip--
[Thu Sep 26 23:34:59 2013] [error] [client 127.0.0.1] script not found or unable to stat: /usr/lib/cgi-bin/test.cgi
[Thu Sep 26 23:42:08 2013] [error] [client 127.0.0.1] script not found or unable to stat: /usr/lib/cgi-bin/test.cgi
系统信息:
lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 12.04.2 LTS
Release: 12.04
Codename: precise
uname -a
Linux #### 3.2.0-39-generic #62-Ubuntu SMP Thu Feb 28 00:28:53 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
我想我找到了罪魁祸首:
/etc/apache2/sites-enabled/000-默认值:
1 <VirtualHost *:80>
2 ServerAdmin webmaster@localhost
3
4 DocumentRoot /var/www
5 <Directory />
6 Options FollowSymLinks
7 AllowOverride None
8 </Directory>
9 <Directory /var/www/>
10 Options Indexes FollowSymLinks MultiViews
11 AllowOverride None
12 Order allow,deny
13 allow from all
14 </Directory>
15
16 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
17 <Directory "/usr/lib/cgi-bin">
18 AllowOverride None
19 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
20 Order allow,deny
21 Allow from all
22 </Directory>
特别是第 16 行。我从没想过要查看此目录