CentOs nginx 安装 及 负载均衡配置

来源:互联网 发布:金润软件成都 编辑:程序博客网 时间:2024/04/30 14:28

准备rpm包:

下载nginx的rpm包:http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

步骤:

a、先安装pcre(重定向)和openssl(Https)    yum -y install pcre*    yum -y install openssl*    (可以考虑在装服务器的时候选择安装这俩文件)b、rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm c、yum install nginx

查询Nginx路径:

whereis nginx            nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx1 配置所在目录:/etc/nginx/2 PID目录:/var/run/nginx.pid3 错误日志:/var/log/nginx/error.log4 访问日志:/var/log/nginx/access.log5 默认站点目录:/usr/share/nginx/html

常用命令:

启动nginx: nginx重启nginx: nginx -s reload停止nginx: nginx -s stop

配置负载均衡:

主配置文件:/etc/nginx/nginx.confserver配置文件:etc/nginx/conf.d/default.conf1、在nginx.conf里面的http模块下添加如下内容:(具体根据实际情况配置)    #服务器集群    upstream jboss7{   #jboss7是服务器集群名称,自定义        ip_hash;       #自动定位到同一台后端服务器上        #sticky;       #需另外安装        server 192.168.xx.xx:8080 weight=1;        server 192.168.xx.xx:8080 weight=1;        server 191.168.xx.xx:8080 weight=1 down;        #注意事项:        #nginx sticky模块不能与ip_hash同时使用        #weight是权重的意思,权重越大,分配的概率越大    }2、在conf.d/default.conf server模块修改如下:    location / {        proxy_connect_timeout   3;        proxy_read_timeout      10;        proxy_send_timeout      10;        proxy_pass       http://192.168.xx.xx;    }

sticky下载地址:http://code.google.com/p/nginx-sticky-module/downloads/list

参考:
nginx安装:
http://yubosun.akhtm.com/tech/centos-nginx.htm

nginx sticky使用:

0 0
原创粉丝点击