nginx

2022-03-08  本文已影响0人  wsj1211

nginx 简介

  1. 准备工作
    对外开放端口
    firewall-cmd --add-port=8080/tcp --permanent
    firewall-cmd --reload
    查看已经开放的端口号
    firewall-cmd --list-all
  2. 配置文件:
    三部分组成
  1. 案例

反向代理

root  html;
proxy_pass http://xxx.xxx.xxx:8080;
index index.html index.htm;

}
}
~~~

负载均衡

修改配置文件

#在http块添加upstream server中location的proxy_pass 配成upstream的名字
http {
   upstream  dalaoyang-server {
       server    localhost:10001;
       server    localhost:10002;
   }

   server {
       listen       10000;
       server_name  localhost;

       location / {
        proxy_pass http://dalaoyang-server;
        proxy_redirect default;
      }

    }

}

负载均衡的方式

upstream  dalaoyang-server {
       server    localhost:10001 weight=1;
       server    localhost:10002 weight=2;
}
upstream  dalaoyang-server {
       ip_hash; 
       server    localhost:10001 weight=1;
       server    localhost:10002 weight=2;
}
upstream  dalaoyang-server {
       server    localhost:10001;
       server    localhost:10002;
       fair;  
}

动静分离

就是配置为访问服务器的一个文件夹 即可访问文件夹下的图片和html文件等

高可用模式

两台服务器+ keepalived(配置相同的虚拟ip)
两台服务器都启动nginx 并配置一样的环境(nginx+ keepalived)
keepalived分为master和backup 一台服务器宕机 自动转为获取另外一台服务器

nginx内部模式

上一篇下一篇

猜你喜欢

热点阅读