第七节:Nginx限流和负载均衡、页面cdn、IIS部署优化、后续计划
一. Nginx限流和负载均衡
1. 限流
可以ip限流或者限制总请求数。防止大量恶意请求,通过nginx的ip限制处理 1秒1个ip只能请求一次,但也有弊端,比如多个人在同一个ip下,容易误杀,所以看怎么取舍了.
参考代码:
#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;
#limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#limit_req zone=one burst=5 nodelay;
limit_conn addr 1;
root html;
index index.html index.htm;
}
#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;
# }
#}
}
参考文章:https://cloud.tencent.com/developer/article/1404137
http://nginx.org/en/docs/http/ngx_http_limit_req_module.html
http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html
2. 负载均衡
参考:https://www.cnblogs.com/yaopengfei/p/12499588.html
在后续微服务章节中详细剖析测试。
二. 页面cdn 、IIS部署
采用前后端分离的模式,前端页面可以单独部署cdn,或者一些秒伤详情页面可以做成纯静态页面,放到SSD硬盘上,从而减少了DB查询。
该模块都在后续的微服务章节进行详细剖析和测试。
三. 后续计划
单体架构下,主要是围绕下单业务,提供了一些思路,一些常规业务并没有实现,在后续的微服务章节,会完善常规业务。
微服务架构涉及到的组件比较多,接下来一段时间将逐渐完善微服务的搭建,选择最适合的框架组装方式,不单单局限于.Net,组合测试到一定程度,回来完善微服务模块的博客。
!
- 作 者 : Yaopengfei(姚鹏飞)
- 博客地址 : http://www.cnblogs.com/yaopengfei/
- 声 明1 : 如有错误,欢迎讨论,请勿谩骂^_^。
- 声 明2 : 原创博客请在转载时保留原文链接或在文章开头加上本人博客地址,否则保留追究法律责任的权利。