【分享&讨论】Apache2 + Tomcat5 配置多站点服务器

lizhenyang 2010-01-25 05:19:00
假如,现在有3个站点:www.ab26.com,w1.ab26.com,w2.ab26.com,均指向同一服务器(假如公网IP:11.22.333.444)。
下载mod_jk模块,并将其拷贝至Apache安装目录的modules目录下。

Apache配置:

1.修改配置文件httpd.conf,在文件尾加入下面两行:
Include conf/extra/mod_jk.conf
Include conf/extra/thosts.conf

2.在conf目录下新建文件夹extra,所有新建的配置文件都放在这里,以便管理。

3.在extra目录下新建文本文件thosts.conf,内容如下:
# www.ab26.com
<VirtualHost 11.22.333.444:80>
ServerAdmin lo@lo.com
ServerName ab26.com
ServerAlias ab26.com www.ab26.com
DocumentRoot "D:/websites/www.ab26.com/ROOT"
Alias /mydl/ "D:/dl/"
<Directory "D:/websites/www.ab26.com/ROOT">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Location ~"/WEB-INF/">
AllowOverride None
deny from all
</Location>
<Directory "D:/dl">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
CustomLog "logs/www.ab26.com-access_2009.log" combined
ErrorLog "logs/www.ab26.com-error_2009.log"
JkLogFile "logs/www.ab26.com-jk-error_2009.log"
JkLogLevel error
DirectoryIndex default.htm index.htm default.jsp index.jsp
JkMountFile conf/extra/www.ab26.com.properties
</VirtualHost>
# w1.ab26.com
<VirtualHost 11.22.333.444:80>
ServerAdmin lo@lo.com
ServerName w1.ab26.com
ServerAlias w1.ab26.com
DocumentRoot "D:/websites/w1.ab26.com/ROOT"
<Directory "D:/websites/w1.ab26.com/ROOT">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Location ~"/WEB-INF/">
AllowOverride None
deny from all
</Location>
CustomLog "logs/w1.ab26.com-access_2009.log" combined
ErrorLog "logs/w1.ab26.com-error_2009.log"
JkLogFile "logs/w1.ab26.com-jk-error_2009.log"
JkLogLevel error
DirectoryIndex default.htm index.htm default.jsp index.jsp
JkMountFile conf/extra/w1.ab26.com.properties
</VirtualHost>
# w2.ab26.com
<VirtualHost 11.22.333.444:80>
ServerAdmin lo@lo.com
ServerName w2.ab26.com
ServerAlias w2.ab26.com
DocumentRoot "D:/websites/w2.ab26.com/ROOT"
<Directory "D:/websites/w2.ab26.com/ROOT">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Location ~"/WEB-INF/">
AllowOverride None
deny from all
</Location>
CustomLog "logs/w2.ab26.com-access_2009.log" combined
ErrorLog "logs/w2.ab26.com-error_2009.log"
JkLogFile "logs/w2.ab26.com-jk-error_2009.log"
JkLogLevel error
DirectoryIndex default.htm index.htm default.jsp index.jsp
JkMountFile conf/extra/w2.ab26.com.properties
</VirtualHost>


4.在extra目录下新建文本文件mod_jk.conf,内容如下:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/extra/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error

5.在extra目录下新建文本文件workers.properties,内容如下:
workers.tomcat_home=C:\myServer\Tomcat-5.5
workers.java_home=C:\myServer\Java\jre6
worker.list=ajp13_a0,ajp13_a1,ajp13_a2
worker.ajp13_a0.port=8009
worker.ajp13_a0.host=127.0.0.1
worker.ajp13_a0.type=ajp13
worker.ajp13_a1.port=8109
worker.ajp13_a1.host=127.0.0.1
worker.ajp13_a1.type=ajp13
worker.ajp13_a2.port=8209
worker.ajp13_a2.host=127.0.0.1
worker.ajp13_a2.type=ajp13

