Under the .net platform, there are two ways of load balancing that I have deployed so far (iis7 and Nginx). The following uses Nginx as an example to explain the load balancing of the web layer.
The first part WEB layer load balancing
Introduction: Nginx surpasses Apache’s high performance and stability, making Nginx used as a Web server in China
There are also more and more websites on the server, including Sina Blog, Sina Podcast, Netease News and other portal channels, Liujianfang, 56.com, etc., video sharing websites, Discuz! Official Forum, Shuimushe
District and other well-known forums, emerging Web 2.0 websites such as Douban, YUPOO photo album, domestic SNS, and Thunder Online.
It is said that Nginx can withstand 30,000 concurrent connections. This point has not been tested. In short, Nginx is famous for its high concurrency.
Nginx is also a good choice for front-end load balancing, and it has nothing to do with the specific language. The following is how Nginx distributes to IIS
Simple process: user visits website (server C) -> server C (no IIS required)
Nginx distributes requests to ->A or B or more servers (specific IIS servers) to achieve front-end load
The configuration is very simple, as follows:
1. Download Nginx
Windows version, just search online. After downloading, unzip it and place it in the C: or D: directory of the C server (192.168.0.3), for example (c:\nginx)
2. Copy the asp.net site to server A (192.168.0.1), server B (192.168.0.2), and establish the corresponding iis,
The port is self-determined, for example (81)
Make sure that the pages of server A and server B are exactly the same, and that web.config needs to configure the same machineKey, otherwise an exception will be reported.
<machineKey validation="3DES"
validatiOnKey=”319B474B1D2B7A87C996B280450BB36506A95AEDF9B51211″
decryptiOnKey=”280450BB36319B474C996B506A95AEDF9B51211B1D2B7A87″
decryption=”3DES”/>
3. Configure the nginx configuration file of the C server (front-end load forwarding server) nginx.conf
The following red ones need to be configured. Among them, ip_hash is very important (it can ensure that each visitor can fix a backend and ensure that the session will not cause problems)
#user nobody;
worker_processes 1;
#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;
the
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream mytest.oa.com
{
ip_hash;
server 192.168.0.1:81;
server 192.168.0.2:81;
}
server {
listen 80;
“ server_name`
www.server110.com;
#charset koi8-r;
#access_log
logs/host.access.log main;
location / {
proxy_pass http://www.server110.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;
# server_name
localhost;
#
ssl
on;
#
ssl_certificate cert.pem;
# ssl_certificate_key
cert.key;
# ssl_session_timeout
5m;
# ssl_protocols SSLv2
SSLv3 TLSv1;
# ssl_ciphers
ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#
ssl_prefer_server_ciphers on;
# location / {
#
root html;
#
index index.html index.htm;
# }
#}
}
5. After the configuration is complete,
Enter the ngnix directory through the command line and run ngnix.exe to start ngnix. (Please make sure that no other iis or apache occupies port 80)
6. The command to close ngnix is: ngnix -s stop.