Nginx四層負載均衡的實現示例
1、Nginx四層負載均衡
1.1 負載均衡概述
負載均衡是一種分布式計算技術,用于將網絡流量和用戶請求分散到多臺服務器上,以此來提高網絡服務的可用性和可靠性。它通過優(yōu)化資源使用、最大化吞吐量以及最小化響應時間,增強了網絡、服務器和數據中心的伸縮性和靈活性。
Nginx的負載均衡功能主要通過其反向代理模式實現。當客戶端發(fā)送請求到Nginx服務器時,Nginx會根據預設的負載均衡策略將請求轉發(fā)給后端服務器,并將后端服務器的響應返回給客戶端。Nginx作為代理服務器,有效地分攤了請求壓力,提高了系統(tǒng)的處理能力。
1.2 負載均衡的目的
提高可用性:通過將請求分散到多個服務器,即使部分服務器出現故障,整個系統(tǒng)仍然可以繼續(xù)提供服務。
增強性能:負載均衡可以提高系統(tǒng)處理大量并發(fā)請求的能力,從而提升整體性能。
故障轉移:當一臺服務器發(fā)生故障時,負載均衡器可以自動將流量轉移到其他健康的服務器上,以避免服務中斷。
降低延遲:通過選擇最佳的服務器來處理請求,減少數據傳輸的延遲。
資源優(yōu)化:合理分配請求到各個服務器,避免某些服務器過載而其他服務器空閑,優(yōu)化資源使用。
1.3 Nginx的負載均衡調度算法
1.3.1 輪詢(Round Robin)
輪詢是最簡單的負載均衡算法,它將請求按順序分發(fā)到每個服務器。當一個請求被發(fā)送到一個服務器后,下一個請求將被發(fā)送到列表中的下一個服務器。這種方法簡單易行使用,但可能不適合所有場景,特別是當某些服務器的處理能力不同時。
1.3.2 最少連接(Least Connections)
最少的連接算法將請求發(fā)送到當前連接數最少的服務器。這種方法可以更有效地利用服務器資源,因為它完全避免過載服務器。然而,這種方法可能會導致負載不均衡,特別是在服務器性能差異方面更大的情況發(fā)生。
1.3.3 IP哈希(IP Hash)
IP哈希算法根據客戶端的IP地址哈希值將請求發(fā)送到服務器。該方法可以保證來自相同客戶端的這種請求總是被發(fā)送到相同服務器,這對于需要會話保持的應用程序很有用。該方法可能會導致負載不均衡,特別是在服務器數量變化時。
1.3.4 加權輪詢(Weighted Round Robin)
加權輪詢是輪詢算法的一個變體,它允許為每個服務器分配重權。權重損失的服務器將接收到更多的請求。這種方法可以根據服務器的性能和負載情況動態(tài)調整負載分配。
1.3.5 加權最少連接(Weighted Least Connections)
加權最小連接算法結合了最小連接和加權輪詢的概念。它根據服務器的權重和當前連接數來選擇服務器,以實現更平衡的負載分配。
1.3.6 哈希(Hash)
哈希算法根據請求的某些屬性(如 URL 或請求頭)來選擇服務器。這種方法可以保證相同的請求總是被發(fā)送到相同的服務器,但需要注意的是,如果服務器數量發(fā)生變化,可能會導致負載不均衡。
1.4 Nginx四層負載均衡基本配置
| 主機 | IPV4地址 | 版本 |
|---|---|---|
proxy (代理) | 192.168.110.31/24 | Rocky-Linux 8 |
web-01 (主機-01) | 192.168.110.32/24 | Rocky-Linux 8 |
web-02 (主機-02) | 192.168.110.33/24 | Rocky-Linux 8 |
web-03 (主機-03) | 192.168.110.34/24 | Rocky-Linux 8 |
client (客戶端) | 192.168.110.35/24 | Rocky-Linux 8 |
1.4.1 后端主機配置
1.4.1.1 web-01配置
[root@web-01 ~]# mkdir -p /nginx/web
[root@web-01 ~]# echo "This is `hostname` IP=`hostname -I`" >> /nginx/web/index.html
[root@web-01 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.32:80;
root /nginx/web;
?
location /{
index index.html;
}
}
?
[root@web-01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-01 ~]# nginx -s reload
[root@web-01 ~]# curl 192.168.110.32
This is web-01 IP=192.168.110.321.4.1.2 web-02配置
[root@web-02 ~]# mkdir -p /nginx/web
[root@web-02 ~]# echo "This is `hostname` IP=`hostname -I`" >> /nginx/web/index.html
[root@web-02 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.33:80;
root /nginx/web;
?
location /{
index index.html;
}
}
?
[root@web-02 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-02 ~]# nginx -s reload
[root@web-02 web]# curl 192.168.110.33
This is web-02 IP=192.168.110.331.4.1.3 web-03配置
[root@web-03 ~]# mkdir -p /nginx/web
[root@web-03 ~]# echo "This is `hostname` IP=`hostname -I`" >> /nginx/web/index.html
[root@web-03 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.34:80;
root /nginx/web;
?
location /{
index index.html;
}
}
?
[root@web-03 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-03 ~]# nginx -s reload
[root@web-03 ~]# curl 192.168.110.34:80
This is web-03 IP=192.168.110.341.4.2 代理服務器配置
[root@proxy ~]# vim /etc/nginx/conf.d/proxy.conf
upstream wwwPools {
server 192.168.110.32;
server 192.168.110.33;
server 192.168.110.34;
}
?
server {
location / {
proxy_pass http://wwwPools;
}
}
?
[root@proxy ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@proxy ~]# nginx -s reload1.4.3 客戶端端訪問測試
[root@client ~]# for ((i=1;i<=9;i++)); do curl http://www.proxy.com; done #默認算法為RR This is web-01 IP=192.168.110.32 This is web-02 IP=192.168.110.33 This is web-03 IP=192.168.110.34 This is web-01 IP=192.168.110.32 This is web-02 IP=192.168.110.33 This is web-03 IP=192.168.110.34 This is web-01 IP=192.168.110.32 This is web-02 IP=192.168.110.33 This is web-03 IP=192.168.110.34
1.4.4 upstream模塊參數解釋
| 參數 | 說明 |
|---|---|
| server | 定義后端服務器的IP地址或域名,可選地指定端口號,默認為80端口。 |
| weight | 服務器權重,默認為1。權重越高,處理的請求比例越大。 |
| max fails | Nginx嘗試連接后端服務器失敗的次數,默認為1。超過此次數,Nginx將服務器標記為失敗。 |
| fail timeout | 在max fails定義的失敗次數后,距離下次檢查的間隔時間,默認為10秒。 |
| backup | 熱備配置,僅當所有激活的服務器失敗后,請求才會被轉發(fā)到標記為backup的服務器。 |
| down | 標記服務器永遠不可用,通常用于維護或測試。配合ip_hash使用時,服務器不能被標記為down。 |
1.4.5 增加權重
[root@proxy ~]# vim /etc/nginx/conf.d/proxy.conf
upstream wwwPools {
server 192.168.110.32 weight=1;
server 192.168.110.33 weight=2;
server 192.168.110.34 weight=3 down;
}
?
server {
location / {
proxy_pass http://wwwPools;
}
}
?
[root@proxy ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@proxy ~]# nginx -s reload
?
訪問測試
[root@client ~]# for ((i=1;i<=9;i++)); do curl http://www.proxy.com; done #web-01和web-02為2:1 ,web-03處于維護中
This is web-02 IP=192.168.110.33
This is web-01 IP=192.168.110.32
This is web-02 IP=192.168.110.33
This is web-02 IP=192.168.110.33
This is web-01 IP=192.168.110.32
This is web-02 IP=192.168.110.33
This is web-02 IP=192.168.110.33
This is web-01 IP=192.168.110.32
This is web-02 IP=192.168.110.331.5 多臺虛擬主機之間基于端口實現負載均衡
1.5.1 后端主機配置
1.5.1.1 web-01配置
[root@web-01 ~]# echo "This is `hostname` IP:`hostname -I` port=80" >> /nginx/web/index80.html
[root@web-01 ~]# echo "This is `hostname` IP:`hostname -I` port=81" >> /nginx/web/index81.html
[root@web-01 ~]# echo "This is `hostname` IP:`hostname -I` port=82" >> /nginx/web/index82.html
[root@web-01 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.32:80;
root /nginx/web;
?
location /{
index index80.html;
}
}
?
server {
listen 192.168.110.32:81;
root /nginx/web;
?
location /{
index index81.html;
}
}
?
server {
listen 192.168.110.32:82;
root /nginx/web;
?
location /{
index index82.html;
}
}
?
[root@web-01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-01 ~]# nginx -s reload
[root@web-01 ~]# curl 192.168.110.32:80
This is web-01 IP:192.168.110.32 port=80
[root@web-01 ~]# curl 192.168.110.32:81
This is web-01 IP:192.168.110.32 port=81
[root@web-01 ~]# curl 192.168.110.32:82
This is web-01 IP:192.168.110.32 port=821.5.1.2 web-02配置
[root@web-02 web]# echo "This is `hostname` IP:`hostname -I` port=80" >> /nginx/web/index80.html
[root@web-02 web]# echo "This is `hostname` IP:`hostname -I` port=81" >> /nginx/web/index81.html
[root@web-02 web]# echo "This is `hostname` IP:`hostname -I` port=82" >> /nginx/web/index82.html
[root@web-02 web]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.33:80;
root /nginx/web;
?
location / {
index index80.html;
}
}
?
server {
listen 192.168.110.33:81;
root /nginx/web;
?
location / {
index index81.html;
}
}
?
server {
listen 192.168.110.33:82;
root /nginx/web;
?
location / {
index index82.html;
}
}
?
?
[root@web-02 web]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-02 web]# nginx -s reload
[root@web-02 ~]# curl 192.168.110.33:80
This is web-02 IP:192.168.110.33 port=80
[root@web-02 ~]# curl 192.168.110.33:81
This is web-02 IP:192.168.110.33 port=81
[root@web-02 ~]# curl 192.168.110.33:82
This is web-02 IP:192.168.110.33 port=821.5.1.3 web-03配置
[root@web-03 ~]# echo "This is `hostname` IP:`hostname -I` port=80" >> /nginx/web/index80.html
[root@web-03 ~]# echo "This is `hostname` IP:`hostname -I` port=81" >> /nginx/web/index81.html
[root@web-03 ~]# echo "This is `hostname` IP:`hostname -I` port=82" >> /nginx/web/index82.html
[root@web-03 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.34:80;
root /nginx/web;
?
location / {
index index80.html;
}
}
?
server {
listen 192.168.110.34:81;
root /nginx/web;
?
location / {
index index81.html;
}
}
?
server {
listen 192.168.110.34:82;
root /nginx/web;
?
location / {
index index82.html;
}
}
?
[root@web-03 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-03 ~]# nginx -s reload
[root@web-03 ~]# curl 192.168.110.34:80
This is web-03 IP:192.168.110.34 port=80
[root@web-03 ~]# curl 192.168.110.34:81
This is web-03 IP:192.168.110.34 port=81
[root@web-03 ~]# curl 192.168.110.34:82
This is web-03 IP:192.168.110.34 port=821.5.2 代理服務器配置
[root@proxy ~]# vim /etc/nginx/conf.d/proxy.conf
upstream wwwPools {
server 192.168.110.32:80;
server 192.168.110.33:80;
server 192.168.110.34:80;
server 192.168.110.32:81;
server 192.168.110.33:81;
server 192.168.110.34:81;
server 192.168.110.32:82;
server 192.168.110.33:82;
server 192.168.110.34:82;
?
}
?
server {
location / {
proxy_pass http://wwwPools;
}
}
?
[root@proxy ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@proxy ~]# nginx -s reload1.5.3 客戶端訪問測試
[root@client ~]# for ((i=1;i<=12;i++)); do curl http://www.proxy.com; done This is web-01 IP:192.168.110.32 port=80 This is web-02 IP:192.168.110.33 port=80 This is web-03 IP:192.168.110.34 port=80 This is web-01 IP:192.168.110.32 port=81 This is web-02 IP:192.168.110.33 port=81 This is web-03 IP:192.168.110.34 port=81 This is web-01 IP:192.168.110.32 port=82 This is web-02 IP:192.168.110.33 port=82 This is web-03 IP:192.168.110.34 port=82 This is web-01 IP:192.168.110.32 port=80 This is web-02 IP:192.168.110.33 port=80 This is web-03 IP:192.168.110.34 port=80
1.6 反向代理多虛擬主機節(jié)點服務器
1.6.1 模塊主要參數
在 Nginx 的配置中使用 proxy_set_header 指令是為了在 Nginx 作為反向代理服務器時,向真實的后端服務器傳遞客戶端的原始信息。以下是對 proxy_set_header 指令的詳細解釋,以及它如何影響代理請求:
proxy_set_header host $host;
這條指令的作用是:
proxy_set_header:這是 Nginx 用來設置由代理服務器發(fā)送給后端服務器的 HTTP 請求頭的指令。host:這是 HTTP 請求頭中的一個字段,通常包含了客戶端請求的原始主機信息,如域名或 IP 地址。$host:這是 Nginx 變量,它代表客戶端請求中的Host頭部的值。
1.6.2 為什么需要 proxy_set_header host $host;
當 Nginx 作為反向代理時,它默認會將客戶端的請求轉發(fā)給配置好的后端服務器,但是在這個過程中,原始的
Host請求頭可能會丟失或被修改。這可能導致后端服務器無法正確識別客戶端請求的虛擬主機,尤其是在后端服務器配置了多個虛擬主機時。例如,如果客戶端發(fā)送了一個帶有
Host: www.yunjisuan.com的請求,但是 Nginx 在轉發(fā)請求時沒有保留這個Host頭部,后端服務器可能會默認提供一個它配置的第一個虛擬主機的響應,而不是客戶端請求的那個特定的虛擬主機。
1.6.3 配置示例
1.6.3.1 web-01配置
[root@web-01 ~]# mkdir -p /nginx/web-{1..3}
[root@web-01 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-1" >> /nginx/web-1/index.html
[root@web-01 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-2" >> /nginx/web-2/index.html
[root@web-01 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-3" >> /nginx/web-3/index.html
[root@web-01 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.32:80;
server_name www.web-01.com;
root /nginx/web-1;
?
location /{
index index.html;
}
}
?
server {
listen 192.168.110.32:80;
server_name www.web-02.com;
root /nginx/web-2;
?
location /{
index index.html;
}
}
?
server {
listen 192.168.110.32:80;
server_name www.web-03.com;
root /nginx/web-3;
?
location /{
index index.html;
}
}
?
[root@web-01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-01 ~]# nginx -s reload1.6.3.2 web-02配置
[root@web-02 ~]# mkdir -p /nginx/web-{1..3}
[root@web-02 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-1" >> /nginx/web-1/index.html
[root@web-02 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-2" >> /nginx/web-2/index.html
[root@web-02 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-3" >> /nginx/web-3/index.html
[root@web-02 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.33:80;
server_name www.web-01.com;
root /nginx/web-1;
?
location /{
index index.html;
}
}
?
server {
listen 192.168.110.33:80;
server_name www.web-02.com;
root /nginx/web-2;
?
location /{
index index.html;
}
}
?
server {
listen 192.168.110.33:80;
server_name www.web-03.com;
root /nginx/web-3;
?
location /{
index index.html;
}
}
?
[root@web-02 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-02 ~]# nginx -s reload1.6.3.3 web-03配置
[root@web-03 ~]# mkdir -p /nginx/web-{1..3}
[root@web-03 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-1" >> /nginx/web-1/index.html
[root@web-03 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-2" >> /nginx/web-2/index.html
[root@web-03 ~]# echo "This is `hostname` IP=`hostname -I` dir=/nginx/web-3" >> /nginx/web-3/index.html
[root@web-03 ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
listen 192.168.110.34:80;
server_name www.web-01.com;
root /nginx/web-1;
?
location /{
index index.html;
}
}
?
server {
listen 192.168.110.34:80;
server_name www.web-02.com;
root /nginx/web-2;
?
location /{
index index.html;
}
}
?
server {
listen 192.168.110.34:80;
server_name www.web-03.com;
root /nginx/web-3;
?
location /{
index index.html;
}
}
?
[root@web-03 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web-03 ~]# nginx -s reload1.6.3.4 代理服務器配置(不加proxy_set_header host $host;)
[root@proxy ~]# vim /etc/nginx/conf.d/proxy.conf
upstream wwwPools {
server 192.168.110.32:80;
server 192.168.110.33:80;
server 192.168.110.34:80;
}
?
server {
listen 80;
server_name www.web-01.com;
?
location / {
proxy_pass http://wwwPools;
}
}
?
server {
listen 80;
server_name www.web-02.com;
?
location / {
proxy_pass http://wwwPools;
}
}
?
server {
listen 80;
server_name www.web-03.com;
?
location / {
proxy_pass http://wwwPools;
}
}
?
[root@proxy ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@proxy ~]# nginx -s reload1.6.3.5 客戶端訪問
[root@client ~]# echo '192.168.110.31 www.web-01.com www.web-02.com www.web-03.com' >> /etc/hosts #添加hosts解析,ip為proxy的ip [root@client ~]# for ((i=1;i<=3;i++)); do curl http://www.web-01.com; done This is web-01 IP=192.168.110.32 dir=/nginx/web-1 This is web-02 IP=192.168.110.33 dir=/nginx/web-1 This is web-03 IP=192.168.110.34 dir=/nginx/web-1 [root@client ~]# for ((i=1;i<=3;i++)); do curl http://www.web-02.com; done This is web-01 IP=192.168.110.32 dir=/nginx/web-1 This is web-02 IP=192.168.110.33 dir=/nginx/web-1 This is web-03 IP=192.168.110.34 dir=/nginx/web-1 [root@client ~]# for ((i=1;i<=3;i++)); do curl http://www.web-03.com; done This is web-01 IP=192.168.110.32 dir=/nginx/web-1 This is web-02 IP=192.168.110.33 dir=/nginx/web-1 This is web-03 IP=192.168.110.34 dir=/nginx/web-1 ? 注:無論訪問那個域名,都是第一臺虛擬主機提供服務
注意:若后端有多臺虛擬主機如果不添加proxy_set_header host $host;的話代理服務器無法判斷代理的是哪個虛擬主機,所以不管訪問的是哪個域名返還的都是第一臺虛擬主機的內容
1.6.3.6 代理服務器配置包含proxy_set_header host $host;
[root@proxy ~]# vim /etc/nginx/conf.d/proxy.conf
upstream wwwPools {
server 192.168.110.32:80;
server 192.168.110.33:80;
server 192.168.110.34:80;
}
?
server {
listen 80;
server_name www.web-01.com;
?
location / {
proxy_pass http://wwwPools;
proxy_set_header host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
?
server {
listen 80;
server_name www.web-02.com;
?
location / {
proxy_pass http://wwwPools;
proxy_set_header host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
?
server {
listen 80;
server_name www.web-03.com;
?
location / {
proxy_pass http://wwwPools;
proxy_set_header host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
?
[root@proxy ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@proxy ~]# nginx -s reload| 指令 | 參數 | 說明 |
|---|---|---|
| proxy_set_header | host $host | 設置代理請求中的Host頭部,值為原始請求中的Host頭部。這確保了后端服務器能夠識別客戶端請求的虛擬主機。 |
| proxy_set_header | X-Forwarded-For $remote_addr | 設置代理請求中的X-Forwarded-For頭部,值為客戶端的IP地址。這個頭部用于記錄客戶端真實的IP地址,支持識別通過HTTP代理或負載均衡器發(fā)送的請求。 |
1.6.3.6 客戶端訪問
[root@client ~]# for ((i=1;i<=3;i++)); do curl http://www.web-01.com; done This is web-01 IP=192.168.110.32 dir=/nginx/web-1 This is web-02 IP=192.168.110.33 dir=/nginx/web-1 This is web-03 IP=192.168.110.34 dir=/nginx/web-1 [root@client ~]# for ((i=1;i<=3;i++)); do curl http://www.web-02.com; done This is web-01 IP=192.168.110.32 dir=/nginx/web-2 This is web-02 IP=192.168.110.33 dir=/nginx/web-2 This is web-03 IP=192.168.110.34 dir=/nginx/web-2 [root@client ~]# for ((i=1;i<=3;i++)); do curl http://www.web-03.com; done This is web-01 IP=192.168.110.32 dir=/nginx/web-3 This is web-02 IP=192.168.110.33 dir=/nginx/web-3 This is web-03 IP=192.168.110.34 dir=/nginx/web-3
1.6.3.7 查看訪問日志
[root@web-01 ~]# tail -3 /var/log/nginx/access.log 192.168.110.31 - - [21/Apr/2024:15:31:38 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" 192.168.110.31 - - [21/Apr/2024:15:31:39 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" 192.168.110.31 - - [21/Apr/2024:15:31:41 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" ? [root@web-02 ~]# tail -3 /var/log/nginx/access.log 192.168.110.31 - - [21/Apr/2024:15:31:38 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" 192.168.110.31 - - [21/Apr/2024:15:31:39 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" 192.168.110.31 - - [21/Apr/2024:15:31:41 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" ? [root@web-03 ~]# tail -3 /var/log/nginx/access.log 192.168.110.31 - - [21/Apr/2024:15:31:38 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" 192.168.110.31 - - [21/Apr/2024:15:31:39 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35" 192.168.110.31 - - [21/Apr/2024:15:31:41 +0800] "GET / HTTP/1.0" 200 52 "-" "curl/7.61.1" "192.168.110.35"
到此這篇關于Nginx四層負載均衡的實現示例的文章就介紹到這了,更多相關Nginx四層負載均衡內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
解決國內k8s的ingress-nginx鏡像無法正常pull拉取問題
本文主要介紹了解決國內k8s的ingress-nginx鏡像無法正常pull拉取問題,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-03-03
nginx+php出現No input file specified解決辦法
這篇文章主要介紹了nginx+php出現No input file specified解決辦法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-03-03
解決nginx:[emerg]?getpwnam(“nginx“)failed報錯問題
編譯安裝nginx時,啟動服務報錯nginx:[emerg]getpwnam("nginx")failed,原因是沒有為nginx創(chuàng)建用戶,解決方法是創(chuàng)建一個nginx用戶,該用戶是你在編譯時指定的用戶2025-02-02
Nginx中l(wèi)ocation匹配以及rewrite重寫跳轉詳解
訪問重寫 rewrite 是 Nginx HTTP 請求處理過程中的一個重要功能,下面這篇文章主要給大家介紹了Nginx中l(wèi)ocation匹配以及rewrite重寫跳轉的相關資料,需要的朋友可以參考下2022-03-03

