一个文件服务器 多个域名 想当于多线程访问文件 这样的页面加载的速度大大提升
首先需要我们申请 img1-8.ishenbian.com 这几个域名
在我们这个项目中运用到 应用技术是 resin+apache 一个文件服务器(内有apache服务器) 4个应用服务器
多域名 设置需要在文件服务器上的apache 下的conf/extra/httpd-vhosts.conf 这个文件。
设置如下:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName file.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName file1.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img1.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img2.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img3.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img4.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img5.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img6.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img7.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img8.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/oradata/filelocation"
ServerName img9.ishenbian.com
<Directory /data/oradata/filelocation/>
Options -Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/user/([0-9]{4})([0-9]{3})([0-9]{3})/(.*) /user/$1/$2/$3/$4 [PT,NE]
RewriteRule ^/poi/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/(.*) /poi/$1/$2/$3/$4/$5/$6/$7 [PT,NE]
ErrorDocument 404 /default/title_max.jpg
</IfModule>
</VirtualHost>
代码:
页面fileCache.jsp 内容如下
<%@ page language="java" import="java.util.Random" pageEncoding="UTF-8"%>
<%!
private String getFilepath(){
Random r = new Random(10);
Double f1=new Double(Math.random()*10);
int temp=f1.intValue();
if (temp==0)
temp=1;
if(temp==9)
temp=8;
String filePath = "http://img"+temp+".ishenbian.com/weiyuan_web_new";
//String filePath = "http://file"+temp+".locallove.com/weiyuan_web_new" ;
return filePath;
}
%>
其他页面要访问文件服务器的文件
需要包含fileCache.jsp 页面
例如 index_n 页面的一部分
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@include file="common/fileCache.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>飞信位缘——真实的位置社区,您的生活社区,找身边俊男靓女!</title>
<meta name="keywords" content="位缘 , 位置交友 , WAP交友,身边男女 , 签到 , lbs ,sns ,位置微博 , 身边微博, 身边生活"/>
<meta name="description" content="基于地理位置的交友平台,您的身边生活平台。位置交友 , WAP交友,身边男女 , 签到 , lbs ,sns ,位置微博 , 身边微博。" />
<script type="text/javascript" src="<%=getFilepath()%>/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="<%=getFilepath()%>/js/poi/assert/js/win.js"></script>
<script type="text/javascript" language="javascript" src="<%=getFilepath()%>/js/poi/assert/js/poi/collect.js"></script>
<script type="text/javascript" src="<%=getFilepath()%>/js/log.js"></script>
红色的部分代码是 多域名访问文件服务器过程