Configuring Nginx for WINDOWS/IIS Application load Balancing

Source: Internet
Author: User
Tags servervariables nginx server

Nginx is a cross-platform high-performance HTTP and reverse proxy server developed by the Russians, which can be used to load balance the Web application server.

Reverse proxy refers to the application server that forwards the user request through the proxy server to the back-end internal network, the typical application such as the configuration Nginx, lighttpd and other reverse proxy software to achieve load balancing. The reverse proxy is called a forward proxy, a typical application such as a VPN. Users will not be able to access the Google site directly, and the proxy server can access the Google site. This allows users to access the proxy server, thereby indirectly achieving the purpose of accessing the Google site.

Load balancing means that a large number of Web requests initiated by users are distributed to multiple application servers through a certain algorithm, and the goal of reducing server load pressure is never achieved.

Nginx Official website: http://nginx.org/, can be downloaded on the website. This blog combined with Windows/iis+asp.net+nginx to achieve load balancing, so we download the corresponding Windows version of Nginx. After downloading, we extract the following directories to see Nginx:

We open the nginx.conf file under the Conf directory and modify it to the following configuration:

#user nobody;worker_processes 4; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;events {worker_connections 1024;}    HTTP {include mime.types;    Default_type Application/octet-stream;  #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent    "$http _referer" ' # ' "$http _user_agent" "$http _x_forwarded_for";    #access_log Logs/access.log Main;    Sendfile on;    #tcp_nopush on;    #keepalive_timeout 0;    Keepalive_timeout 65;        #gzip on;        Upstream Cluster_server {server 10.77.137.120:9000 weight=1;    Server 10.77.137.11:8081 weight=2;        } server {Listen 8083;        server_name guwei4037-pc;        #charset Utf-8;        #access_log Logs/host.access.log Main;            Location/{root HTML; Index index.aspx index.html index.htM                        #指向集群名称为cluster_server Proxy_pass Http://cluster_server;            #设置主机头和客户端真实地址 so that the server obtains the client real IP proxy_set_header Host $host;            Proxy_set_header X-real-ip $remote _addr;                        Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;        #禁用缓存 proxy_buffering off; } location ~ \.            (JPG|PNG|JPEG|BMP|GIF|SWF|CSS) $ {expires 30d;        root/nginx-1.9.3/html; #root: #静态文件存在地址, set here under/nginx-1.9.3/html break;        } #error_page 404/404.html;        # REDIRECT Server error pages to the static page/50x.html # Error_page 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$ {# ProX        Y_pass http://127.0.0.1;  #}      # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {#        root HTML;        # Fastcgi_pass 127.0.0.1:9000;        # Fastcgi_index index.php;        # Fastcgi_param Script_filename/scripts$fastcgi_script_name;        # include Fastcgi_params; #} # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one # #l        ocation ~/\.ht {# deny all;       #}} # Another virtual host using mix of ip-, name-, and port-based configuration # #server {# listen    8000;    # Listen somename:8080;    # server_name somename alias Another.alias;    # location/{# root HTML;    # index index.html index.htm;    #} #} # HTTPS Server # #server {# listen 443 SSL;    # server_name localhost;    # ssl_certificate Cert.pem; # ssl_certifIcate_key Cert.key;    # Ssl_session_cache shared:ssl:1m;    # ssl_session_timeout 5m; # ssl_ciphers high:!anull:!    MD5;    # ssl_prefer_server_ciphers on;    # location/{# root HTML;    # index index.html index.htm; #    }    #}}

There are a few things to note about the configuration file:

1, worker_processes is specified as 4, indicating that there are 4 worker processes, this value is generally consistent with the number of CPU cores of the server. After the Nginx service is started through the start Nginx, the process can be seen by the task Manager to see the number of nginx processes.

One of them is the daemon, and 4 is the working process. If you specify Worker_processes as 1, there will be two nginx.exe processes (one daemon, 1 worker processes).

2, worker_connections specifies that 1024 is the default maximum number of connections. You can specify a larger number of connections, but it depends on the configuration of the Nginx server.

3, keepalive_timeout the specified 65s is the time-out for maintaining the connection.

4, through the Server-location-proxy_pass, and set the Cluster_server cluster binding.

5, through the upstream node configuration cluster_server. The two servers on the inside point to two different server, and the probability of accessing the two servers is set by weight (weight).

6. Under Server-location Index, add index.aspx to support access to the ASP.

We then developed an ASPX page for the demo.

protected void Page_Load (object sender, EventArgs e) {this.    Label0.text = "Request Start time:" + DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss"); This. Label1.Text = "Server name:" + base.    Server.machinename; This. Label2.Text = "Server IP Address:" + base.    request.servervariables["Local_addr"]; This. Label3.text = "HTTP Access port:" + base.    request.servervariables["Server_port"]; This. Label4.text = string. Concat (new object[] {". NET Interpretation engine version:. NET CLR ", Environment.Version.Major,". ", Environment.Version.Minor,". ", Environment.Version.Build,". ",    Environment.Version.Revision}); This.    Label5.text = "Server OS version:" + Environment.OSVersion.ToString (); This. Label6.text = "Server IIS version:" + base.    request.servervariables["Server_software"]; This. Label7.text = "Server domain name:" + base.    request.servervariables["SERVER_NAME"]; This. Label8.text = "Absolute path to Virtual directory:" + base.    request.servervariables["Appl_rhysical_path"]; This. Label9.text = "Absolute path to execute file:" + base.    request.servervariables["path_translated"]; This. Label10.text = "Virtual Directory session TotalNumber: "+ this.    Session.Contents.Count.ToString (); This. Label11.text = "Total number of virtual directory application:" + base.    Application.Contents.Count.ToString (); This. Label12.text = "Domain Host:" + base.    request.servervariables["Http_host"]; This. Label13.text = "Server area language:" + base.    request.servervariables["Http_accept_language"]; This. Label14.text = "User information:" + base.    request.servervariables["Http_user_agent"]; This.    Label14.text = "Number of CPUs:" + environment.getenvironmentvariable ("number_of_processors"); This.    Label15.text = "CPU type:" + environment.getenvironmentvariable ("Processor_identifier"); This. Label16.text = "Request Source Address:" + base. request.headers["X-real-ip"];}

It is then published to multiple servers in IIS, such as the 10.77.137.120:9000 and 10.77.137.11:8081 two addresses configured above. We visited the 8083 port we listened to, the address is: http://10.77.137.120:8083/, you can see the following page.

A few more refreshes, you can see the new address information:

Load balancing is implemented as above.

Configuring Nginx for WINDOWS/IIS Application load Balancing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.