• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-23) 22次浏览 已收录 0个评论

在文章《使用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启动的进程数量,我们可以在进程中关注其进程数量变化


五、参数设置

#定义Nginx运行的用户和用户组#user  nobody;#Nginx进程数,建议和cpu总内核一致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   ht
!本文来源gaodai.ma#com搞##代!^码网(
搞gaodaima代码ml; } # 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; # } #}}

以上就介绍了使用Nginx负载均衡搭建高性能.NETweb应用程序二,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:使用Nginx负载均衡搭建高性能.NETweb应用程序二

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址