nginx反向代理

#安装nginx

yum install -y epel-release

yum install -y nginx

# rpm安装

Index of /packages/centos/7/x86_64/RPMS/

rpm -ivh *.rpm

#启动niginx

systemctl start nginx

systemctl enable nginx

#安装tomact用于测试

有tar包解压

cd 进去

cd bin

./startup.sh

#配置反向代理 /etc/nginx/nginx.conf

#要添加反向代理就添加一段server

#在   http   里在   server   外

#基础字段

    server {
        listen port;
        location / {
        proxy_pass   http://ip:port;
     }

}

#示例

server {
        listen 81;
        location / {
            proxy_pass http://127.0.0.1:8080;
        }
    }

#修改完配置文件后重新加载

nginx -s reload

nginx服务不能重启

#负载均衡

nginx upstream

轮询

权重轮询

ip 哈希

url_hash算法

#配置在http顶部——nginx.conf

upstream tomcat {

    server 127.0.0.1:8080 weight=1 max_fails=3 fail_timeout=10s;
    server 127.0.0.1:8081 weight=5 max_fails=3 fail_timeout=10s;
    server 127.0.0.1:8082 backup; # 备用节点,主节点全挂才启用

}

max_fails=3 fail_timeout=10s 不属于负载均衡策略,是健康检查容错配置

#意思是,当访问失败三次后就,超时等待10秒再继续访问检测

#两处修改一个是添加upstream负载均衡策略

#二是把反向代理的地址换成 upstream 名

#基础配置

#动静分离

#nginx平滑升级

tar -xvf 

cd

dnf install gcc gcc-c++ make pcre-devel zlib-devel openssl-devel -y

CFLAGS="-Wno-deprecated-declarations" ./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module

make -j4

make install

usradd -s /sbin/nologin -M nginx

cd /usr/local/nginx/sbin

./nginx

#解压18

tar

cd

CFLAGS="-Wno-deprecated-declarations" ./configure --prefix=/opt/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module

#只升级主进程sbin/nginx——只替换这个

#把旧的挪走

cd /opt/nginx/sbin

mv /usr/local/nginx/sbin/nginx /root/nginx_old

mv /opt/nginx/sbin/nginx /usr/local/nginx/sbin/nginx

检查配置

ps -ef | grep nginx

kill -USR2 旧pid

ps -ef | frep nginx

#逐步关掉旧进程

kill -WINCH 16591

#在确定新版稳定后

kill -QUIT 16591

#倘若进版本出问题了就把之前的旧版本移回来    nginx_old

记住一个前提更新nginx都是因为服务器不止一个nginx先更新不是主的nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值