国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php框架 > 框架设计 > 使用Nginx负载均衡搭建高性能.NETweb应用程序二

使用Nginx负载均衡搭建高性能.NETweb应用程序二

来源:程序员人生   发布时间:2015-01-16 08:17:11 阅读次数:2973次

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


1、下载Nginx部署包

到Nginx官网去下载1个windows平台下面的Nginx部署包,目前我下载的是1个nginx⑴.6.2版本的。


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

重新加载: nginx -s reload


3、实例搭建
首选:我们要在我们的iis上面把我们做好的web利用部署上去,部署到不同的机器上面,设置好对应的ip和端口号,由于我在本机摹拟出效果,所以我就在本机的iis上脸部署了2个web利用,第1个web利用部署在localhost:8011端口,第2个利用部署为localhost:8012端口,同时为了看到演示效果,我们把里面的WebForm1.aspx页面做了1个标记,里面标记为:第几个web利用程序的页面,实际我们部署系统,不需要这样做,就是把我们的1个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

4、其他说明

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

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

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


5、参数设置

#定义Nginx运行的用户和用户组 #user nobody; #Nginx进程数,建议和cpu总内核1致 worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { #定义单个进程的最大连接数(实际最大连接数要除以2) worker_connections 1024; } #定义http服务器 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 huangxiang.com { #服务器集群名字 #server 172.16.21.13:8081 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的几率越大。 #server 192.168.1.186:8081 weight=1; #server 172.16.1.14:8081 weight=2; #server 172.16.1.15:8081 weight=1; #server 172.16.1.15:80 weight=1; server 127.0.0.1:8011 weight=1; server 127.0.0.1:8012 weight=2; } #虚拟机主机配置 server { listen 8010;#端口号 server_name localhost huangxiang.com;#域名可以有多个,多个用空格分开 #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} location / { proxy_pass http://huangxiang.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 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; # } #} }



生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生