1. <strike id="x5xg0"><small id="x5xg0"><ruby id="x5xg0"></ruby></small></strike>
      <code id="x5xg0"></code>

      <code id="x5xg0"></code>

      <del id="x5xg0"><em id="x5xg0"><optgroup id="x5xg0"></optgroup></em></del>

      <th id="x5xg0"></th>
      <object id="x5xg0"><option id="x5xg0"></option></object><strike id="x5xg0"><video id="x5xg0"></video></strike>

      當前位置 主頁 > 服務器問題 > nginx問題匯總 > 最大化 縮小

        Nginx+Tomcat多站點部署的方法

        欄目:nginx問題匯總 時間:2018-09-30 16:14

        本篇文章主要介紹了Nginx+Tomcat多站點部署的方法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

        本文介紹了Nginx+Tomcat多站點部署的方法,分享給大家,具體如下:

        Tomcat配置:

        添加多域名:

        Engine節點下:

        添加域名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>

        注意,還需要一個默認語句,即name="localhost"的域名,否則tomcat偶爾會報空指針錯誤,導致無法使用

         <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 stopsudo /etc/init.d/tomcat8 start


        sudo /etc/init.d/tomcat8 restart

        若域名解析完成,則可在瀏覽器中進行測試

        http://test1.java.com:8080
        http://test2.java.com:8080

        若正確,則可正常訪問

        配置Nginx

        進入Nginx根目錄(以ubuntu 16.04為準)

        cd /etc/nginx

        進入sites-available目錄

        cd sites-available

        創建配置文件(已test1.java.com為例)

        vi test1.java.com

        輸入配置內容

        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進行保存

        創建軟連接已進行使用

        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
        
      雅彩彩票登录