大型架构.net平台篇(WEB层均衡负载nginx)
第一部分 WEB层均衡负载
.net平台下,我目前部署过的均衡负载有两种方式(iis7和Nginx),以下以Nginx为例讲解web层的均衡负载.
简介:Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web
服务器的网站也越来越多,其中包括新浪博客、新浪播客、网易新闻等门户网站频道,六间房、56.com等,视频分享网站,Discuz!官方论坛、水木社
区等知名论坛,豆瓣、YUPOO相册、海内SNS、迅雷在线等新兴Web 2.0网站。
据说Nginx能承受3万并发连接数,这一点没有测试,总之Nginx是以高并发著名的。
Nginx 做前端的均衡负载也是相当不错的选择,而且和具体的语言无关,下面是Nginx 分发到IIS的方式
简单流程:用户访问网站(服务器C)->服务器C(不需要IIS) Nginx分发请求到->A或B或都更多的服务器(具体的IIS服务器), 实现前端负载
配置非常简单,方法如下:
1.下载Nginx windows版本,网上搜一下就行了.下载后解压放在C服务器(192.168.0.3)C:或D:目录下,例如(c:/nginx)
2. 把asp.net站点复制到A服务器(192.168.0.1),B服务器(192.168.0.2),并建立好相应的iis, 端口自已定, 例如(81)
确保A服务器和B服务器的页面是完全一样的,以及web.config需要配置machineKey一致,不然会报异常的。
<system.web>
<machineKey validation="3DES"
validationKey="319B474B1D2B7A87C996B280450BB36506A95AEDF9B51211"
decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A87"
decryption="3DES"/>
3. 配置C服务器(前端负载转发服务器)nginx的配置文件 nginx.conf
以下标红的就是需要配置的.其中ip_hash很重要(可以保证每个访客可以固定一个后端,保证session不会出问题)
#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;
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 mytest.oa.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://mytest.oa.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. 配置完成后, 通过命令行进入ngnix目录,运行ngnix.exe,即启动ngnix。(请确保没有其它iis或apache占用80端口)
6.关闭ngnix命令为:ngnix -s stop.
相关文章
- 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到Ubuntu 16.04
- C#.Net实体代码生成工具(EntitysCodeGenerate)的使用及.NET中的ORM实现
- .Net Core使用NLog记录日志到文件和数据库实战演练
- .NET Core开源Quartz.Net作业调度框架实战演练
- .NET开源Protobuf-net组件修炼手册
- mvc.net分页查询案例——实体层(HouseModel.cs)
- ASP.NET生成验证码
- Asp.Net Web API 2第十七课——Creating an OData Endpoint in ASP.NET Web API 2(OData终结点)
- Asp.Net Web API 2第十三课——ASP.NET Web API中的JSON和XML序列化
- ASP.NET MVC3 301永久重定向实现程序
- 重新整理 .net core 实践篇—————微服务的桥梁EventBus[三十一]
- .NET中异常处理的最佳实践(译)
- 《ASP.NET Core 3框架揭秘》勘误[逐步完善中…]
- 如果没有Visual Studio 2015,我们如何创建.NET Core项目 ?
- [ASP.NET MVC] 利用自定义的AuthenticationFilter实现Basic认证
- 【原创】开源Math.NET基础数学类库使用(11)C#计算相关系数
- VBUC:VB6 代码转换为 C# 和 VB.NET
- Extreme Optimization Numerical Libraries for .NET 8.0
- NET:Spire.XLS 12.11.3 supports a variety of new formulas
- ASP.NET Core微服务(六)——【.Net Core操作redis】StackExchange.Redis
- .Net——使用.net内置处理程序处理自己定义节点Demo
- [C#.NET 拾遗补漏]10:理解 volatile 关键字
- 【.Net实用方法总结】 整理并总结.NET 中的 System.IO.Pipelines(管道)
- ASP.NET MVC 开发模式(下)基础完结篇