【发布时间】:2013-05-31 02:04:33
【问题描述】:
我确实安装了 libapache2-mod-perl2 以通过 apache 将 perl 文件作为 CGI 运行
每次我尝试浏览 perl 文件浏览器时,都会将其显示为纯文本。
###Start###
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there";
###End###
这是虚拟主机文件
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/test
ServerName perl.dev
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/test>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /var/www/test/cgi-bin
<Directory "/var/www/test/cgi-bin">
AddHandler cgi-script .cgi .pl
Options FollowSymLinks +ExecCGI
AllowOverride none
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
当我尝试使用终端运行脚本时,它工作正常,但通过浏览器它永远不会显示正确的输出
谢谢
【问题讨论】:
-
您实际上是通过您的网络服务器(通过 HTTP)访问它,还是尝试从文件系统访问它(使用 file:// URL)?
-
我试图通过 HTTP 而不是从文件系统访问
-
您的测试脚本位于哪个目录中?你是怎么命名的?
-
/var/www/test/cgi-bin
-
###Start###和###End###是您文件的一部分吗?#!/usr/bin/perl行必须在第一行。