windowXP下搭建nginx和tomcat的集羣


首先搞定三個不一樣的tomcat,
修改conf目錄中的server.xml文件,保持tomcat的server端口
和connection端口不一樣便可  www.2cto.com  
第一個:
<Server port="8115" shutdown="SHUTDOWN">
第二個:
<Connector port="18082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8423" />
 
其餘幾個tomcat作相同的改動,只是端口應該不一樣;
 
測試這三個tomcat是否成功。同時啓動tomcat,再作相應的訪問;
  www.2cto.com  
配置nginx的配置:nginx.conf 
 
#Nginx所用用戶和組,window下不指定 
#user niumd niumd; 
#工做的子進程數量(一般等於CPU數量或者2倍於CPU) 
 
worker_processes 2; 
 
#錯誤日誌存放路徑 
#error_log logs/error.log; 
#error_log logs/error.log notice; 
error_log logs/error.log info; 
 
#指定pid存放文件   www.2cto.com  
pid logs/nginx.pid; 
 
events { 
#使用網絡IO模型linux建議epoll,FreeBSD建議採用kqueue,window下不指定。 
#use epoll; 
 
#容許最大鏈接數 
worker_connections 2048; 
 
 
http { 
include mime.types; 
default_type application/octet-stream; 
 
 
#定義日誌格式 
#log_format main '$remote_addr - $remote_user [$time_local] $request ' 
# '"$status" $body_bytes_sent "$http_referer" ' 
# '"$http_user_agent" "$http_x_forwarded_for"'; 
#access_log off; 
 
 
access_log logs/access.log; 
client_header_timeout 3m; 
client_body_timeout 3m; 
send_timeout 3m; 
client_header_buffer_size 1k; 
large_client_header_buffers 4 4k; 
sendfile on; 
tcp_nopush on; 
tcp_nodelay on; 
 
#keepalive_timeout 75 20; 
 
include gzip.conf; 
upstream localhost { 
#根據ip計算將請求分配各那個後端tomcat,許多人誤認爲能夠解決
session問題,其實並不能。 
#同一機器在多網狀況下,路由切換,ip可能不一樣 
#ip_hash; 
server localhost:18081; 
server localhost:18082; 
server localhost:18083;
server { 
listen 8088; 
server_name localhost; 
 
location / { 
proxy_connect_timeout 3; 
proxy_send_timeout 30; 
proxy_read_timeout 30; 
proxy_pass http://localhost; 
}
 
代理設置以下:
Proxy.conf代碼:
proxy_redirect off; 
proxy_set_header Host $host; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
client_max_body_size 10m; 
client_body_buffer_size 128k; 
proxy_connect_timeout 300; 
proxy_send_timeout 300; 
proxy_read_timeout 300; 
proxy_buffer_size 4k; 
proxy_buffers 4 32k; 
proxy_busy_buffers_size 64k; 
proxy_temp_file_write_size 64k;
gzip壓縮相關配置以下:  www.2cto.com  
Gzip.conf代碼:
gzip on; 
gzip_min_length 1000; 
gzip_types text/plain text/css application/x-javascript;
 
驗證配置與測試負載均衡
首先測試nginx配置是否正確,測試命令:nginx -t (默認驗證:conf\nginx.conf),也能夠指定配置文件路徑。
驗證配置負載均衡設置,http://localhost/ 或http://localhost/index.jsp
 
PS:多按按F5刷新網頁,查看tomcat是否是改變了呢。。。。。。
個人案例 下載 :http://l7.yunpan.cn/lk/Q2shePhjvTLNh  (27.5M)
nginx:http://l7.yunpan.cn/lk/Q2sCyc654H7Xm   (1.2M)
相關文章
相關標籤/搜索