第七節: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;
    #    }
    #}

}
View Code

 

參考文章: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 : 原創博客請在轉載時保留原文鏈接或在文章開頭加上本人博客地址,否則保留追究法律責任的權利。
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM