nginx使用
先安装gcc yum install -y gcc
再安装pcre 解压出来,进去目录 ./configure 然后 make&&make install
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
解压nginx 进入目录 ./configure 然后 make&&make install
安装完成后在 /usr/local 多出了 nginx文件夹
在这个文件夹里有 sbin,sbin里有启动脚本
cd sbin ./nginx
在 /usr/local/nginx目录下的conf有配置文件nginx.conf
server{
listen 80; //端口号
......
}
nginx常用命令
./nginx 启动
./nginx -s stop 停止
./nginx -v 查看版本号
./nginx -s reload 重新加载
安装tomcat并启动后,在nginx的conf目录下的nginx.conf中
server{
location: //改成自身ip地址
...
location / {
...
proxy_pass http://host:port;
...
}
}
./nginx -s reload
负载均衡在 nginx.conf配置,添加
upstream foobar {
server ip:port
server ip:port
}
然后在 server的location里添加 proxy_pass http://foobar;
分配策略:
1.轮询
每个请求按照时间顺序注意分配到不同的后端服务器,如果有一个宕机了,能自动剔除
2.weight
在upstream里每个server的ip的后面添加 weight=number;
3.ip_hash
在upstream的第一行添加 ip_hash;
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器
4.fair(第三方)
按后端服务器的响应时间来分配,越短越优先分配
在upstream里,所有server的最后一行添加 fair;
如果乱码,在nginx.conf里的server里添加 charset utf8,gbk;
nginx高可用
yum install keepalived -y
安装好之后在etc会生成目录keepalived 里面的keepalived.conf
ssl ./configure --with-http_ssl_module //重新添加这个ssl模块 make&&make install 重新编译安装

浙公网安备 33010602011771号