6.在extra目录下新建文本文件www.ab26.com.properties,内容如下:
/*.jsp=ajp13_a0
/*.do=ajp13_a0
/fckeditor/*=ajp13_a0
!/*.gif=ajp13_a0
!/*.jpg=ajp13_a0
!/*.png=ajp13_a0
!/*.css=ajp13_a0
!/*.js=ajp13_a0
!/*.htm=ajp13_a0
!/*.html=ajp13_a0

7.在extra目录下新建文本文件w1.ab26.com.properties,内容如下:
/*.jsp=ajp13_a1
/*.do=ajp13_a1
/fckeditor/*=ajp13_a1
!/*.gif=ajp13_a1
!/*.jpg=ajp13_a1
!/*.png=ajp13_a1
!/*.css=ajp13_a1
!/*.js=ajp13_a1
!/*.htm=ajp13_a1
!/*.html=ajp13_a1

8.在extra目录下新建文本文件w2.ab26.com.properties,内容如下:
/*.jsp=ajp13_a2
/*.do=ajp13_a2
/fckeditor/*=ajp13_a2
!/*.gif=ajp13_a2
!/*.jpg=ajp13_a2
!/*.png=ajp13_a2
!/*.css=ajp13_a2
!/*.js=ajp13_a2
!/*.htm=ajp13_a2
!/*.html=ajp13_a2

Tomcat配置:

1.修改配置文件server.xml,找到『<Connector port="8009" connectionTimeout="10000" .... protocol="AJP/1.3" />』,在其后添加以下内容:
<Connector port="8109" connectionTimeout="10000" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<Connector port="8209" connectionTimeout="10000" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

说明:这一步的配置,我不知道是不是正确。

服务器上的网站现在可以正常浏览,但是也遇到点问题,我通过网站后台(使用了struts2框架)上传图片时,经常会出现图片上传失败的情况(也有上传成功的时候),我在本地测试时一切正常(本地使用Eclipse3+JDK6+Tomcat5开发环境)。不知道是网站程序有问题,还是网站服务器配置的问题。下面附上我上传图片的代码及Struts2的配置。

请高手帮忙指点一下,问题如能解决,不胜感激!
...全文
251 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhenyang 2010-01-26
  • 打赏
  • 举报
回复
更正:Apache配置,第5步中,workers.properties文件中最后一行:worker.ajp13_ss.type=status,这一行没有。
lizhenyang 2010-01-25
  • 打赏
  • 举报
回复
web.xml中struts2的配置:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-www.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>


struts-www.xml文件相关内容:
<constant name="struts.locale" value="zh_CN" />
<constant name="struts.i18n.reload" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.action.extension" value="do" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.multipart.maxSize" value="5000000" />
<package name="udFile" extends="struts-default">
<action name="doUpfile" class="com.httpUtils.Upfile" method="upload">
<interceptor-ref name="defaultStack">
<param name ="allowedTypes">image/bmp,image/png,image/gif,image/jpeg</param>
<param name="maximumSize">5000000</param>
</interceptor-ref>
<result name="input">selectFile.jsp</result>
<result name="success">previewFile.jsp</result>
</action>
</package>


Upfile.java内容如下:
package com.httpUtils;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Upfile {
private static final long serialVersionUID = 1L;
private File myFile;
private String fileName;
private String contentType;
private String filePath;

public String upload(){
filePath = "upfiles/";
String yName = StringUtil.getDateTime(1);
String mdName = StringUtil.getDateTime(6);
String feName = StringUtil.getDateTime(9) + getFileExt();//获取当前时间,用来重命名上传的文件
RrscAction.createFolder(filePath);//创建不存的文件夹
filePath += yName +"/";
RrscAction.createFolder(filePath);
filePath += mdName +"/";
RrscAction.createFolder(filePath);
filePath += feName;
String realPath = RrscAction.getRealPath(filePath);
save2file(myFile,realPath);
return "success";
}
private String getFileExt(){
int pos = getFileName().lastIndexOf(".");//出错时,会提示getFileName()为null
if(-1<pos)
return getFileName().substring(pos);
else
return ".noExt";
}
private void save2file(File src,String nfp){
final int BUFFER_SIZE = 1024;
try{
File nf = new File(nfp);
InputStream in = null;
OutputStream out = null;
try{
in = new BufferedInputStream(new FileInputStream(src),BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(nf),BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while(0<in.read(buffer))
out.write(buffer);
} finally {
if(null!=in)
in.close();
if(null!=out)
out.close();
}
} catch (Exception e){
e.printStackTrace();
}
}
public void setMyFile(File myFile){
this.myFile = myFile;
}
public void setMyFileFileName(String fileName) {
this.fileName = fileName;
}
public void setMyFileContentType(String fileType) {
this.contentType = fileType;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public File getMyFile(){
return myFile;
}
public String getFileName() {
return fileName;
}
public String getMyFileContentType() {
return contentType;
}
public String getFilePath() {
return filePath;
}
}


selectFile.jsp主要内容:
<s:form action="doUpfile" method="post" name="upFileForm" onsubmit="return check(this);" enctype="multipart/form-data">
<input name="myFile" type="file">
<input type="submit" name="Submit" value="上传" >
</s:form>

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