日期:2014-05-16  浏览次数:20872 次

OpenCms部署Apache+Tomcat (一)

OpenCms部署Apache+Tomcat (一)

?

测试过的系统环境:

  • Windows 2003
  • Windows Xp

相关文件

  • httpd-2.2.22-win32-x86-no_ssl.msi
  • opencms-8.0.2
  • tomcat-6.x

以上程序环境我安装的路径和端口

  • apache的安装路径:C:\Program Files\Apache Software Foundation\Apache2.2 默认端口:80
  • tomcat的安装路径:C:\Program Files\Apache Software Foundation\Tomcat 6.0 默认端口:8080
  • opencms去掉一个访问时带opencms/的方法:替换tomcat的默认项目webapp/ROOT。具体操作如下:先把tomcat的webapps目录下的ROOT文件夹删掉,把opencms.war文件拷贝到webapps目录下,重命名为ROOT.war。之后重起tomcat进入网址:http://localhost:8080/opencms/setup ?安装opencms。

部署:

部署一共修改了5个配置文件

  • apache2.2(2个配置文件)
  • 第一个配置文件:C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf
  • 搜索并把以下模块的前边#号去掉让apache加载这些模块

?

LoadModule alias_module modules/mod_alias.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so 

?

  • ?把以下字符前边的#号也要去掉让apache加载配置文件否则下边的配置httpd-vhosts.conf文件不会生效。

?

Include conf/extra/httpd-vhosts.conf

?

?

?

  • 第二个配置文件:C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf
  • 把以下配置粘贴到httpd-vhosts.conf文件的最后

?

<VirtualHost *:80>
    <Directory "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/ROOT/">
	Order allow,deny
	Allow from all
    </Directory> 
    ServerName www.snailzhang.com
    ServerAdmin webmaster@alkacon.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/ROOT/"
    ErrorLog logs/error.log
    
    # Log only non-redirect requests in "normal" log file
    SetEnvIf Request_URI "\/opencms\/*" redirect
    CustomLog logs/localhost-access.log common env=!redirect

    ProxyPass         /opencms/                 http://www.snailzhang.com/
    RedirectPermanent /opencms/                 http://www.snailzhang.com/

    ProxyPass         /resources/               http://www.snailzhang.com:8080/resources/
    ProxyPass         /export/                  http://www.snailzhang.com:8080/export/
    
    ProxyPass         /                         http://www.snailzhang.com:8080/opencms/
    ProxyPassReverse  /                         http://www.snailzhang.com:8080/opencms/
</VirtualHost>

?

  • ?ServerName www.snailzhang.com 的www.snailzhang.com?是域名如果没有可以用IP代替。
  • 也可以更改hosts具体方法如下:C:\WINDOWS\system32\drivers\etc\hosts 用记事本打开。在最下边加入

?

192.168.170.154	www.snailzhang.com
  • ?我更改了hosts如果不太了熟悉配置的朋友推荐也改一下。因为以下我基本都会用www.snailzhang.com当然你完全可以用192.168.170.154替换掉。而不用去更改hosts。

到这里apache2.2的配置完成下面配置tomcat6

tomcat6(1个配置文件)

  • C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\server.xml
  • 用以下配置替换掉server.xml里的全部内容(注意是替换全部不是追加),替换前请备份原配置文件

?

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN" debug="0">                    
    <Service name="Tomcat-Standalone">

        <!-- Define a connector for the "public visible" server name -->
        <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
            port="8080" minProcessors="5" maxProcessors="75"
            proxyName="www.snailzhang.com" proxyPort="80"
            useBodyEncodingForURI="true" enableLookups="true" redirectPort="8443"
            acceptCount="100" debug="0" connectionTimeout="20000"
            useURIValidationHack="false" disableUploadTimeout="true" />    

        <Engine name="Standalone" defaultHost="localhost" debug="0">
            <Host name="localhost" debug="0" appBase="webap