vue部署服務器nginx代理配置刪除多余/api部分


 

vue部署服務器后,請求地址統一配置加了‘/api’前綴

要訪問三方接口地址:http://10.10.10.25:8080/IntellLinkPf/GetChainSummary

   vue的請求多了/api:http://10.10.10.25:8080/api/IntellLinkPf/GetChainSummary

修改nginx代理配置解決:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  5024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;

    server {
    listen      8080;
    server_name 10.10.10.25;
    #rewrite_log on; 重寫url記錄日志
    #error_log  logs/test.log debug;

    #代理方式
    location /api/IntellLinkPf/ {
           proxy_pass http://202.14.69.26:18720/IntellLinkPf/; #最后增加'/IntellLinkPf/',代理后地址移除了'/api'
        }
        
    #重寫方式
    location /api/IntellLinkPf/ {
        rewrite /api/(.*) /$1 break; #移除了'/api',$1表示正則中括號匹配到的串
        proxy_pass http://202.14.69.26:18720; 
        }

    location /QCAPI/ {
           proxy_pass http://10.10.10.25:50095;
        }

    location /render/ {
           proxy_pass http://119.123.241.169:9035;
        }

    location /{
       proxy_pass  http://10.10.10.25:8166;
    }
    }

}

參考:https://www.cnblogs.com/lixiuran/p/5515583.html


免責聲明!

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



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