nginx實現負載均衡

在本地的Windows環境下使用nginx,雙擊nginx.exe啓動。(保證conf\nginx.conf中配置的端口未被佔用)html

查看nginx是否運行:nginx

修改conf\nginx.conf, 添加upstream esl, 並使用於proxy_pass:ui

#其餘配置

http {

    upstream esl {
        server 192.168.100.117:9999 weight=3;
        server 192.168.100.118:9999 weight=1;
    }

    #其餘配置

	server {
        listen       8888;
        server_name  localhost;

        location / {
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers "Origin, X-Requested-With, C                                                                                                                                                        ontent-Type, Accept";
            add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";

            root   html/build/dist;
            index  index.html index.htm;
        }

        location /zk/ {
            rewrite  ^/zk/(.*)$ /$1 break;
            proxy_pass http://esl;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                   root   html;
        }
    }
}

加載配置:code

nginx.exe -s reload

配置完成後,訪問http://localhost:8888,實際訪問esl中配置的兩臺機器。server

PS: nginx.exe的全部操做htm

關閉nginx,只須要blog

nginx.exe -s quit
相關文章
相關標籤/搜索