Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue 打包部署在服务器非根目录,访问404 #16

Open
RicoLiu opened this issue May 23, 2019 · 0 comments
Open

vue 打包部署在服务器非根目录,访问404 #16

RicoLiu opened this issue May 23, 2019 · 0 comments

Comments

@RicoLiu
Copy link
Owner

RicoLiu commented May 23, 2019

vue的项目打包部署在服务器后,访问 http://xxxx.com/xxx 时,提示各种静态资源找不到。

查阅了很多资料,对 webpack 打包做修改:

config/index.js:

build: {
  assetsPublicPath: '/xxx/',
}

build/webpack.prod.js:

output: {
  publicPath: '/xxx/',
}

router/index.js:

const router = new Router({
  base: '/xxx/'
})

最后,nginx 也需要修改对应的配置

location  ^~ /xxx/{
                alias /H5/xxx/;
                try_files $uri $uri/ /xxx/index.html;
                gzip on;
                gzip_types application/javascript text/css image/jpeg image/png;
        }

这样,访问静态资源抱404的问题就解决了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant