栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Nginx负载均衡实现动态分离

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx负载均衡实现动态分离

Nginx负载均衡实现动态分离
  • 反向代理与负载均衡

环境

主机名IP服务
agent192.168.164.128Nginx
Nginx192.168.164.133Nginx
httpd192.168.164.137httpd
反向代理与负载均衡

每台主机都关闭防火墙和selinux

[root@localhost]# systemctl stop firewalld.service   //临时关闭防火墙,重启后依旧启动
[root@localhost]# setenforce 0
[root@localhost]# vim /etc/selinux/config
...
SELINUX=disabled
...

agent配置

[root@localhost]#  vim /usr/local/nginx/conf/nginx.conf
......  
     upstream webservers {					//配置负载均衡
          server 192.168.164.133;
         server 192.168.164.137;
    }

     server {
         listen       80;
         server_name  localhost;
          #charset koi8-r;
 
          #access_log  logs/host.access.log  main;
  
          location / {						// 配置反向代理
              proxy_pass http://webservers;
          }
  ......
[root@agent ~]# nginx -t   //检查语法是否有误
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@agent ~]# nginx -s reload    //重新加载配置文件

使用agent的站点


配置动静分离

修改agent主机的Nginx配置文件

[root@localhost]#  vim /usr/local/nginx/conf/nginx.conf
......
 #gzip  on;
upstream dynamic {        
        server 192.168.47.120;			//动态主机的ip
    }
    upstream static {
        server 192.168.47.121;			//静态主机的ip
    }	


    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://static;			//访问静态资源会自动跳转至静态主机
        }

        #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://dynamic;		//访问动态资源会自动跳转到动态主机
        }
......
[root@agent ~]# nginx -t    //检查配置文件语法是否有问题
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@agent ~]# nginx -s reload    //重新加载配置文件

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/388600.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号