Nginx七层负载均衡配置
生活随笔
收集整理的這篇文章主要介紹了
Nginx七层负载均衡配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Nginx七層負載均衡
?
Nginx要實現七層負載均衡需要用到proxy_pass代理模塊配置。Nginx默認安裝支持這個模塊,我們不需要再做任何處理。Nginx的負載均衡是在Nginx的反向代理基礎上把用戶的請求根據指定的算法分發到一組【upstream虛擬服務池】。
Nginx七層負載均衡的指令
upstream指令
該指令是用來定義一組服務器,它們可以是監聽不同端口的服務器,并且也可以是同時監聽TCP和Unix socket的服務器。服務器可以指定不同的權重,默認為1。
| 默認值 | — |
| 位置 | http |
server指令
該指令用來指定后端服務器的名稱和一些參數,可以使用域名、IP、端口或者unix socket
| 默認值 | — |
| 位置 | upstream |
Nginx七層負載均衡的實現流程
服務端設置
server {listen 9001;server_name localhost;default_type text/html;location /{return 200 '<h1>192.168.200.146:9001</h1>';} } server {listen 9002;server_name localhost;default_type text/html;location /{return 200 '<h1>192.168.200.146:9002</h1>';} } server {listen 9003;server_name localhost;default_type text/html;location /{return 200 '<h1>192.168.200.146:9003</h1>';} }負載均衡器設置
upstream backend{server 192.168.200.146:9091;server 192.168.200.146:9092;server 192.168.200.146:9093; } server {listen 8083;server_name localhost;location /{proxy_pass http://backend;} }總結
以上是生活随笔為你收集整理的Nginx七层负载均衡配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx负载均衡状态介绍
- 下一篇: Nginx负载均衡实现之四层与七层负载