1. 程式人生 > 實用技巧 >vue部署伺服器nginx代理配置刪除多餘/api部分

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