运维小知识之nginx---nginx配置Jboss集群负载均衡

时间:2023-03-08 17:12:10

codyl 2016-01-26 00:53:00 浏览385 评论0

负载均衡

转自

运维小知识之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文中如有纰漏之处,还望您能不吝赐教!