设为首页 收藏本站
查看: 509|回复: 0

[经验分享] 配置Apache支持cgi, 配置Apache支持SSI | 以及如何使用shtml

[复制链接]

尚未签到

发表于 2017-1-7 08:22:24 | 显示全部楼层 |阅读模式
配置Apache支持cgi,更详细的介绍参看:

http://blog.csdn.net/omohe/archive/2007/05/18/1615505.aspx

如下为简化版。
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等等,任意可以想到的,但是避免使用已有的如.html, .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指令,可以参考如下介绍:
http://httpd.apache.org/docs/1.3/howto/ssi.html

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

DSC0000.gif <html>
<head>
<title>shtml</title>
</head>
<body>

<!--#configtimefmt="%D"-->
Thisfilelastmodified
<!--#echovar="LAST_MODIFIED"--><br/>

<!--#configtimefmt="%A%B%d,%Y"-->
Todayis
<!--#echovar="DATE_LOCAL"--><br/>

<!--#includevirtual="embed.html"--><br/>

<!--#execcmd="test.pl"--><br/>

<!--#execcmd="dir"--><br/>
</body>
</html>



2)
embed.html

<html>
<head>
<title>embedhtml</title>
</head>
<body>
Thisisthecontentfromembed.html
</body>
</html>



3)
test.pl

#!C:perlinperl-w
usestrict;

subprint_header()
{
print"ThisisHeaderfunction! ";
}

subprint_footer()
{
print"ThisisFooterfunction! ";
}

print_header();
print_footer();






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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-324878-1-1.html 上篇帖子: Apache SeriveMix Kernel 已经成为Apache Felix的子项目了 下篇帖子: Apache James邮件服务器使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表