Nginx 简单的负载均衡配置

1.服务器要开启端口号
upstream fuzai.shenhongwei.top {  
          server 你的公网IP地址:8087 weight=5; #1
          server 你的公网IP地址:8090 weight=10;#2
        }

8087,8090端口需要开启  weight是权重,权重越高访问概率越高
2.
在负载均衡服务器上:
server
    {
        listen 8050; 
        server_name 你的域名; 
        location / { 
            proxy_pass        你的域名; 
            proxy_set_header  Host            $host; 
            proxy_set_header  X-Real-IP        $remote_addr; 
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for; 
        } 
        
        access_log  /home/wwwlogs/access.log;
    }
3.
分别在1服务器和2服务器
server
    {
        listen 8090; 或者8087
        server_name 你的域名; 
        index index.php index.html; 
        root 文件路径;
        
        #error_page   404   /404.html;

        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        #include enable-php.conf;
        location ~ .*\.(php|php7)?$ {
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }
        access_log  /home/wwwlogs/access.log;
    }

4.重启nginx : service nginx restart

5.打开你的域名,测试即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值