亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

.Net Core + Nginx實(shí)現(xiàn)項(xiàng)目負(fù)載均衡的全步驟

 更新時(shí)間:2020年07月19日 11:19:01   作者:江北的博客、  
這篇文章主要給大家介紹了關(guān)于.Net Core + Nginx實(shí)現(xiàn)項(xiàng)目負(fù)載均衡的相關(guān)資料,文中通過示例代碼以及圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧

nginx大家如果沒用過那或多或少都應(yīng)該聽過,vue的部署、反向代理、負(fù)載均衡nginx都能幫你做到。

今天主要說一下nginx負(fù)載均衡我們的項(xiàng)目,如下圖所示,請(qǐng)求到達(dá)nginx,nginx再幫我們轉(zhuǎn)發(fā)。

首先使用Docker安裝nginx.

docker pull nginx:latest

運(yùn)行容器,將本地的8080端口映射到容器內(nèi)部的 80 端口.

docker run --name nginx -p 8080:80 -d nginx

查看nginx容器,如果有錯(cuò)請(qǐng)看日志.

瀏覽器中訪問一下

ok,到此我們的nginx就已安裝完成。

我們準(zhǔn)備好3個(gè)以上的webapi的項(xiàng)目并發(fā)布。

進(jìn)入nginx容器

Docker exec -it nginx bash

找到nginx.conf文件并作修改,nginx.conf分為http塊、events塊和server塊,此次主要在server塊中做更改.

此時(shí)在nginx容器里面使用vi或者vim沒有用,需要依次執(zhí)行如下兩條命令

apt-get update 
apt-get install vim

進(jìn)入文件內(nèi),末尾處指向了另一個(gè)文件,沒錯(cuò)這個(gè)文件里就是放server塊配置內(nèi)容

進(jìn)入etc/nginx/conf.d/default.conf文件中并做修改

upstream ServiceInstance{   #nginx默認(rèn)輪詢下面的服務(wù)實(shí)例
  server ***.**.***.***:9007; 
  server ***.**.***.***:9008; 
  server ***.**.***.***:9009;
} 
server { 
  listen    80; 
  server_name localhost; 
 
  #charset koi8-r; 
  #access_log /var/log/nginx/host.access.log main; 
 
  location / { 
    #root  /usr/share/nginx/html; 
    #index index.html index.htm;     #請(qǐng)求到達(dá)后會(huì)進(jìn)行轉(zhuǎn)發(fā)
    proxy_pass http://ServiceInstance; 
  } 
 
  #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  /usr/share/nginx/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; 
  #} 
}

完成之后重啟一下容器,如果有錯(cuò)誤請(qǐng)查看日志.

docker restart nginx

瀏覽器中調(diào)用一個(gè)接口查看

每一次都會(huì)輪詢不同的服務(wù)實(shí)例,負(fù)載均衡的預(yù)期就實(shí)現(xiàn)了!

我們也可以設(shè)置權(quán)重比例,weight值越大,請(qǐng)求到達(dá)此實(shí)例的次數(shù)就越多!

upstream ServiceInstance{ 
  #nginx默認(rèn)輪詢下面的服務(wù)實(shí)例
  server ***.**.***.***:9007 weight=1; 
  server ***.**.***.***:9008 weight=2; 
  server ***.**.***.***:9009 weight=3;
}

各位同學(xué)也可慢慢研究,nginx很強(qiáng)大的!😎

總結(jié)

到此這篇關(guān)于.Net Core + Nginx實(shí)現(xiàn)項(xiàng)目負(fù)載均衡的文章就介紹到這了,更多相關(guān).Net Core+Nginx項(xiàng)目負(fù)載均衡內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論