日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx+Tomcat集群与负载均衡

發布時間:2025/4/5 Nginx 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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無此情況

<ContextdocBase="/opt/tomcat/cluster01/webapps/ROOT"path=""/>

到此重啟tomcat與nginx服務即可.


轉載于:https://blog.51cto.com/wxl604746107/1305440

總結

以上是生活随笔為你收集整理的Nginx+Tomcat集群与负载均衡的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。