zoukankan      html  css  js  c++  java
  • 使用Nginx负载均衡搭建高性能.NETweb应用程序二

    在文章《使用Nginx负载均衡搭建高性能.NETweb应用程序一》中,让我们对Nginx有了一个初步认识,下面我们将在windows平台下面使用Nginx演示集群部署我们的web应用。


    一、下载Nginx部署包

    到Nginx官网去下载一个windows平台下面的Nginx部署包,目前我下载的是一个nginx-1.6.2版本的。


    二、命令启动服务
    启动:start nginx.exe
    停止:nginx -s stop

    重新加载: nginx -s reload


    三、实例搭建
    首 选:我们要在我们的iis上面把我们做好的web应用部署上去,部署到不同的机器上面,设置好对应的ip和端口号,因为我在本机模拟出效果,所以我就在本 机的iis上面部署了2个web应用,第一个web应用部署在localhost:8011端口,第二个应用部署为localhost:8012端口,同 时为了看到演示效果,我们把里面的WebForm1.aspx页面做了一个标记,里面标记为:第几个web应用程序的页面,实际我们部署系统,不需要这样 做,就是把我们的一个web应用部署到不同机器上面的服务器上,下面所示。

    web应用1地址:http://localhost:8011/WebForm1.aspx
    web应用2地址:http://localhost:8012/WebForm1.aspx

    (1)启动Nginx服务

    (2)修改Nginx配置项,具体配置说明,我们在参数设置部门说明,然后验证服务是否正常启动。

    (3)访问地址http://localhost:8010/WebForm1.aspx观察结果

     


    (4)这样我们就可以模拟出负载均衡效果了,ok

    四、其他说明

    (1)配置域名访问:首先我们要在Nginx中添加域名设置,其次我们要在本机设置127.0.0.1映射为域名

    这样我们就可以这样访问了:http://huangxiang:8010/WebForm1.aspx

    (2)配置Ngnix启动的进程数量,我们可以在进程中关注其进程数量变化


    五、参数设置

    [javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
      1. #定义Nginx运行的用户和用户组  
      2. #user  nobody;  
      3. #Nginx进程数,建议和cpu总内核一致  
      4. worker_processes  2;  
      5.  
      6. #error_log  logs/error.log;  
      7. #error_log  logs/error.log  notice;  
      8. #error_log  logs/error.log  info;  
      9.  
      10. #pid        logs/nginx.pid;  
      11.   
      12.   
      13. events {  
      14. #定义单个进程的最大连接数(实际最大连接数要除以2)  
      15.     worker_connections  1024;  
      16. }  
      17.  
      18. #定义http服务器  
      19. http {  
      20.     include       mime.types;#定义文件扩展名和文件类型映射表  
      21.     default_type  application/octet-stream;  
      22.  
      23.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
      24.     #                  '$status $body_bytes_sent "$http_referer" '  
      25.     #                  '"$http_user_agent" "$http_x_forwarded_for"';  
      26.  
      27.     #access_log  logs/access.log  main;  
      28.   
      29.     sendfile        on;  
      30.     #tcp_nopush     on;  
      31.  
      32.     #keepalive_timeout  0;  
      33.     keepalive_timeout  65;  
      34.  
      35.     #gzip  on;  
      36.  
      37.  
      38.    #服务器的集群  
      39.     upstream  huangxiang.com {  #服务器集群名字  
      40.         #server   172.16.21.13:8081 weight=1;#服务器配置   weight是权重的意思,权重越大,分配的概率越大。  
      41.         #server   192.168.1.186:8081 weight=1;  
      42.         #server   172.16.1.14:8081 weight=2;  
      43.         #server   172.16.1.15:8081 weight=1;  
      44.         #server   172.16.1.15:80 weight=1;        
      45.         server    127.0.0.1:8011 weight=1;  
      46.         server    127.0.0.1:8012 weight=2;  
      47.     }     
      48. #虚拟机主机配置  
      49.     server {  
      50.         listen       8010;#端口号  
      51.         server_name  localhost huangxiang.com;#域名可以有多个,多个用空格分开  
      52.  
      53.         #charset koi8-r;  
      54.  
      55.         #access_log  logs/host.access.log  main;  
      56.  
      57.         #location / {  
      58.         #    root   html;  
      59.         #    index  index.html index.htm;  
      60.         #}  
      61.     location / {  
      62.             proxy_pass http://huangxiang.com;  
      63.             proxy_redirect default;  
      64.         }  
      65.  
      66.  
      67.         #error_page  404              /404.html;  
      68.  
      69.         # redirect server error pages to the static page /50x.html  
      70.         #  
      71.         error_page   500 502 503 504  /50x.html;  
      72.         location = /50x.html {  
      73.             root   html;  
      74.         }  
      75.  
      76.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
      77.         #  
      78.         #location ~ .php$ {  
      79.         #    proxy_pass   http://127.0.0.1;  
      80.         #}  
      81.  
      82.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
      83.         #  
      84.         #location ~ .php$ {  
      85.         #    root           html;  
      86.         #    fastcgi_pass   127.0.0.1:9000;  
      87.         #    fastcgi_index  index.php;  
      88.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
      89.         #    include        fastcgi_params;  
      90.         #}  
      91.  
      92.         # deny access to .htaccess files, if Apache's document root  
      93.         # concurs with nginx's one  
      94.         #  
      95.         #location ~ /.ht {  
      96.         #    deny  all;  
      97.         #}  
      98.     }  
      99.  
      100.  
      101.     # another virtual host using mix of IP-, name-, and port-based configuration  
      102.     #  
      103.     #server {  
      104.     #    listen       8000;  
      105.     #    listen       somename:8080;  
      106.     #    server_name  somename  alias  another.alias;  
      107.  
      108.     #    location / {  
      109.     #        root   html;  
      110.     #        index  index.html index.htm;  
      111.     #    }  
      112.     #}  
      113.  
      114.  
      115.     # HTTPS server  
      116.     #  
      117.     #server {  
      118.     #    listen       443 ssl;  
      119.     #    server_name  localhost;  
      120.  
      121.     #    ssl_certificate      cert.pem;  
      122.     #    ssl_certificate_key  cert.key;  
      123.  
      124.     #    ssl_session_cache    shared:SSL:1m;  
      125.     #    ssl_session_timeout  5m;  
      126.  
      127.     #    ssl_ciphers  HIGH:!aNULL:!MD5;  
      128.     #    ssl_prefer_server_ciphers  on;  
      129.  
      130.     #    location / {  
      131.     #        root   html;  
      132.     #        index  index.html index.htm;  
      133.     #    }  
      134.     #}  
      135.   
  • 相关阅读:
    js实现快速排序
    使用NodeList
    变量提升问题
    使用Location对象查询字符串参数
    一天一小段js代码(no.2)
    一天一小段js代码(no.1)
    JS闭包中的this对象
    JS数组去重
    FreeCodeCamp----Intermediate Algorithm Scripting解法
    关于表单验证
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/5835525.html
Copyright © 2011-2022 走看看