欢迎光临
我们一直在努力

Linux 下安装支持 JSP/PHP 的 WEB server-JSP教程,开发工具

建站超值云服务器,限时71元/月

0. 综述\r

0.1 目标\r

在 linux 平台上安装一个支持 ssl、url 重写、反向代理、页面压缩、cgi、php、jsp 的 免费 web 服务器\r

0.2 许可协议\r

gnu free documentation license http://www.gnu.org/licenses/fdl.html

允许任意转载,但请保持本文档的完整性

如有修改,务请通知作者

0.3 作者

钝刀 webmaster@yufeng.net

1. 下载

1.1 apache http://www.apache.org/dist/httpd/

1.2 php http://www.php.net/downloads.php

1.3 tomcat http://www.apache.org/dist/jakarta/tomcat-4/

1.4 jtc(jakarta tomcat connectors) http://www.apache.org/dist/jakarta/tomcat-4/source/

2. 安装

2.1 apache

$tar vfxz httpd-2.0.46.tar.gz

$cd httpd-2.0.46

$./configure \

$–enable-so \

$–enable-ssl=shared \

$–enable-rewrite=shared \

$–enable-proxy=shared \

$–enable-deflate=shared \

$–with-mpm=worker \

$–prefix=/www/server/apache2

$make

$make install

#–enable-so 要使用 jk2 连接 tomcat,必须让 apache2 支持模块动态加载

#–enable-ssl=shared 支持 ssl

#–enable-rewrite=shared 支持 url 重写

#–enable-proxy=shared 支持代理\r

#–enable-deflate=shared 支持网页压缩\r

#–with-mpm=worker 采用worker的mpm方式运行

#–prefix=/www/server/apache2 安装目录

2.2 php

$tar vfxz php-4.3.2.tar.gz

$cd php-4.3.2

$./configure \

$–with-apxs2=/www/server/apache2/bin/apxs \

$–prefix=/www/server/php

$make

$make install

$cp php.ini-dist /usr/local/lib/php.ini

#–with-apxs2=/www/server/apache2/bin/apxs 作为 apache2 的模块编译\r

#–prefix=/www/server/php 安装目录,并没有太大作用

2.3 tomcat

$tar vfxz jakarta-tomcat-4.1.24.tar.gz

$cp -r jakarta-tomcat-4.1.24 /www/server/

$ln -s /home/data/www/jakarta-tomcat-4.1.24 /home/data/www/tomcat

2.4 jtc

#编译错误请参考下文处理\r

$lynx http://www.pubbitch.org/jboss/mod_jk2.html

$tar vfxz jakarta-tomcat-connectors-4.1.24-src.tar.gz

$cd jakarta-tomcat-connectors-4.1.24-src

#以下两步如果没有编译错误不需要做\r

$cp /usr/java/j2sdk1.4.1_02/include/linux/jni_md.h /usr/java/j2sdk1.4.1_02/include/

$ln -s /www/server/apache2/lib/libapr-0.so /www/server/apache2/lib/libapr.so

#开始编译准备

$cd util

$cp build.properties.sample build.properties

$cd ../jk

$cp build.properties.sample build.properties

$vi build.properties

catalina.home=/www/server/tomcat

tomcat40.home=${catalina.home}

apache2.home=/www/server/apache2

#修改以上内容

$cd ../coyote

$cp build.properties.sample build.properties

$vi build.properties

catalina.home=/www/server/tomcat

#修改以上内容

$cd ../jk

#编译jk2

$ant native

$cp build/jk2/apache2/mod_jk2.so /www/server/apache2/modules

3. 配置

3.1 apache2/conf/httpd.conf

$vi /home/data/www/apache2/conf/httpd.conf

#禁用默认字符集

#adddefaultcharset iso-8859-1

#加载 jk2

loadmodule jk2_module modules/mod_jk2.so

#支持 php

addtype application/x-httpd-php .php

#支持页面压缩\r

setoutputfilter deflate

deflatefilternote ratio

setenvifnocase request_uri \.(?:gif|jpe?g|png)$ no-gzip dont-vary

setenvifnocase request_uri \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary

setenvifnocase request_uri \.pdf$ no-gzip dont-vary

#包含虚拟主机设置

include conf/virtual_host.conf

3.2 apache2/conf/virtual_host.conf

$touch /www/server/apache2/conf/virtual_host.conf

$vi /www/server/apache2/conf/virtual_host.conf

namevirtualhost 123.456.78.9:80

<virtualhost 123.456.78.9:80>

documentroot /www/host/www.domain.com/htdocs

servername www.domain.com

serveralias domain.com

errorlog /www/host/www.domain.com/logs/apache_error.log

customlog /www/host/www.domain.com/logs/apache_access.log common

</virtualhost>

#反向代理的虚拟主机\r

<virtualhost 123.456.78.9:80>

servername www2.domain.com

rewriteengine on

proxyrequests off

usecanonicalname off

rewriterule ^/(.*)$ http://192.168.0.1/$1 [p,l]

</virtualhost>

3.3 apache2/conf/ssl.conf

$vi /www/server/apache2/conf/ssl.conf

namevirtualhost 123.456.78.9:443

<virtualhost 123.456.78.9:443>

documentroot "/www/host/www.domain.com/htdocs"

servername www.domain.com

serveradmin webmaster@domain.com

errorlog /www/host/www.domain.com/logs/ssl_error.log

transferlog /www/host/www.domain.com/logs/ssl_access.log

sslcertificatefile /www/host/www.domain.com/server.crt

sslcertificatekeyfile /www/host/www.domain.com/server.key

sslcertificatechainfile /www/ca.crt

customlog /www/host/www.domain.com/logs/ssl_request.log \

"%t %h %{ssl_protocol}x %{ssl_cipher}x \"%r\" %b"

</virtualhost>

3.4 apache2/conf/workers2.properties

$touch /www/server/apache2/conf/workers2.properties

$vi /www/server/apache2/conf/workers2.properties

[shm]

file=${serverroot}/logs/shm.file

size=1048576

# example socket channel, override port and host.

[channel.socket:example]

port=8009

host=127.0.0.1

# define the worker

[ajp13:example]

channel=channel.socket:example

#[status:status]

# uri mapping

#[uri:/jkstatus/*]

#worker=status:status

# uri mapping

[uri:/*.jsp]

worker=ajp13:example

#[uri:/examples/*]

#worker=ajp13:example

3.5 tomcat/conf/jk2.properties

$touch /www/server/tomcat/conf/jk2.properties

$vi /www/server/tomcat/conf/jk2.properties

# the default port is 8009 but you can use another one

# channelsocket.port=8019

3.6 tomcat/conf/web.xml

$vi /www/server/tomcat/conf/web.xml

<servlet>

<servlet-name>default</servlet-name>

<servlet-class>

org.apache.catalina.servlets.defaultservlet

</servlet-class>

<init-param>

<param-name>debug</param-name>

<param-value>0</param-value>

</init-param>

<init-param>

<param-name>listings</param-name>

#此处重点,禁用目录列表\r

<param-value>false</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

3.7 tomcat/conf/tomcat-users.xml

$vi /www/server/tomcat/conf/tomcat-users.xml

#增加tomcat的管理员

<user name="xxx" password="xxx" roles="manager" />

3.8 tomcat/conf/server.xml

$vi /www/server/tomcat/conf/server.xml

#设置虚拟主机\r

<host name="www.domain.com"

debug="0"

appbase="/www/host/www.domain.com/webapps"

unpackwars="true">

<alias>crcchem.com</alias>

<logger classname="org.apache.catalina.logger.filelogger"

directory="/www/host/www.domain.com/logs"

prefix="catalina."

suffix=".log"

timestamp="true"/>

<context path=""

docbase="/www/host/www.domain.com/htdocs"

debug="0"/>

</host>

4. 测试

4.1 apache2

$touch /www/host/www.domain.com/htdocs/test.html

$vi /www/host/www.domain.com/htdocs/test.html

<h1>hello</h1>

$/www/server/apache2/bin/apachectl configtest

$/www/server/apache2/bin/apachectl startssl

$lynx http://www.domain.com/test.html

4.2 ssl

$lynx https://www.domain.com/test.html

4.3 反向代理\r

$lynx http://www2.domain.com/

4.4 php

$touch /www/host/www.domain.com/htdocs/test.php

$vi /www/host/www.domain.com/htdocs/test.php

<?phpinfo();?>

$lynx http://www.domain.com/test.php

4.5 jsp

touch /www/host/www.domain.com/htdocs/test.jsp

$vi /www/host/www.domain.com/htdocs/test.jsp

<%=new java.util.date();%>

$lynx http://www.domain.com/test.jsp

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Linux 下安装支持 JSP/PHP 的 WEB server-JSP教程,开发工具
分享到: 更多 (0)