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="webapps" unpackWARs="true" autoDeploy="true">
<!-- You can change "unpackWARs" and "autoDeploy" to false after the installation is finished -->
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>
</Host>
</Engine>
</Service>
</Server>
到这里tomcat6的配置以完成下面配置opencms
opencms(2个配置文件)
- 第1个配置文件:
- C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\config\opencms-importexport.xml
- opencms-importexport.xml 原配置
<rendersettings> <rfs-prefix>${CONTEXT_NAME}/export</rfs-prefix> <vfs-prefix>${CONTEXT_NAME}${SERVLET_NAME}</vfs-prefix> <userelativelinks>false</userelativelinks> <exporturl>http://127.0.0.1:8080${CONTEXT_NAME}/handle404</exporturl> <plainoptimization>true</plainoptimization> <testresource uri="/system/shared/page.dtd"/> <resourcestorender> <regex>/sites/.*</regex> <regex>/system/workplace/commons/style/.*</regex> <regex>/system/galleries/.*</regex> <regex>/system/modules/.*/resources/.*</regex> </resourcestorender> </rendersettings>
主要修改以下这段,去掉${SERVLET_NAME}
<vfs-prefix>${CONTEXT_NAME}${SERVLET_NAME}</vfs-prefix>
修改后的配置
<rendersettings> <rfs-prefix>${CONTEXT_NAME}/export</rfs-prefix> <vfs-prefix>${CONTEXT_NAME}</vfs-prefix> <userelativelinks>false</userelativelinks> <exporturl>http://127.0.0.1:8080${CONTEXT_NAME}/handle404</exporturl> <plainoptimization>true</plainoptimization> <testresource uri="/system/shared/page.dtd"/> <resourcestorender> <regex>/sites/.*</regex> <regex>/system/workplace/commons/style/.*</regex> <regex>/system/galleries/.*</regex> <regex>/system/modules/.*/resources/.*</regex> </resourcestorender> </rendersettings>
- 第2个配置文件
- C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\config\opencms-system.xml
- opencms-system.xml 原配置文件
<sites>
<workplace-server>http://localhost:8080</workplace-server>
<default-uri>/sites/default/</default-uri>
<shared-folder>/shared/</shared-folder>
<site server="http://localhost:8080" uri="/sites/default/"/>
</sites>
- 把localhost修改成域名www.snailzhang.com
<sites> <workplace-server>http://www.snailzhang.com</workplace-server> <default-uri>/sites/default/</default-uri> <shared-folder>/shared/</shared-folder> <site server="http://www.snailzhang.com" uri="/sites/default/"/> </sites>
到这里把有的配置文件都修改完成
先 重起tomcat
再 重起 apache
进入网址 http://www.snailzhang.com 就可以看到opencms的主页了。
进 入后台 http://www.snailzhang.com/system/login/index.html
如果是部署到服务器上。到时指要把hosts里的ip地址改成服务器的独立IP就可以了。opencms初级的部署基本就完成了。