您的位置:首页 > 运维架构 > Tomcat

Tomcat7 部署CGI程序

2016-02-24 14:01 495 查看
部署环境:

1. ubuntu14.04.3_x64

2. jdk1.7.0_79

3. apache-tomcat-7.0.63

Apache官方参考资料: CGI How To

1) 修改
$CATALINA_HOME/conf/web.xml

<!-- The CGI Gateway servlet -->
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>

<!-- The mapping for the CGI Gateway servlet -->
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>


根据
web.xml
中的描述,关于
executable
部分,默认值如下

<!-- if you leave the param blank it will run any script type. -->
<init-param>
<param-name>executable</param-name>
<param-value></param-value>
</init-param>


2) 修改
$CATALINA_HOME/conf/context.xml

<Context privileged="true">
...
</Context>


在原来的基础上将Context部分添加上
privileged="true"


3) 目录结构

|-tomcat
|--webapps
|---cgi-example
|----WEB-INF
|-----cgi
|------first.py
|------second.pl


4) 启动Tomcat

user@ubuntu:/opt/tomcat7/bin $./startup.sh


5) 访问路径

http://localhost:8080/cgi-example/cgi-bin/first.py


http://localhost:8080/cgi-example/cgi-bin/second.pl


附录

python
first.py

#! /usr/bin/python

print "content-type: text/html"
print ""

print "<html><head><title>Welcome</title></head>"
print "<body><h1>Welcome to the output of a CGI under Tomcat</h1>"
print "<p>The subject says all.</p>"
print "</body></html>"


Perl
second.pl

#! /usr/bin/perl

print "content-type: text/html";

$now = localtime();
print "<h1>It is $now</h1>";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: