Http://www.java2000.net/viewthread.jsp? Tid = 5422
Do you want your server to provide an independent second-level domain name for each member? For example
Aa.test.com
Bb.test.com/blog
Of course, both AA and BB are your members.
Below are some of my successful attempts today
1. I will not talk about installing Apache, tomcat, and mod_jk. If you cannot use them, please refer to other tutorials.
2. Related configuration files
Httpd. conf
# Remove the preceding # and enable it
Loadmodule rewrite_module modules/mod_rewrite.so
# Enable JK and configure parameters at the same time
Loadmodule jk_module modules/mod_jk.so
Jkworkersfile D:/apache2.2/CONF/workers. Properties
Jklogfile D:/apache2.2/logs/mod_jk.log
Jkloglevel info
# Jkloglevel debug
Jklogstampformat "[% A % B % d % H: % m: % S % Y]"
Jkoptions + forwardkeysize + forwarduricompat-forwarddirectories
Jkrequestlogformat "% w % v % t"
Jkmount/servlet/* myloadbalancer
Jkmount/*. jsp myloadbalancer
# VM. The call of a.test.com, B .test.com, and a.tst.com/blogis simulated here.
<Virtualhost _ default _: 80>
Serveradmin yourmail@domain.com
DocumentRoot D: apache2.2htdocs
Servername all-sites
Errorlog logs/all-sites-error.log
Customlog logs/all-sites-access.log common
Rewriteengine on
# The following four lines implement dynamic resolution
Rewritecond % {http_host} ^ [a-z0-9-] + .test.com $
Rewriterule ^/(. *) $/% {http_host}/$1
Rewriterule ^/[a-z0-9-] +) .test.com /? $/Index. jsp? U = $1 [L, pt]
Rewriterule ^/([a-z0-9-] +) .test.com/blog (/(.*))? $/Blog. jsp? U = $1 & $3 [L, pt]
<Directory "D: apache2.2htdocs">
Options followsymlinks
AllowOverride none
Order allow, deny
Allow from all
</Directory>
</Virtualhost>
Workers. Properties
Worker. List = myloadbalancer
Worker. tomcat1.type = ajp13
Worker. tomcat1.host = localhost
Worker. tomcat1.port = 8009
Worker. tomcat1.lbfactor = 1
Worker. myloadbalancer. type = LB
Worker. myloadbalancer. balance_workers = worker at1
Worker. Status. type = Status
Server. xml
Remove the preceding and following <! -- And --> enable port 8009
<Connection Port = "8009"
...
3. Description
In httpd. conf, rewrite_module and mod_jk are enabled, and tomcat connection configuration is configured.
Virtual Host Configuration is critical
Servername all-sites
Can be modified
Servername test.com
Serveralias * .test.com
In this way, you can specify the Domain Name of the VM.
Urlrewrite Configuration
- Rewritecond % {http_host} ^ [a-z0-9/-] +/. Test/. com $
- Rewriterule ^/(. *) $/% {http_host}/$1
- Rewriterule ^/([a-z0-9/-] +)/. Test/. com /? $/Index. jsp? U = $1 [L, pt]
- Rewriterule ^/([a-z0-9/-] +)/. Test/. com/blog (/(.*))? $/Blog. jsp? U = $1 & $3 [L, pt]
The first line declares that this rewrite is only interested in the Host Name (% {http_host}) similar to xxxx.test.com, which is a regular
In the second line, all requests for this domain name are rewritten for the first time, for example
Change a.test.com
/A.test.com
Set
B .test.com/blog changed
/B. Test/COM/blog
Row 3: Adjust access without Parameters
Change/a.test.com
/Index. jsp? U =
Row 4: Adjust the path with Parameters
Change/B .test.com/blog
/Blog. jsp? U = B
If there are parameters such
B .test.com/id1_3 is finally rewritten
/B .test.com/id1_3
/Blog. jsp? U = B & id = 3
I won't say much about the rest!