vue 代理问题

233 阅读1分钟

在开发环境下的代理

配置config中的index.js文件


 '/web':{
        target: 'http://192.168.1.xxx:9092',  /*代理的是后端地址*/
        changeOrigin: true,
        pathRewrite: {
        '^/web': '/web/' /*代表是web开始的接口映射到 以web开始定义的接口*/
      }


在生产环境,build下,可以使用nignx反向代理

  # underscores_in_headers on;


server {
    listen       80;
    server_name  localhost;

   
	access_log  /var/log/nginx/host.access.log  main;
    error_log  /var/log/nginx/error.log  error;
    

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    


  location /web/ {

       proxy_set_header  Content-type 'application/json;charset-UTF-8';

       proxy_set_header   Access-Control-Allow-Origin  '*';

        proxy_pass   http://xxxx:9092; /*xxx 代表后端地址或者对应的域名*/

}


}