購買功能變數名稱。示例:example.com 設置多個二級功能變數名稱。如圖: 配置tomcat文件: 修改tomcat/conf目錄下的server.xml文件: 在tomcat根目錄下,複製webapps文件夾,併在tomcat根目錄下粘貼兩份,分別命名為:webapps1和webapps2。註意此文件夾名稱 ...
-
購買功能變數名稱。示例:example.com
-
設置多個二級功能變數名稱。如圖:
-
配置tomcat文件:
-
修改tomcat/conf目錄下的server.xml文件:
- 如下配置配置了3個容器,使用三個不同的埠。
- 請註意三點:①埠號:Connector port;②容器名稱:portservice name;③項目存放地址:Host appBase;
- 示例配置如下,可直接使用。
<Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> <Service name="Catalina1"> <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina1" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps1" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> <Service name="Catalina2"> <Connector port="8082" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8011" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina1" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps2" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service>
-
在tomcat根目錄下,複製webapps文件夾,併在tomcat根目錄下粘貼兩份,分別命名為:webapps1和webapps2。註意此文件夾名稱需要與第一步server.xml中添加的Host appBase名稱一致。示例圖如下:
-
在tomcat/conf文件夾下,複製Catalina,併在tomcat/conf目錄下粘貼兩份(Catalina文件夾下的localhost文件夾不要更改名稱,否則server.xml所添加的配置也需要改動。為不引起麻煩事,建議直接複製Catalina文件夾即可),分別命名為:Catalina1和Catalina2,註意此文件夾命名需要與第一步server.xml中添加的portservice name名稱一致。示例圖如下:
-
-
配置Nginx反向代理:修改nginx/conf目錄下的nginx.conf文件,添加反向代理配置與虛擬主機配置:
#反向代理 upstream www.example.com{ server 110.110.110.110:8080; #主機ip+埠號 } upstream me.example.com{ server 110.110.110.110:8081; } upstream dev.example.com{ server 110.110.110.110:8082; } #配置虛擬主機 server { listen 80; server_name www.example.com; index index.jsp index.html index.htm; #include proxy-pass-php.conf; location / { proxy_pass http://www.example.com; #與server_name保持一致 proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log /home/wwwlogs/www.example.com.log; } server { listen 80; server_name me.example.com; index index.jsp index.html index.htm; #include proxy-pass-php.conf; location / { proxy_pass http://me.example.com; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log /home/wwwlogs/me.example.com.log; } server { listen 80; server_name dev.example.com; index index.jsp index.html index.htm; #include proxy-pass-php.conf; location / { proxy_pass http://dev.example.com; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log /home/wwwlogs/dev.example.com.log; } include vhost/*.conf;
-
完成配置後,在tomcat中分別於webapps、webapps1、webapps2文件夾下部署三個不同的項目,項目名稱都命名為ROOT.war。啟動tomcat,分別訪問www.example.com、me.example.com、dev.example.com即可。