nginx简单部署vue项目

360 阅读1分钟
  • congfig/index.js
	assetsPublicPath:'/admin/'	//改成自己的命名
  • router/index.js
	mode: 'history',	//去掉地址栏的 # 
	base: '/admin/',	//这里加一行自己的命名
  • 打包
	npm run build 
  • 上传项目
	打包好的项目上传到 nginx/html/admin 目录下
  • nginx/cong/nginx.conf

    location ^~ /admin {
        alias	/html/admin;	#配置项目路径
        index  index.html index.htm;
        error_page  404  /index.html;
        try_files $uri $uri/ @router;	# 处理 Vue 单页面应用 路由模式为 history 模式刷新页面 404 的问题
    }

  	#避免刷新页面出现404
    location @router {
        rewrite ^.*$ /jfsc/index.html last;
    }
  • 访问项目
	ip + /admin/index.html