使用nginx打开本地打包vue文件

280 阅读1分钟

vue hash路由打包部署nginx

1. vue路由配置,并打包

`router.js`
const router = new VueRouter({
	mode: "hash",
	base: "/",
	routes,
});
`vue.config.js`
module.exports = {
	publicPath: "/",
	outputDir: "local", // 输出文件目录
}
npm run build ...

2.nginx 配置

找到 ...\nginx-1.20.2\conf目录下的 nginx.conf

image.png

  • 遇到到问题:history路由打包后,刷新路由404(未解决问题)

3.运行或重载nginx

启动:start nginx

配置文件修改重装载命令:nginx -s reload

nginx常用命令

操作nginx命令,需要切换目录到 ...\nginx

    启动:start nginx
    快速停止或关闭:nginx -s stop
    正常停止或关闭:nginx -s quit
    重启:
    查看启动项:tasklist /fi "imagename eq nginx.exe"
    关闭所有启动项:taskkill /f /t /im nginx.exe
    配置文件修改重装载命令:nginx -s reload
    重启服务:service nginx restart
  • 遇到问题:# nginx重启发生异常The system cannot find the file specified
  • 解决方案:系统任务管理器,找到nginx.exe进程,结束任务