最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Nginx七層負(fù)載均衡的實(shí)現(xiàn)示例

 更新時(shí)間:2024年04月24日 08:52:49   作者:幸存者 · KXY  
七層負(fù)載均衡它是在應(yīng)用層,那么它可以完成很多應(yīng)用方面的協(xié)議請求,本文主要介紹了Nginx七層負(fù)載均衡的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下

七層負(fù)載均衡介紹

Nginx七層負(fù)載均衡是在應(yīng)用層(HTTP/HTTPS)上進(jìn)行的,可以根據(jù)HTTP請求的具體內(nèi)容,如URL、Cookie、Header等,來決定將請求轉(zhuǎn)發(fā)到哪個(gè)后端服務(wù)器。這種方式不僅能夠均衡服務(wù)器的計(jì)算負(fù)載,還能實(shí)現(xiàn)更復(fù)雜的路由策略,例如:

  • 會(huì)話粘性(Sticky Sessions):確保用戶的會(huì)話請求始終被定向到同一個(gè)后端服務(wù)器。

  • 基于內(nèi)容的路由:根據(jù)請求的內(nèi)容(如URL、頭部信息)將請求分發(fā)到不同的服務(wù)器。

四層與七層負(fù)載均衡的區(qū)別

1.1 四層負(fù)載均衡(Layer 4 Load Balancing)

  • 在傳輸層(Transport Layer)上進(jìn)行。

  • 關(guān)注網(wǎng)絡(luò)層面的信息,如源和目標(biāo)IP地址、端口號(hào)等。

  • 根據(jù)網(wǎng)絡(luò)信息決定將數(shù)據(jù)包轉(zhuǎn)發(fā)到哪個(gè)服務(wù)器。

  • 不深入檢查數(shù)據(jù)包的內(nèi)容。

  • 主要適用于基于TCP/UDP的流量,如HTTP和HTTPS。

1.2 七層負(fù)載均衡(Layer 7 Load Balancing)

  • 在應(yīng)用層(Application Layer)上進(jìn)行。

  • 深入檢查網(wǎng)絡(luò)流量的內(nèi)容,如HTTP請求頭、URL、Cookie等。

  • 根據(jù)流量內(nèi)容做復(fù)雜的路由決策。

  • 可以處理多種應(yīng)用層協(xié)議,不僅限于HTTP。

2 七層負(fù)載均衡配置

服務(wù)器類型IP地址發(fā)行版
代理服務(wù)器(proxy)192.168.110.31/24Rocky Linux 8
靜態(tài)地址服務(wù)器(static)192.168.110.32/24Rocky Linux 8
默認(rèn)地址服務(wù)器(default)192.168.110.33/24Rocky Linux 8
動(dòng)態(tài)地址服務(wù)器(upload)192.168.110.34/24Rocky Linux 8

2.1 后端節(jié)點(diǎn)配置

2.1.1 靜態(tài)地址服務(wù)器(static)

[root@static ~]# mkdir /nginx/static
[root@static ~]# echo "This is static page IP=`hostname -I`" >> /nginx/static/index.html
[root@static ~]# vim /etc/nginx/conf.d/VirtualHost.conf
server {
        listen 192.168.110.32:80;
        server_name www.nginx,com;
        root /nginx;
?
        location / {
                index index.html;
        }
}
?
[root@static ~]# nginx -s reload
[root@static ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@static ~]# curl 192.168.110.32/static/
This is static page IP=192.168.110.32

2.1.2 默認(rèn)地址服務(wù)器(default)

[root@default ~]# mkdir /nginx/default
[root@default ~]# echo "This is default page IP=`hostname -I`" >> /nginx/default/index.html
[root@default ~]# vim /etc/nginx/conf.d/VirtualHost.conf 
server {
        listen 192.168.110.33:80;
        server_name www.nginx,com;
        root /nginx/default;
?
        location / {
                index index.html;
        }
}
?
[root@default ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@default ~]# nginx -s reload
[root@default ~]# curl 192.168.110.33/default/
This is default page IP=192.168.110.33

