欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

nginx轉(zhuǎn)載到多個(gè)服務(wù)器實(shí)例代碼

 更新時(shí)間:2025年09月02日 10:11:14   作者:云宮小鋪  
本文主要介紹了nginx轉(zhuǎn)載到多個(gè)服務(wù)器實(shí)例代碼,通過修改nginx.conf文件實(shí)現(xiàn)前端路由轉(zhuǎn)發(fā)和后端服務(wù)器實(shí)例添加,具有一定的參考價(jià)值,感興趣的可以了解一下

一、安裝nginx

使用官方倉(cāng)庫(kù)安裝

sudo yum install epel-release
  • 安裝了EPEL倉(cāng)庫(kù)之后,可以通過yum來安裝Nginx
sudo yum install nginx -y
  • 啟動(dòng)Nginx
sudo systemctl start nginx
  • 設(shè)置Nginx開機(jī)啟動(dòng)
sudo systemctl enable nginx
  • 檢查Nginx狀態(tài)
sudo systemctl status nginx

二、更改代理配置

  • 在nginx配置文件中配置前段路由轉(zhuǎn)發(fā)

vim /etc/nginx/nginx.conf

server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

#添加代理的前端文件轉(zhuǎn)發(fā)
        location / {
        root /opt/soft/fs-fms-webapp;
        index index.html index.html;
        }
#添加前端的路由接口,可以通過瀏覽器的開發(fā)者模式網(wǎng)絡(luò)請(qǐng)求接口查看:/fsm-api/
        location /fms-api/ {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMORE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#請(qǐng)求轉(zhuǎn)發(fā)到部署后端代碼的服務(wù)器地址啟動(dòng)所占用的端口
        proxy_pass http://10.201.65.185:8080/;
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
  • 更改配置后要重新重載一遍nginx配置
sudo systemctl restart nginx

三、添加多個(gè)后端實(shí)例,也就是所謂的負(fù)載均衡

vim /etc/nginx/nginx.conf

#自定義一個(gè)函數(shù)組,存放多個(gè)服務(wù)器后端運(yùn)行
upstream fms{
        server 10.201.65.185:8080 weight=5;
        server 10.201.65.186:8080 weight=3;

        }
    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
        root /opt/soft/fs-fms-webapp;
        index index.html index.html;
        }
        location /fms-api/ {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMORE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#將代理的地址換成上面定義的函數(shù)組名
        proxy_pass http://fms/;
        }
        error_page 404 /404.html;
        location = /404.html {
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }

更改配置后要重新重載一遍nginx配置

sudo systemctl restart nginx

到此這篇關(guān)于nginx轉(zhuǎn)載到多個(gè)服務(wù)器實(shí)例代碼的文章就介紹到這了,更多相關(guān)nginx轉(zhuǎn)載到多個(gè)服務(wù)器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論