vue项目配置打包后,设置的 devServer 失效,需要使用 nginx 来映射地址
安装环境 nginx
将打包后的 dist 文件放到 nginx 目录下的 html 中
在 nginx 目录下 conf/nginx.conf 进行配置
server {
# 监听端口号
listen 8888;
# 访问地址
server_name localhost;
location / {
# 文件入口
root html;
index index.html;
try_files $uri $uri/ /index.html;
}
# 映射接口地址
location /api {
proxy_pass http://localhost:5000/;
}
}
启动命令(在nginx目录下输入)
start nginx
输入地址 localhost:8888 就能打开了