轉】Nginx+tomcat叢集環境搭建(Windows下)

來源:互聯網
上載者:User

標籤:目錄結構   apache   查看   tomcat6   程式   poll   pop   exe   end   

 

 

  原博文出自於:    http://blog.csdn.net/clj198606061111/article/details/22621003       感謝!

 

 

 

實驗環境

  windows xp sp3

 

  Nginx版本:1.5.12;

  :http://nginx.org/en/download.html

 

  Tomcat版本:6.0.39

  :http://tomcat.apache.org/download-60.cgi

 

 

 

 

 

一、配置nginx

1、  在D盤根目錄建立nginx檔案夾,把下載的nginx發布包nginx-1.5.12.zip解壓到該目錄。

2、  D:\nginx\nginx-1.5.12目錄結構

Nginx-

              |_  conf      配置目錄

              |_  contrib.

              |_  docs      文檔目錄

              |_  logs      日誌目錄
              |_  temp      臨時檔案目錄

              |_  html      靜態頁面目錄

              |_  nginx.exe 主程式

3、  啟動nginx

  windows下啟動nginx非常簡單,雙擊運行nginx.exe即可。Nginx預設運行在80連接埠,檢查nginx是否啟動我們只需要在瀏覽器中輸入http://localhost便可看到如下頁面,說明我們nginx已經啟起來了。

 

 

 

 

 

1、  停止nginx

如果需要停止nginx,需要開啟一個命令列視窗,進入nginx解壓的目錄,也就是進入nginx.exe檔案所在的目錄,輸入命令nginx –s stop 便可停止nginx。

 

 

 

二、叢集配置

1、  配置tomcat

在D盤根目錄建立tomcat檔案夾,解壓2份tomcat6.0.39發布包到該目錄下,分別命名為tomcat01,tomcat02。為了便於觀察我們訪問的是哪個tomcat,我們修改tomcat01的D:\tomcat\tomcat01\webapps\ROOT\index.html中

  

<td align="left" valign="top"><b>Apache Tomcat</b></td>  

改為

<td align="left" valign="top"><b>Apache Tomcat 1</b></td>  

 

 

 

 

 

同理我們把tomcat02的D:\tomcat\tomcat02\webapps\ROOT\index.html中

<td align="left" valign="top"><b>Apache Tomcat</b></td>  

改為

<td align="left" valign="top"><b>Apache Tomcat 2</b></td>  

 

 

 

2個tomcat我們在同一台電腦上,為了讓2個tomcat的連接埠不衝突,我們把tomcat02的D:\tomcat\tomcat02\conf\server.xml中

<Server port="8005" shutdown="SHUTDOWN">  

 改為

<Server port="8105" shutdown="SHUTDOWN">  

 

 

 

 

<Connector port="8080" protocol="HTTP/1.1"   

           connectionTimeout="20000"   

    redirectPort="8443" />  

 改為

<Connector port="8180" protocol="HTTP/1.1"   

              connectionTimeout="20000"   

    redirectPort="8543" />  

 

 

 

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 

改為

<Connector port="8109" protocol="AJP/1.3" redirectPort="8543" />  

 

 

 

 

2、  配置nginx

nginx.conf

  1. #Nginx所用使用者和組,window下不指定   
  2. #user  niumd niumd;   
  3.   
  4. #工作的子進程數量(通常等於CPU數量或者2倍於CPU)  
  5. worker_processes  2;  
  6.   
  7. #錯誤記錄檔存放路徑  
  8. #error_log  logs/error.log;  
  9. #error_log  logs/error.log  notice;  
  10. #error_log  logs/error.log  info;  
  11.   
  12. #指定pid存放檔案  
  13. #pid        logs/nginx.pid;  
  14.   
  15.   
  16. events {  
  17.     #使用網路IO模型linux建議epoll,FreeBSD建議採用kqueue,window下不指定。  
  18.     #use epoll;  
  19.       
  20.     #允許最大串連數  
  21.     worker_connections  1024;  
  22. }  
  23.   
  24.   
  25. http {  
  26.     include       mime.types;  
  27.     default_type  application/octet-stream;  
  28.   
  29.     #定義日誌格式   
  30.     log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘  
  31.                       ‘$status $body_bytes_sent "$http_referer" ‘  
  32.                       ‘"$http_user_agent" "$http_x_forwarded_for"‘;  
  33.   
  34.     access_log  logs/access.log  main;  
  35.       
  36.     client_header_timeout  3m;  
  37.     client_body_timeout    3m;  
  38.     send_timeout           3m;  
  39.       
  40.     client_header_buffer_size    1k;  
  41.     large_client_header_buffers  4 4k;  
  42.       
  43.   
  44.     sendfile        on;  
  45.     tcp_nopush      on;  
  46.     tcp_nodelay     on;  
  47.   
  48.     #keepalive_timeout  0;  
  49.     keepalive_timeout  65;  
  50.   
  51.     #gzip  on;  
  52.       
  53.     upstream localhost {    
  54.           #根據ip計算將請求分配各那個後端tomcat,許多人誤認為可以解決session問題,其實並不能。    
  55.           #同一機器在多網情況下,路由切換,ip可能不同    
  56.           ip_hash;     
  57.           server localhost:8080;    
  58.           server localhost:8180;    
  59.          }    
  60.   
  61.   
  62.     server {  
  63.         listen       80;  
  64.         server_name  localhost;  
  65.   
  66.         #charset koi8-r;  
  67.   
  68.         #access_log  logs/host.access.log  main;  
  69.   
  70.         location / {  
  71.             proxy_connect_timeout   3;    
  72.             proxy_send_timeout      30;    
  73.               proxy_read_timeout      30;    
  74.             proxy_pass http://localhost;    
  75.         }  
  76.   
  77.         #error_page  404              /404.html;  
  78.   
  79.         # redirect server error pages to the static page /50x.html  
  80.         #  
  81.         error_page   500 502 503 504  /50x.html;  
  82.         location = /50x.html {  
  83.             root   html;  
  84.         }  
  85.   
  86.     }  
  87. }  

 

 

 

 

3、  查看反向 Proxy配置結果

啟動nginx、tomcat01、tomcat02。

瀏覽器輸入http://localhost便看到tomcat01的管理介面,如。

 

 

   然後透明停止tomcat02,重新整理頁面,nginx自動幫我們切換到tomcat02了,如。

 

轉】Nginx+tomcat叢集環境搭建(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.