apache的跳转跟转发(转载)
startWebLogic.sh
-Dweblogic.management.username=weblogic -Dweblogic.management.password=weblogic
apache中设置代理:
NameVirtualHost 10。88。3。7:80
<VirtualHost 10。88。3。7:80 >
ServerAdmin abc@123.com
ServerName 10.88.3.7
ErrorLog logs/rsa-error.log
CustomLog logs/rsa-access.log common
ProxyPass / http://10.88.3.5:7001
ProxyPassReverse / http://10.88.3.5:7001
</VirtualHost>
本来我可以访问http://10.88.3.5:7001/zhcxxt
我现在访问http://10.88.3.7/zhcxxt就可以了
apache中设置跳转:
修改httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteRule ^/(.*) http://www.****.net/ [R,L]
#无论http://localhost/XXX中XXX有多长都转到****.net
RewriteRule ^/$ http://www.****.net/ [R,L]
#只有当输入http://localhost时跳转,输入http://localhsot/index.html时不跳转.
RewriteRule ^/(.*) http://www.****.net/$1 [R,L]
#当输入http://localhost/mm/index.htm 时转到http://www.****.net/mm/index.htm
========================
apache_plugin:
apache和weblogic放在不同的机器上,动态生成的页面发到weblogic上去。
配置方法:
在每一台机器的apache配置文件中httpd.conf加入:
ServerName 10.88.3.7:80(apache服务器的IP和端口)
LoadModule weblogic_module modules/mod_wl_20.so
<IfModule mod_weblogic.c>
WeblogicHost <填写weblogic主机名或IP地址>
WeblogicPort <weblogic服务端口>
</IfModule>
<Location />
SetHandler weblogic-handler
</Location>
例:
LoadModule weblogic_module modules/mod_wl_20.so
<IfModule mod_weblogic.c>
WeblogicHost zhcxa.tj
WeblogicPort 7001
</IfModule>
<Location />
SetHandler weblogic-handler
</Location>
4.7版本n(n>1)级域名自动生成并绑定的说明
4.7版本的子店n(n>2)级域名自动生成并绑定
的功能要达到以下效果
[attach]5170[/attach]
将以上对子店的访问形式,改写为
[attach]5171[/attach]
4.7多店中子店的n级域名绑定 的原理是使用apache强大的url rewrite功能实现的,有关url rewrite的详细说明请看apache的手册。
apache的url rewrite是基于正则表达式的,所以看这篇文章前最好对正则表达式有个印象
一、启用该功能的要求
1.必须是apache 服务器
2.apache必须已经打开mod_rewrite
[attach]5165[/attach]
如果windows下在httpd.conf中将附图上这行的注释符去掉就行了
[attach]5167[/attach]
如果您是*nix下编译安装,可以参考这个编译参数,这样会把重写模块编译进apache核心中,加快处理速度
./configure \
–prefix=/usr/local/apache \
–with-mpm=prefork \
–enable-so \
–enable-rewrite=static
\
–enable-track-vars
3.网站的域名必须做泛解析,就是让* .site.com 都能指向的您服务器
本地测试可以修改hosts文件,模拟泛解析
[attach]5168[/attach]
二、配置过程:
1.配置apache的重写表,重写表保存有n级域名和子店实际物理地址的映射关系。
在include/mall_config.php中
$RewriteMap_Url=”rmap/vhost.map”;
设置apache重写表的保存地址,它的位置是相对与syssite目录。
重写表的格式如下
n级域名 子店的实际物理地址
样例:
shop1.www.xuni.com D:/Server/wwwroot/shopexm47/syssite/home/shop/00/00/01
它的内容将会由ShopEx的注册程序在子店开通时生成。
由于这个文件保存有网站的物理地址,务必请将它设置为
一个
不容易猜测
的目录。
[attach]5166[/attach]
2.在apache的配置文件httpd.conf中启用rewrite map功能
打开apache的配置文件httpd.conf在末尾添加以下配置信息
*nix系统的内容如下
RewriteLog logs/rewrite.log
RewriteLogLevel 0
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/var/www/html/syssite/vhost.map
RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]
windows系统的内容如下
RewriteLog logs/rewrite.log
RewriteLogLevel 0
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:D:/Server/wwwroot/shopexm47/syssite/rmap/vhost.map
RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$
RewriteCond ${vhost:%1} ^(D:/.*)$
RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]
[attach]5169[/attach]
附图中的
RewriteLogLevel 5
是用于调试用的,这样可以在logs/rewrite.log中看到形如:
127.0.0.1 – - [10/May/2007:11:33:42 +0800] [shop1.www.xuni.com/sid#2cc240
][rid#5934a80/initial] (4) RewriteCond: input=’shop1.www.xuni.com
‘ pattern=’^(.+)$’ => matched
127.0.0.1 – - [10/May/2007:11:33:42 +0800] [shop1.www.xuni.com/sid#2cc240
][rid#5934a80/initial] (5) map lookup OK: map=vhost[txt] key=shop1.www.xuni.com
-> val=D:/Server/wwwroot/shopexm47/syssitehome/shop/00/00/01
127.0.0.1 – - [10/May/2007:11:33:42 +0800] [shop1.www.xuni.com/sid#2cc240
][rid#5934a80/initial] (4) RewriteCond: input=’D:/Server/wwwroot/shopexm47/syssitehome/shop/00/00/01′ pattern=’^(D:/.*)$’ => matched
127.0.0.1 – - [10/May/2007:11:33:42 +0800] [shop1.www.xuni.com/sid#2cc240
][rid#5934a80/initial] (2) rewrite ‘/index.php’ -> ‘D:/Server/wwwroot/shopexm47/syssitehome/shop/00/00/01/index.php’
以上的log片段就是一个 rewrite的过程。
设为5是用于调试的,实际使用环境下务必将 RewriteLogLevel 设置为0,否则rewrite的log很快将您的磁盘撑爆!
要点:
1.正则^(.+)$ 要和vhost.map的第一部分匹配,在这个例子中^(.+)$是可以匹配shop1.www.xuni.com 的
2.正则^(D:/.*)$要和vhost.map的第二部分匹配,在这个例子中^(D:/.*)$是可以匹配D:/Server/wwwroot/shopexm47/syssite/home/shop/00/00/01的
3.vhost.map的地址要用*nix like的格式,就是要用/表示目录,而不是windows的\
所以win的主机要用
RewriteCond ${vhost:%1} ^(D:
/.*)$
把盘符D:加入到正则中,如果您的web文件不是放在D盘而是E盘,要把D:改为E:。
而*nix没有盘符,所以用
RewriteCond ${vhost:%1} ^(/
.*)$
4.这段配置信息的位置,一般放在httpd.conf的末尾。但是如果您的总站是用VirtualHost进行绑定 ,请将以上的配置信息放在在VirtualHost的段中。
样例:
<VirtualHost 10.1.2.3>
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
RewriteLog logs/rewrite.log
RewriteLogLevel 0
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/var/www/html/syssite/vhost.map
RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]
</VirtualHost>
三、网店后台配置说明
前缀+商品ID方式 shop shopxxx.mysite.com
申请的商店用户名方式 username.mysite.com (中文名会有问题)
四、参考资料:
1.rewrite map的路径问题: http://www.webmasterworld.com/apache/3239775.htm
2.简易正则表达式文档: http://www.w3pop.com/sucai/regular_expression/regular_expression.htm#reference
Win的主机的Server变量有点不一样,需要替换syssite目录下的register_act.php文件,否则生成
rewrite map有问题!
关键的配置在这里:一是要打开
Httpd.comf中的
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
<VirtualHost 192.168.0.52:80> //这个是你原来的虚拟主机
AddDefaultCharset GB2312
ServerAdmin *@*.*
ServerName www.a.com
DirectoryIndex index.htm index.html index.jsp
ErrorLog logs/*.net-error_log
CustomLog logs/*.net-access_log common
RewriteEngine on
RewriteLog logs/rewrite.log
RewriteRule ^/$ http://www.b.com/
$1 [R=301,L] //这里设置转向
</VirtualHost>
apache的404错误自定义跳转说明
Submitted by wayswang on 2007, November 2, 9:40 AM. Linux
404错误其实就是我们经常见到的找不到文件的错误,但是那是默认的效果,很难看。
有时候我们需要的这样的功能:我们要记录下来404是的页面时哪些,更有些时候我需要判断404页面是不是本来系统应该生成的静态页面但是没有生成成功的,如果是,我们应该生成这个静态页面,然后把生成的静态页面返回给用户。
我要处理的逻辑就是:把404错误跳转到一个页面,我们取名叫:missing404.php
然后再这个页面中实现我们需要的功能。
首先定义跳转:在虚拟站点定义中使用如下语句即可。
ErrorDocument 404 http
:
//www.blogguy.cn/missing404.php
定义完成后的虚拟站点如下
<
VirtualHost
*:
80
>
ServerAdmin wayswang @ gmail . com
DocumentRoot / usr / local / apache / htdocs / blogguy . cn
ServerName www. blogguy . cn
ServerAlias blogguy. cn
ErrorLog logs/ blogguy . cn_err_log
CustomLog logs/ blogguy . cn - access_log2 common
ErrorDocument 404 http: //www.blogguy.cn/missing404.php
< IfModule mod_limitipconn . c >
<Location / upimg / soft >
MaxConnPerIP 5
</ Location >
</IfModule >
</VirtualHost >
在missing404.php中的处理将另外说明
这里再提供另外一种方法,但是不推荐,以为比较耗资源,使用 .htaccess 来重定向
在 .htaccess 中加入
ErrorDocument 404
/
404.html
不要以为就此完了,你可能会发现404.html根本跳转不到他上面去,嘿嘿,原因是你的404.html文件太小了,IE认为找不到,又是404错误。如果404.html的小于512字节的话,那么IE会认为这个错误页面不够“友好”,会忽视掉的。