这篇文章我准备了很久了,但一直没来得及整理,今天抽时间分享出来。本文是结合我的网站的示例进行讲解。首先看看我的几个网站。
主站:CODE大全,网址:http://www.codedq.net
二级域名站:
Book阅读,网址:http://book.codedq.net/
网址大全,网址:http://site.codedq.net/
在线工具,网址:http://tool.codedq.net/
百度网盘搜索,网址:http://pan.codedq.net/
在线小游戏,网址:http://pan.codedq.net/
二级域名的申请很简单,直接到你购买域名的网站上,新增一条解析即可。二级域名不需要重新备案。如果你不会申请二级域名,可以看这篇文章:http://jingyan.baidu.com/article/22a299b51948d19e19376ae7.html
worker_processes 1; events { use epoll; worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; fastcgi_intercept_errors on; gzip on; gzip_min_length 1000; gzip_types text/plain application/x-javascript text/css application/xml; upstream localhost { server localhost:6688; } server { listen 80; server_name localhost; location / { #root html; #index index.html index.htm; proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://localhost; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name pan.codedq.net; location / { proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://localhost/pan; } error_page 404 /404.html; } server { listen 80; server_name site.codedq.net; location / { root /www/site; index index.html; proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; } error_page 404 /404.html; location = /40x.html { root html; } } server { listen 80; server_name tool.codedq.net; location / { proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://localhost/tool; } error_page 404 /404.html; } server { listen 80; server_name game.codedq.net; location / { proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://localhost/game; } error_page 404 /404.html; } server { listen 80; server_name book.codedq.net; location / { root /www/book; index index.html; proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; } error_page 404 /404.html; } }
在 tomcat 的conf目录下,找到 server.xml ,在已有的<Host>节点后面添加一下配置,即可。
<Host name="tool.codedq.net" appBase="" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/www/tool" reloadable="false"/> </Host> <Host name="site.codedq.net" appBase="" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/www/site" reloadable="false"/> </Host> <Host name="game.codedq.net" appBase="" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/www/game" reloadable="false"/> </Host> <Host name="pan.codedq.net" appBase="" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/www/pan" reloadable="false"/> </Host>