Nginx+Tomcat集群与负载均衡
生活随笔
收集整理的這篇文章主要介紹了
Nginx+Tomcat集群与负载均衡
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Nginx+Tomcat集群與負載均衡
架構描述
前端一臺nginx服務器做負載均衡器,后端放N臺tomcat組成集群處理服務,通過nginx轉發到后面(注:沒做動靜分離,靜態動態全部都轉給tomcat)
優點:實現了可彈性化的架構,在壓力增大的時候可以臨時添加tomcat服務器添加到這個架構里面去.
先修改nginx.conf配置
如想了解Nginx負載均衡策略,請查閱Nginx負載均衡策略.
user nginx; worker_processes 10; worker_rlimit_nofile 100000;error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice;#error_log /var/log/nginx/error.log info;pid /var/run/nginx.pid;events {worker_connections 1024;use epoll; }http {include /etc/nginx/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 /var/log/nginx/access.log main;sendfile on;tcp_nopush on;tcp_nodelay on;server_tokens off;gzip on;gzip_static on;gzip_comp_level 5;gzip_min_length 1024;keepalive_timeout 65;limit_conn_zone $binary_remote_addr zone=addr:10m;# Load config files from the /etc/nginx/conf.d directoryinclude /etc/nginx/conf.d/*.conf;upstream www.wp.com {#此處為輪詢策略 換成你自己的tomcat地址#可以根據自己的需求配置多個tomcat,當某個地址無效時,nginx會自動切換server 192.168.5.206:8081;server 192.168.5.206:8082;}server {#配置對應的端口與域名listen 80;server_name www.wp.com;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;#配置上面的server nameproxy_pass http://www.wp.com;proxy_set_header X-Real-IP $remote_addr;}location ~ ^/(WEB-INF)/ {deny all;}error_page 404 /404.html;location = /404.html {root /usr/share/nginx/html;}# redirect server error pages to the static page /50x.htmlerror_page 500502503504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}}}修改tomcat配置
找到TOMCAT_HOME/conf/server.xml,在host標簽處加入Context標簽
注意:如果是單機啟動多tomcat需要改變對應的port,否則會啟動不了,多機tomcat無此情況
到此重啟tomcat與nginx服務即可.
轉載于:https://blog.51cto.com/wxl604746107/1305440
總結
以上是生活随笔為你收集整理的Nginx+Tomcat集群与负载均衡的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 修正本地乱码(待补充)
- 下一篇: qt显示图片