Nginx監聽多個端口配置實例 Linux


開發者門戶UI的訪問和調用的nginx配置如下(需修改的配置文件默認在${nginxInstallPath}/conf/nginx.conf):

server {

        listen   8010;  #端口

        server_name portal; #路徑

 

        root  /data/ui; #解壓后ui項目所在路徑

 

        client_max_body_size 10M; #若門戶端上傳附件圖片或資源受限時,需在此處配置文件大小的限制

 

        location / {

            try_files $uri $uri/ @router;#需要指向下面的@router否則會出現vue的路由在nginx中刷新出現404

            index  index.html index.htm;

        }

        #對應上面的@router,主要原因是路由的路徑資源並不是一個真實的路徑,所以無法找到具體的文件

        #因此需要rewrite到index.html中,然后交給路由在處理請求資源

        location @router {

            rewrite ^.*$ /index.html last;

        }

 

      location /portal/ {     #portal服務端

           proxy_pass http://10.22.0.160:30095/;

           proxy_redirect off;

       }

   }

 訪問驗證

如按上述配置,訪問http://nginx所在IP:8010  ,瀏覽器查看是否能顯示門戶端首頁即可。

 

綜合運管UI的訪問和調用的nginx配置如下(需修改的配置文件默認在${nginxInstallPath}/conf/nginx.conf):

server {

        listen   9010;

        server_name adm;

        

        root  /data/ui; #解壓后ui項目所在路徑

        

        client_max_body_size 10M; #若綜合運管上傳附件圖片或資源受限時,需在此處配置文件大小的限制

 

        location / {

            try_files $uri $uri/ @router;#需要指向下面的@router否則會出現vue的路由在nginx中刷新出現404

            index  index.html index.htm;

        }

        #對應上面的@router,主要原因是路由的路徑資源並不是一個真實的路徑,所以無法找到具體的文件

        #因此需要rewrite到index.html中,然后交給路由在處理請求資源

        location @router {

            rewrite ^.*$ /index.html last;

        }

 

      location /adm/ {      #adm服務端

           proxy_pass http://10.22.0.160:30096/;

           proxy_redirect off;

       }

      location /gateway/ {    #網關的govern端

           proxy_pass http://10.22.0.160:9099/;

           proxy_redirect off;

       }

   }

 

訪問驗證

如按上述配置,訪問http://nginx所在IP:9010  ,瀏覽器查看是否能顯示門戶端首頁即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM