Under Windows nginx configure multiple servers for load balancing

Nginx (engine x) is a high-performance HTTP server and reverse proxy services, is also a IMAP / POP3 / SMTP services.

Nginx is a lightweight Web server / reverse proxy server and e-mail (IMAP / POP3) proxy server, and released under a BSD-like agreement. It features occupy less memory, high concurrency, the ability to do concurrent nginx fact the same type of web server performance is better.

Next and how everyone in the introduction to Windows nginx configure multiple servers to achieve load balancing applications on IIS.

1, a plurality of servers as a selection nginx proxy server, other servers as the application server (IIS local test, three sites), as shown below:

2, we nginx on the proxy server, install nginx, we first to nginx official website to download the installation package, as shown below:

     Download the official site: http://nginx.org/en/download.html

 

3, the installation package D extract to the root directory, the directory structure of the file, as shown below:

4, the installation find nginx conf file directory nginx.conf, default access port 8080, as shown below:

     Note: If the port is 80, turn off the IIS default port 80

 

5, we can add the following configuration section

    #IIS配置多台Server,weight是权重,权重越大,被访问的几率越大
    upstream iis_server{
        server 127.0.0.1:801 weight=1;
        server 127.0.0.1:802 weight=1;
        server 127.0.0.1:803 weight=1;
    }

6、接下来我们修改端口为8080,然后在location配置节下配置代理地址已经静态的目录,如下图所示:

        location / {
            root   html;
            index  index.html index.htm;
            #iis_server代理地址
            proxy_pass http://iis_server;
        }

7、设置字符集,以防止中文字符乱码,如下图所示:

 

8、进入到nginx根目录,使用命令提示符关闭和重新启动nginx,

 

9、然后我们通过nginx代理服务地址访问,可以看到内容是随机访问3台服务器上的,如果我们有多台服务器,在这多台服务器上部署相同的应用,就可以达到负载均衡的目的,如下图所示:

 

Windows下Nginx的启动、停止等命令

在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动、停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍。
1、启动:

C:\server\nginx-1.0.2>start nginx

或

C:\server\nginx-1.0.2>nginx.exe

注:建议使用第一种,第二种会使你的cmd窗口一直处于执行中,不能进行其他命令操作。

2、停止:

C:\server\nginx-1.0.2>nginx.exe -s stop

或

C:\server\nginx-1.0.2>nginx.exe -s quit


注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。

3、重新载入Nginx:

C:\server\nginx-1.0.2>nginx.exe -s reload

当配置信息修改,需要重新载入这些配置时使用此命令。

4、重新打开日志文件:

C:\server\nginx-1.0.2>nginx.exe -s reopen

5、查看Nginx版本:

C:\server\nginx-1.0.2>nginx -v

 

 参考手册:http://shouce.jb51.net/nginx/left.html

 

转:http://www.mssqls.com/Home/ListDetail/d1a253d7-ab52-4858-85ad-db21d27bc625

 https://www.cnblogs.com/kevin1990/p/6821948.html

 

Guess you like

Origin www.cnblogs.com/pingming/p/11202960.html