运维小知识之nginx---nginx配置Jboss集群负载均衡
转自
运维小知识之nginx---nginx配置Jboss集群负载均衡-博客-云栖社区-阿里云
https://yq.aliyun.com/articles/17925
运维小知识之nginx---nginx配置Jboss集群负载均衡
背景
紧接着上一篇博客《运维小知识---CentOS6.5安装nginx配置nginx sticky》安装完成之后剩下的工作就是配置了,其实如果我们想要去做负载均衡session共享是一个绕不过去的问题,而解决session共享的方法有很多,我这里介绍的事使用nginx sticky,方便易用。
具体配置
由于目前的项目中会出现什么情况还不清楚,所以目前只是做了最简单的配置,如下:
http { include mime.types; default_type application/octet-stream; #Proxy_cache_path /usr/local/nginx/NginxTestImgLoglevels=1:2 keys_zone=cache_one:200minactive=1d max_size=30g; #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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #服务器的集群 upstream jboss6.2 { #服务器集群名字 #server 172.16.21.13:8081 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。 sticky; #配置session共享 server xxx.xx.xx.25:80weight=1; server xxx.xx.xx.26:80weight=1; server xxx.xx.xx.27:80weight=1; } #当前的Nginx的配置 server { listen 80; server_name yyy.yy.yyy.121; rewrite_log on; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://jboss6.2; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
目前只使用了一台nginx服务器,如果其宕机了就无法怎么办这个问题也暂时没有考虑(配置一个nginx集群,当然这些都是后话了),笔者一直坚信最好的开发是按需而为,不是炫技,不是过度设计。在技术这条路上,听过,看过,最重要的是做过!
最后还想强调的一句话是——不解决session共享的负载均衡其实是耍流氓。笔者初步接触nginx文中如有纰漏之处,还望您能不吝赐教!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?