2.1.3 動(dòng)態(tài)地址服務(wù)器(upload)

[root@upload ~]# mkdir /nginx/upload
[root@upload ~]# echo "This is upload page IP=`hostname -I`" >> /nginx/upload/index.html
[root@upload ~]# vim /etc/nginx/conf.d/VirtualHost.conf 
server {
        listen 192.168.110.34:80;
        server_name www.nginx,com;
        root /nginx;
?
        location / {
                index index.html;
        }
}
?
[root@upload ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@upload ~]# nginx -s reload
[root@upload ~]# curl 192.168.110.34/upload/
This is upload page IP=192.168.110.34

2.2 代理服務(wù)器配置

[root@proxy ~]# vim /etc/nginx/conf.d/proxy.conf
upstream static_pools {
        server 192.168.110.32;
}
?
upstream default_pools {
        server 192.168.110.33;
}
?
upstream upload_pools {
        server 192.168.110.34;
}
?
server {
        listen 80;
        server_name www.nginx.com;
?
        location /static {
                proxy_pass http://static_pools;
                proxy_set_header host $host;
                proxy_set_header X-Forwarded-For $remote_addr;
        }
?
        location /default {
                proxy_pass http://default_pools;
                proxy_set_header host $host;
                proxy_set_header X-Forwarded-For $remote_addr;
        }
?
        location /upload {
                proxy_pass http://upload_pools;
                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

注意:這里location的寫法,這里的主要難點(diǎn)就在這。例如:如果站點(diǎn)目錄寫 root /nginx/ststic; 那最后訪問 http://www.nginx.com/static/ 時(shí)轉(zhuǎn)發(fā)路徑就為http://www.nginx.com/static/static。所以寫/nginx就行了

2.3 客戶端測試訪問

[root@client ~]# echo '192.168.110.31 www.nginx.com' >> /etc/hosts
[root@client ~]# curl http://www.nginx.com
This is default page IP=192.168.110.33 
[root@client ~]# curl http://www.nginx.com/static/
This is static page IP=192.168.110.32 
[root@client ~]# curl http://www.nginx.com/upload/
This is upload page IP=192.168.110.34

2.4 查看各節(jié)點(diǎn)訪問日志

[root@static ~]# tail -1 /var/log/nginx/access.log
192.168.110.31 - - [21/Apr/2024:17:07:34 +0800] "GET /static/ HTTP/1.0" 200 39 "-" "curl/7.61.1" "192.168.110.35"
?
[root@default ~]# tail -1 /var/log/nginx/access.log
192.168.110.31 - - [21/Apr/2024:17:07:32 +0800] "GET / HTTP/1.0" 200 40 "-" "curl/7.61.1" "192.168.110.35"
?
[root@upload ~]# tail -1 /var/log/nginx/access.log
192.168.110.31 - - [21/Apr/2024:17:07:36 +0800] "GET /upload/ HTTP/1.0" 200 39 "-" "curl/7.61.1" "192.168.110.35"

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

相關(guān)文章

  • nginx出現(xiàn)500 Internal Server Error錯(cuò)誤的解決方法

    nginx出現(xiàn)500 Internal Server Error錯(cuò)誤的解決方法

    這篇文章主要介紹了nginx出現(xiàn)500 Internal Server Error錯(cuò)誤的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-09-09
  • Nginx的版本平滑升級(jí)和回退的實(shí)現(xiàn)

    Nginx的版本平滑升級(jí)和回退的實(shí)現(xiàn)

    有時(shí)候我們需要對Nginx版本進(jìn)行升級(jí)以滿足對其功能的需求,而此時(shí) Nginx又在跑著業(yè)務(wù)無法停掉,這時(shí)我們就可能選擇平滑升級(jí)平滑升級(jí),本文就來詳細(xì)的介紹一下Nginx的版本平滑升級(jí)和回退的實(shí)現(xiàn),感興趣的可以了解一下
    2026-05-05
  • Nginx 緩存清理的具體實(shí)現(xiàn)

    Nginx 緩存清理的具體實(shí)現(xiàn)

    Nginx通過緩存機(jī)制加速Web服務(wù),并提供高效的響應(yīng)和減少后端服務(wù)器負(fù)載,緩存數(shù)據(jù)需要定期清理以管理磁盤空間和確保數(shù)據(jù)時(shí)效性,下面就來介紹一下,感興趣的可以了解一下
    2024-12-12
  • nginx反向代理服務(wù)器及負(fù)載均衡服務(wù)配置方法

    nginx反向代理服務(wù)器及負(fù)載均衡服務(wù)配置方法

    正向代理一般是在客戶端設(shè)置代理服務(wù)器,通過代理服務(wù)器轉(zhuǎn)發(fā)請求,最終訪問到目標(biāo)服務(wù)器,這篇文章主要介紹了nginx反向代理服務(wù)器及負(fù)載均衡服務(wù)配置方法,需要的朋友可以參考下
    2023-12-12
  • nginx安裝第三方模塊的方法

    nginx安裝第三方模塊的方法

    這篇文章主要介紹了nginx安裝第三方模塊的方法,包含在未安裝nginx的情況下安裝nginx第三方模塊和在已安裝nginx情況下安裝nginx第三方模塊,需要的朋友可以參考下
    2014-06-06
  • nginx中指令root與alias舉例說明

    nginx中指令root與alias舉例說明

    在Nginx配置中,root和alias都是用于指定請求對應(yīng)的文件系統(tǒng)路徑的指令,但它們的工作方式有顯著區(qū)別,這篇文章主要介紹了nginx中指令root與alias的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-11-11
  • nginx中常見日志分析命令合集

    nginx中常見日志分析命令合集

    這篇文章主要為大家整理了一些nginx中常見日志分析命令,例如 查看實(shí)時(shí)日志,統(tǒng)計(jì)狀態(tài)碼分布,分析客戶端 IP等,有需要的小伙伴可以參考一下
    2025-05-05
  • Nginx代理Redis哨兵主從配置的實(shí)現(xiàn)

    Nginx代理Redis哨兵主從配置的實(shí)現(xiàn)

    本文主要介紹了Nginx代理Redis哨兵主從配置的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • nginx 偽靜態(tài)化rewrite規(guī)則

    nginx 偽靜態(tài)化rewrite規(guī)則

    用Nginx的朋友可以參考,加到nginx.conf相應(yīng)主機(jī)server段配置中即可!
    2009-10-10
  • 在Debian11上安裝Openresty服務(wù)(Nginx+Lua)的詳細(xì)教程

    在Debian11上安裝Openresty服務(wù)(Nginx+Lua)的詳細(xì)教程

    OpenResty 是一個(gè)基于 Nginx 與 Lua 的高性能 Web 平臺(tái),其內(nèi)部集成了大量精良的 Lua 庫、第三方模塊以及大多數(shù)的依賴項(xiàng),這篇文章主要介紹了在Debian11上安裝Openresty服務(wù)(Nginx+Lua)?,需要的朋友可以參考下
    2022-10-10

最新評(píng)論

多伦县| 剑阁县| 大方县| 托克托县| 永泰县| 泗水县| 湄潭县| 铜山县| 湾仔区| 祁连县| 扶余县| 仙桃市| 武隆县| 屏东县| 陵水| 临西县| 蚌埠市| 方城县| 浮梁县| 丰镇市| 来安县| 新巴尔虎左旗| 双流县| 仁布县| 玉田县| 常州市| 大化| 澄城县| 天峻县| 通渭县| 张家川| 綦江县| 连云港市| 乐东| 五指山市| 保靖县| 青冈县| 绥阳县| 普兰店市| 卓资县| 花垣县|