nginx 反向代理及负载均衡

假设我们在 192.168.137.11:8080 上有一个web服务,在 192.168.137.12 配置了一台 nginx,我们可以进行如下配置:

location / {
    proxy_pass http://192.168.137.11:8080;
}

这样配置后,我们对 192.168.137.12 的访问都会被转发到 192.168.137.11:8080,此时这台 nginx 就是反向代理服务器。

 

负载均衡:

现在还有一台 192.168.137.13:8080 提供与 192.168.137.11:8080  一样的web 服务,nginx 通过下面的配置,可以实现负载均衡。

upstream loadbalance {

    ip_hash;
    server 192.168.137.11:8080;
    server 192.168.137.48:8080;    

    #下面的3行配置是用于检查上面配置的服务器的状态的
    check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    check_http_send "HEAD / HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;

}

server {
    listen 80;
    server_name www.nginx1.com;

    location / {
        proxy_pass http://loadbalance;
        root html;
        index index.html index.htm;
    }

    location /status { #通过此URL(www.nginx1.com/status)可查看服务器的状态。这功能被 tengine 增强了

        check_status;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

}

posted @ 2018-02-25 11:05  一剑侵心  阅读(295)  评论(0编辑  收藏  举报