1. 程式人生 > >nginx tomcat 單機多例項多網站

nginx tomcat 單機多例項多網站

參考文章 http://www.ttlsa.com/tomcat/config-multi-tomcat-instance/

修改conf/server.xml

   <Server port="8001" shutdown="SHUTDOWN">
   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

    <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

有幾個就修改幾個server.xml  紅色部分數值依次增加 

啟動檔案tomcat.sh

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #!/bin/sh # AuthName:涼白開 # Website:http://www.ttlsa.com
# DateTime:2014-05-04 # description: 啟動tomcat多例項. ./etc/init.d/functions RETVAL=$? # tomcat例項目錄 exportCATALINA_BASE="$PWD" # tomcat安裝目錄 exportCATALINA_HOME="/usr/local/tomcat-7.0.50" # 可選 exportJVM_OPTIONS="-Xms128m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m" case"$1"in start) if[-f$CATALINA_HOME
/bin/startup.sh];then echo$"Start Tomcat" $CATALINA_HOME/bin/startup.sh fi ;; stop) if[-f$CATALINA_HOME/bin/shutdown.sh];then echo$"Stop Tomcat" $CATALINA_HOME/bin/shutdown.sh fi ;; *) echo$"Usage: $0 {start|stop}" exit1 ;; esac exit$RETVAL

啟動和關閉程式碼分別是 ./tomcat.sh start     ./tomcat.sh stop

所有網站專案都這麼配置

轉到Nginx

在 Nginx/conf/nginx.conf檔案中,將 server{}刪除,取代之

include /usr/lcoal/nginx/conf/vhosts/*;

然後建立並在 vhosts 資料夾裡寫各個網站的訪問規則。例如

 // 注意埠號一定要與上面改動的一致

server {
        listen  80;
        server_name biusxxp.com  www.biusxxp.com;


        location / {
            index index.html index.htm index.jsp;
            proxy_pass http://127.0.0.1:8081;           
        }


}