Use Nginx load balancing to build high performance. Netweb Application Two

Source: Internet
Author: User
Tags to domain nginx load balancing

In the article, using Nginx load Balancing to build High-performance. Netweb application One, let's have a preliminary understanding of Nginx, and we'll use the Nginx demo cluster below the Windows platform to deploy our Web applications.


First, download Nginx deployment package

to Nginx website to download a Windows platform under the Nginx deployment package, I currently download a nginx-1.6.2 version of the.


Second, the command to start the service
Start: Start Nginx.exe
Stop: Nginx-s stop

Reload: Nginx-s Reload


Third, the example constructs
First choice: We need to deploy our Web application to the top of our IIS, deploy to different machines, set the corresponding IP and port number, because I simulate the effect on the native, so I have deployed 2 Web applications on the native IIS. The first Web application was deployed on the localhost:8011 port, the second application was deployed as a localhost:8012 port, and in order to see the demo, we made a tag inside the WebForm1.aspx page labeled: Page of the first few Web applications, we actually deploy the system, and we don't have to do that by deploying one of our Web applications to a server on a different machine, as shown below.

Web Application 1 Address: http://localhost:8011/WebForm1.aspx
Web application 2 Address: http://localhost:8012/WebForm1.aspx

(1) Start Nginx Service

(2) Modify the Nginx configuration items, specific configuration instructions, we set the department description in the parameters, and then verify that the service is starting normally.

(3) Access to address http://localhost:8010/WebForm1.aspx observation results


(4) So we can simulate the load balancing effect, OK

Iv. Other Notes

(1) Configure domain name access: First of all, we want to add the domain name setting in the Nginx, secondly we want to set the 127.0.0.1 map to domain name in the local

So we can access it like this: http://huangxiang:8010/WebForm1.aspx

(2) Configure the number of processes initiated by the Ngnix, we can focus on the process number of changes


Five, parameter setting

#定义Nginx运行的用户和用户组 #user Nobody;

#Nginx进程数, the recommendation and CPU total kernel consistent worker_processes 2;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;


#pid Logs/nginx.pid;

Events {#定义单个进程的最大连接数 (the actual maximum number of connections divided by 2) worker_connections 1024;}

    #定义http服务器 http {include mime.types; #定义文件扩展名和文件类型映射表 Default_type Application/octet-stream; #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sen

    T "$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 huangxiang.com {#服务器集群名字 #server 172.16.21.13:8081 weight=1; #服务器配置 weight is the meaning of weight, the greater the weight, the probability of distribution
		Bigger.
		#server 192.168.1.186:8081 weight=1;
		#server 172.16.1.14:8081 weight=2; #server 172.16.1.15:8081Weight=1;		
		#server 172.16.1.15:80 weight=1;
		Server 127.0.0.1:8011 weight=1;
	Server 127.0.0.1:8012 weight=2;

        #虚拟机主机配置 server {Listen 8010; #端口号 server_name localhost huangxiang.com; #域名可以有多个, multiple spaces separated

        #charset Koi8-r;

        #access_log Logs/host.access.log Main;
        #location/{# root HTML;
        # index index.html index.htm;
            #} location/{Proxy_pass http://huangxiang.com;
        Proxy_redirect default;

        } #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$ {#
        Proxy_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 #
        #location ~/\.ht {# deny all; #}} # Another virtual host using mix of ip-, name-, and port-based configuration # #server {# l
    Isten 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;
 #    }
    #}

}



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.