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