Home > Article > Backend Development > Use Nginx load balancing to build high-performance .NET web applications 2
In the article "Using Nginx Load Balancing to Build High-Performance .NET Web Applications 1", we have a preliminary understanding of Nginx. Next, we will use the Nginx demonstration cluster to deploy our web application under the windows platform.
Go to the Nginx official website to download an Nginx deployment package for the windows platform. Currently, I downloaded an nginx-1.6.2 version.
Reload: nginx -s reload
3. Example construction
First choice: We need to deploy our web application on our IIS, deploy it to different machines, and set the corresponding IP and port number. Because I simulate the effect on this machine, I Two web applications are deployed on the iis of this machine. The first web application is deployed on localhost: port 8011, and the second application is deployed on localhost: port 8012. At the same time, in order to see the demonstration effect, we put the WebForm1. The aspx page has a mark, which is marked as: The page of the web application. In fact, when we deploy the system, we don’t need to do this. We just deploy 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. For specific configuration instructions, we will explain them in the parameter setting department, and then verify whether the service starts normally.
(3) Access addresshttp://localhost:8010/WebForm1.aspxObservation results
(4) In this way we can simulate the load balancing effect, ok
4. Other instructions
(1) Configure domain name access: First we need to add domain name settings in Nginx, and secondly we need to set 127.0.0.1 to be mapped to the domain name on this machine
In this waywe can access it like this:http://huangxiang:8010/WebForm1.aspx
(2) Configure the number of processes started by Ngnix. We can pay attention to the changes in the number of processes during the process
5. Parameter settings
#定义Nginx运行的用户和用户组 #user nobody; #Nginx进程数,建议和cpu总内核一致 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 { #定义单个进程的最大连接数(实际最大连接数要除以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_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 huangxiang.com { #服务器集群名字 #server 172.16.21.13:8081 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。 #server 192.168.1.186:8081 weight=1; #server 172.16.1.14:8081 weight=2; #server 172.16.1.15:8081 weight=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;#域名可以有多个,多个用空格分开 #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 500 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 { # 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; # } #} }
The above introduces the use of Nginx load balancing to build high-performance .NET web applications II, including the content, I hope it will be helpful to friends who are interested in PHP tutorials.