160512、nginx+多個tomcat叢集+session共用(windows版)

來源:互聯網
上載者:User

標籤:

第一步:下載nginx的windows版本,解壓即可使用,點擊nginx.exe啟動nginx

或cmd命令

 

1、啟動:

D:\nginx+tomcat\nginx-1.9.3>start nginx或D:\nginx+tomcat\nginx-1.9.3>nginx.exe註:建議使用第一種,第二種會使你的cmd視窗一直處於執行中,不能進行其他命令操作。

2、停止:

D:\nginx+tomcat\nginx-1.9.3>nginx.exe -s stop或D:\nginx+tomcat\nginx-1.9.3>nginx.exe -s quit註:stop是快速停止nginx,可能並不儲存相關資訊;quit是完整有序的停止nginx,並儲存相關資訊。

3、重新載入Nginx:

D:\nginx+tomcat\nginx-1.9.3>nginx.exe -s reload

當配置資訊修改,需要重新載入這些配置時使用此命令。

4、重新開啟記錄檔:

D:\nginx+tomcat\nginx-1.9.3>nginx.exe -s reopen

5、查看Nginx版本:

D:\nginx+tomcat\nginx-1.9.3>nginx -v

nginx預設連接埠是80直接存取localhost如果顯示nginx歡迎頁面則表明成功,這一步一般不會出現問題

第三步:配置幾個tomcat,每個裡面分別將server.xml中8080,8005,8009這幾個地方修改掉就可以了

第三步:修改nginx.conf(注意添加紅色部分就可以了)

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

upstream server_lb{#server_lb跟下面的一樣

server localhost:8090;#這裡是tomcat的地址

server localhost:8091;

}

    server {

        listen       80;

        server_name  localhost;

        location / {

            root   html;

    proxy_pass http://server_lb;

            index  index.html index.htm index.jspf index.jsp;

    proxy_redirect  default;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }

}

第四步:修改每個tomcat中的server.xml設定檔檔案

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" jvmRoute="jvmRoute"/>

注,但是此時由於每個tomcat部署同一套工程,如果有資料 直接寫往session,而且不是使用的cookie存放session的key(由於訪問地址使用ip,並不適用網域名稱,所以沒法使用cookie),會 造成兩次訪問session id不一致。此時就需要做session複製或共用。需要以下操作:

第五步:session共用,因為windows中支援tomcat的廣播機制,所以只需在web.xm中添加<distributable/>就可以了;如果再linux中需要實現session共用就不能通過這種方式,linux中可以通過redis,後期將會介紹

      通過以上步驟就實現了再windows中nginx叢集tomcat,並實現了session共用。如果需要視頻的朋友,可以在往期的文章中尋找

160512、nginx+多個tomcat叢集+session共用(windows版)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.