1 Install tomcat/apache
2 Download jk.so, please select the specific version according to your needs, no more details
3 The key is configuration
httpd.conf view copy to clipboard print
# Remove the # in front of this 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
# Virtual host, here simulates the calls of a.test.com, b.test.com and a.tst.com/blog
<VirtualHost_default_:80>
ServerAdmin [email protected]
DocumentRoot D:Apache2.2htdocs
ServerName all-sites
ErrorLog logs/all-sites-error.log
CustomLog logs/all-sites-access.log common
RewriteEngineOn
# The following three lines implement dynamic parsing
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>
# Remove the # in front of this 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
# Virtual host, here simulates the calls of a.test.com, b.test.com and a.tst.com/blog
<VirtualHost _default_:80>
ServerAdmin [email protected]
DocumentRoot D:Apache2.2htdocs
ServerName all-sites
ErrorLog logs/all-sites-error.log
CustomLog logs/all-sites-access.log common
RewriteEngineOn
# The following three lines implement dynamic parsing
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 view copy to clipboard print
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=tomcat1
worker.status.type=status
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=tomcat1
worker.status.type=status server.xml
Remove the <!-- and --> before and after and enable port 8009 to view and copy to the clipboard for printing.
<Connector port="8009"
..
<Connector port="8009"
...Explain that rewrite_module and mod_jk are enabled in httpd.conf, and the connection configuration with tomcat is configured.
The configuration of virtual host is key
ServerName all-sites
can be modified to
ServerName test.com
ServerAlias*.test.com
This allows you to clearly specify the domain name that this virtual host is responsible for.
urlRewrite configuration part
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 host names (%{HTTP_HOST}) similar to XXXX.test.com. That is the second line of the regular code, which rewrites all requests for this domain name for the first time, such as
a.test.com changed to
/a.test.com
Bundle
b.test.com/blog changed to
/b.test/com/blog
In the third line, adjust the parameter-less access and change /a.test.com to
/index.jsp?u=a
The fourth line, adjust the parameter path and change /b.test.com/blog to
/blog.jsp?u=b
If there are parameters such as
b.test.com/id=3 is finally rewritten as
/b.test.com/id=3
/blog.jsp?u=b&id=3
Not much to say about the rest!
http://www.laozizhu.com/view.jsp?articleId=553