Nginx+Tomcat多站點(diǎn)部署的方法
本文介紹了Nginx+Tomcat多站點(diǎn)部署的方法,分享給大家,具體如下:
Tomcat配置:
添加多域名:
Engine節(jié)點(diǎn)下:
添加域名1
<Host name="test1.java.com" 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" /> <Context path="" docBase="/var/lib/tomcat8/webapps/test1" debug="0" reloadable="true" crossContext="true" /> </Host>
添加域名2
<Host name="test1.java.com" 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" /> <Context path="" docBase="/var/lib/tomcat8/webapps/manage" debug="0" reloadable="true" crossContext="true" /> </Host>
注意,還需要一個(gè)默認(rèn)語句,即name="localhost"的域名,否則tomcat偶爾會(huì)報(bào)空指針錯(cuò)誤,導(dǎo)致無法使用
<Host name="localhost" appBase="webapps0" 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" /> <Context path="" docBase="/var/lib/tomcat8/webapps/manage" debug="0" reloadable="true" crossContext="true" /> </Host>
至此,配置完成,重啟tomcat:
sudo /etc/init.d/tomcat8 stop sudo /etc/init.d/tomcat8 start
或
sudo /etc/init.d/tomcat8 restart
若域名解析完成,則可在瀏覽器中進(jìn)行測試
http://test1.java.com:8080
http://test2.java.com:8080
若正確,則可正常訪問
配置Nginx
進(jìn)入Nginx根目錄(以ubuntu 16.04為準(zhǔn))
cd /etc/nginx
進(jìn)入sites-available目錄
cd sites-available
創(chuàng)建配置文件(已test1.java.com為例)
vi test1.java.com
輸入配置內(nèi)容
server{ listen 80; server_name test1.java.com; server_name_in_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://test1.java.com:8080; } }
esc后:wq進(jìn)行保存
創(chuàng)建軟連接已進(jìn)行使用
ln -s /etc/nginx/sites-available/test1.java.com /etc/nginx/sites-enabled/test1.java.com
重啟Nginx
/etc/init.d/nginx stop /etc/init.d/nginx start 或 /etc/init.d/nginx restart
至此 配置完成
還有一些其他的配置方法,比如tomcat可配置為多端口對應(yīng)多站點(diǎn),但我配置后發(fā)現(xiàn)速度明顯變慢,未找到原因,而此配置已經(jīng)能滿足要求,特此記錄。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
nginx禁止直接通過ip進(jìn)行訪問并跳轉(zhuǎn)到自定義500頁面的操作
這篇文章主要介紹了nginx禁止直接通過ip進(jìn)行訪問并跳轉(zhuǎn)到自定義500頁面的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05訪問nginx顯示未找到站點(diǎn)的問題分析及解決方案
當(dāng)我們在安裝好nginx準(zhǔn)備訪問80端口時(shí),突然出現(xiàn)您的請求在Web服務(wù)器中沒有找到對應(yīng)的站點(diǎn),所以本文給大家介紹了訪問nginx顯示未找到站點(diǎn)的問題分析及解決方案,需要的朋友可以參考下2024-03-03Jenkins實(shí)現(xiàn)集群化管理以及流水線項(xiàng)目配置
這篇文章主要為大家介紹了Jenkins基本概念,配置實(shí)現(xiàn)集群化管理以及配置流水線項(xiàng)目的實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03nginx提示:500 Internal Server Error錯(cuò)誤解決辦法
這篇文章主要介紹了 nginx提示:500 Internal Server Error錯(cuò)誤解決辦法的相關(guān)資料,這里提供了解決該問題的詳細(xì)步驟,希望能幫助到大家,需要的朋友可以參考下2017-08-08使用Docker主機(jī)啟動(dòng)Nginx服務(wù)器的完整步驟詳解
Docker是一個(gè)開源的容器化平臺(tái),用于輕松地打包、部署和運(yùn)行應(yīng)用程序,而Nginx是一個(gè)高性能的開源反向代理服務(wù)器,也是一個(gè)流行的Web服務(wù)器,這篇文章主要給大家介紹了關(guān)于使用Docker主機(jī)啟動(dòng)Nginx服務(wù)器的完整步驟,需要的朋友可以參考下2024-07-07