zoukankan      html  css  js  c++  java
  • vue打包成dist发布到服务器后代理失效

    1、项目中用到了代理,本地开发时没问题,但是发布到服务器就404。

    // config文件夹下面index.js文件
     
    module.exports = {
      dev: {
        assetsSubDirectory: "static",
        assetsPublicPath: "/",
        proxyTable: {
          "/api": {
            target: 'http://www.test.com/',      // 需要访问的代理接口
            changeOrigin: true,
            pathRewrite: {
              "^/api": "/"
            }
          }
        },
        host: 'localhost', // can be overwritten by process.env.HOST
        port: 8001, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
        autoOpenBrowser: true,
        errorOverlay: true,
        notifyOnErrors: true,
        poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
        useEslint: true,
        showEslintErrorsInOverlay: false,
        devtool: "eval-source-map",
        cacheBusting: true,
        cssSourceMap: false
      },
    }
    

    2、打包发布后需要在nginx配置文件中加入如下配置:

    location /api{
            rewrite ^.+api/?(.*)$ /$1 break; //可选参数,正则验证地址
            include uwsgi_params; //可选参数,uwsgi是服务器和服务端应用程序的通信协议,规定了怎么把请求转发给应用程序和返回
            proxy_pass http://www.test.com; // 接口地址
    }
    
  • 相关阅读:
    判断pc端或移动端并跳转
    拖动验证码插件
    angularjs 简易模态框
    angularjs 设置全局变量的3种方法
    摄影之HDR
    CentOS上使用yum安装Apache
    CentOs6.5中安装和配置vsftp简明教程
    python 安装easy_install和pip
    linux mysql 操作命令
    .net源码分析
  • 原文地址:https://www.cnblogs.com/zhangzimuzjq/p/14241261.html
Copyright © 2011-2022 走看看