下载 nginx下载
- 使用npm run build编译vue项目
- 得到一个dist的文件夹,复制放入nginx下的html文件下
- 找到conf下nginx.conf文件打开修改配置
location / {
root html/dist;
try_files $uri /index.html; #简略理解是:尝试去找文件,具体意思baidu
}
location /api { # /api 代表所有的带api路径的请求都会转发到proxy_pass所写的访问路径上
proxy_pass http://localhost:9091;
proxy_http_version 1.1;
}
- vue中修改路由
const createRouter = () => new VueRouter({
mode: 'history',//history模式,去除#号
routes
})
const router = createRouter()
// 注销时重置router
export function resetRouter () {
const newRouter = createRouter()
router.matcher = newRouter.matcher
}
- springboot项目的properties配置文件
server.port=9091
server.servlet.context-path=/api
- nginx常用命令
- 启动nginx服务
start nginx
- 重新载入配置文件
当有系统配置文件有修改,用此命令,建议不要停止再重启,以防报错!
nginx -s reload
- 从容停止服务
需要进程完成当前工作后再停止。
nginx -s quit
- 立即停止服务
无论进程是否在工作,都直接停止进程。
nginx -s stop