让Apache支持cgi、SSI、shtml的配置方法

softyun3年前云服务器66

1.首先明确,只能够指定某个确定的目录,支持cgi,即运行该目录执行cgi程序;否则不太安全。
寻找:

复制代码 代码如下:

    #
    # "C:/Program Files/Apache Group/Apache/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
    <Directory "E:/Website_Field/cgi">
        AllowOverride all
        Options all
        Order allow,deny
        Allow from all
    </Directory>

 

设置Directory为可以执行cgi的目录

2.
寻找:

复制代码 代码如下:

    #
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the realname directory are treated as applications and
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    #
    ScriptAlias /cgi-bin/ "E:/Website_Field/cgi"

 

将之后的目录改成和上面的相同。

3.
设置cgi脚本的后缀,寻找:

复制代码 代码如下:

   #
    # AddHandler allows you to map certain file extensions to "handlers",
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action command (see below)
    #
    # If you want to use server side includes, or CGI outside
    # ScriptAliased directories, uncomment the following lines.
    #
    # To use CGI scripts:
    #
    AddHandler cgi-script .cgi .pl

 

设置后缀如.cgi, .pl等等,任意可以想到的,但是避免使用已有的如, .asp, .php等

注意:设置支持cgi的目录之后,该目录下的内容及子目录的内容都可以执行。

配置Apache支持SSI,即服务器端解析的server-parsed html(shtml)
关于什么是SSI以及什么是shtml,请参看本站的其他两篇文章。
使用SSI可以实现html的动态嵌入内容,可以为一下SSI的命令,甚至是系统返回结果,以及比较常用的调用Perl程序(尤其是perl的cgi返回结果)

1. 配置Apache:
1)首先找到:

 

复制代码 代码如下:

   #
    # To use server-parsed HTML files
    #
    AddType text/html .shtml
    AddHandler server-parsed .shtml
 

 

去掉后两行之前的#号;
2)同时需要指定那个在哪个目录内支持这种解析,寻找:

复制代码 代码如下:

  #
    # "C:/Program Files/Apache Group/Apache/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
    <Directory "E:/Website_Field/shtml">
        AllowOverride all
        Options all
        Order allow,deny
        Allow from all
    </Directory>


从Directory开始进行修改:
首先指定到自己的目录,这里是"E:/Website_Field/shtml";
然后设置各个选项如上:

 

 

复制代码 代码如下:

AllowOverride all
Options all
Order allow,deny
Allow from all


完后重启Apache应该就可以了。

 

2. 关于Apache支持的SSI指令,可以参考如下介绍:
zzvips/tools/onlinetools/apache-chs/howto/ssi

3. 一个使用SSI的shtml页面实例:
1)、index.shtml

 

复制代码 代码如下:

<html>
<head>
   <title>shtml</title>
</head>
<body>
<!--#config timefmt="%D" -->
  This file last modified <!--#echo var="LAST_MODIFIED" --><br />
  <!--#config timefmt="%A %B %d, %Y" -->
  Today is <!--#echo var="DATE_LOCAL" --><br />
 <!--#include virtual="embed" --><br />
 <!--#exec cmd="test.pl" --><br />
 <!--#exec cmd="dir" --><br />
</body>
</html>

 

2)、embed

 

复制代码 代码如下:

<html>
<head>
    <title>embed html</title>
</head>
<body>
This is the content from embed
</body>
</html>

 

3)、test.pl
 

复制代码 代码如下:


#!C:\perl\bin\perl -w
use strict;

 

sub print_header()
{
    print "This is Header function! ";  
}

sub print_footer()
{
    print "This is Footer function! ";  
}

print_header();
print_footer();


 

总结:
设置Apache支持cgi和支持SSI的时候有个相同的部分,设置目录Directory,而且需要设置为相同的。
因此,如果单使用ssi的话,可以按照ssi的设置进行配置,将shtml等放置到设置的目录下;
如果已设置Apache支持cgi,只需要打开ssi,同时将shtml等文件放置到cgi的目录中即可。

免责声明:本文内容来自用户上传并发布,站点仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。请核实广告和内容真实性,谨慎使用。

相关文章

美国空间的优缺点是什么

美国空间的优缺点是:1、美国空间的优点是稳定性好,独立ip资源充足,且价格便宜,能满足站长的网站需求;2、美国空间的缺点是国内访问速度较慢,售后沟通上有语言沟通不便,解决问题的时间较长。具体内容如下:...

保障硬防服务器的技巧有哪些

保障硬防服务器的技巧有:1、编写服务器硬件防火墙的配置文件,如详细到类似哪些流量被允许等;2、记录服务器硬件防火墙的磁盘使用情况,保留日志记录;3、看服务器硬件防火墙的CPU负载,判断硬件防火墙系统运...

阿里云香港大带宽服务器双向cn2专线快速稳定

如今香港机房水平变高,稳定而且无需备案。即买即用,尽管贵了些,但仍然很受欢迎。毕竟,香港服务器性能好,国内访问速度快,稳定性好,而且整体的租用价格也不贵。但香港服务器整体的带宽都不大,所以现在很难租用...

为什么说台湾服务器更合适手游挂机

台湾服务器更合适手游挂机的原因:1. 台湾服务器能够满足模拟器的使用,台湾服务器不少型号都支持显卡安装。2. 台湾服务器的IP资源比较丰富,而且均为独享IP,不会出现被顶号或者误封的情况,最大限度的保...

购买美国便宜云服务器有哪些用途

购买美国便宜云服务器可以有以下用途:1、网站托管将网站的数据和文件存储在云服务器上,提供访问和服务。2、数据备份和存储将重要的数据备份和存储在云服务器上,保证数据的安全性和可靠性。3、虚拟化和云计算利...

购买vps服务器怎么维护管理

购买vps服务器维护管理的方法:1、定期对管理密码进行修改,降低被黑客暴力破解的风险;2、配置防火墙,提高vps服务器的防御能力;3、做好数据备份操作,避免数据丢失后无法进行恢复;4、不要运行未知来源...