在 Apache 上执行 CGI 脚本的问题 [英] Problem with Executing CGI Scripts on Apache

查看:27
本文介绍了在 Apache 上执行 CGI 脚本的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里几乎是一个完整的 Linux/Apache 新手,我正在将站点从共享主机迁移到 Linode VPS.一切都很顺利,直到我开始尝试移动使用一系列 CGI 脚本运行的 Moveable Type 博客.我正在运行 Ubuntu 10.04 和 Apache2.经过几个小时的混乱,我得到了一个 PERL hello world 脚本 (hello.cgi),可以从根 HTML 目录中的 Web 浏览器执行.这是脚本:

Pretty much a complete Linux/Apache newbie here, I am in the process of moving a site from a shared host to a Linode VPS. It's all been going smoothly until I starting trying to move my Moveable Type blog which runs using a series of CGI scripts. I am running Ubuntu 10.04 and Apache2. After hours of messing about I got a PERL hello world script (hello.cgi) to execute from a the web browser in the root HTML directory. Here's the script:

#!/usr/bin/perl -w
use strict;
print "Content-Type: text/html\n\nHello world!";

我通过将以下内容添加到/etc/apache2/sites-available/mysitename.com 文件来实现此目的.

I got this working by adding the following to the /etc/apache2/sites-available/mysitename.com file.

<Directory /srv/www/mysitename.com/public_html/>
    Options +ExecCGI
    AddHandler cgi-script .cgi
</Directory>

但我想在/srv/www/mysitename.com/public_html/mt/目录中执行 CGI 脚本,所以我将上面条目中的目录更改为该路径,当我查看该文件夹中的 hello world 脚本时通过浏览器,我看到了 hello.cgi 脚本的源代码而不是输出.显然有些不对劲.我已经花了足够多的时间来尝试自己解决这个问题,现在是寻求帮助的时候了.那么,有人有什么建议吗?请保持答案简单我真的只是在学习在这里明智地踩水 Linux/Apache2!

But I want to execute CGI scripts in the /srv/www/mysitename.com/public_html/mt/ directory, so I changed the directory in the entry above to that path and when I view the hello world script in that folder via a browser I see the source for the hello.cgi script rather than the output. Clearly something isn't right. I've spent more than enough time trying to work this out myself and the time has come to ask for help. So, anyone got any suggestions? Please keep answers simple I really am just learning to tread water Linux/Apache2 wise here!

找到解决方案:

<VirtualHost *:80>
  ServerName www.sitename.com
  ServerAdmin general@sitename.com
  ServerAlias sitename.com
  DocumentRoot /srv/www/mysitename.com/public_html/
  ErrorLog /srv/www/mysitename.com/logs/error.log
  CustomLog /srv/www/mysitename.com/logs/access.log combined
  AddHandler cgi-script .cgi .pl
</VirtualHost>

<Directory /srv/www/mysitename.com/public_html/>
    AllowOverride All
    Order allow,deny
    Allow from all
    Options All +SymLinksIfOwnerMatch +FollowSymLinks +ExecCGI -Indexes -MultiViews
</Directory>

<Directory /srv/www/mysitename.com/public_html/mt/>
    AllowOverride All
    Order allow,deny
    Allow from all
    Options All +SymLinksIfOwnerMatch +FollowSymLinks +ExecCGI -Indexes -MultiViews
</Directory>

推荐答案

你添加 mod-perl 了吗?

Have you added mod-perl?

添加这些行

AddType perl-script .pl
AddHandler perl-script .htm

指定目录索引

(目录块外)

你也在使用虚拟主机吗?老实说,我通常不会像你那样做事.

Are you using vhosts too? I wouldn't normally do things the way you're doing them to be honest.

这篇关于在 Apache 上执行 CGI 脚本的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