Nginx安装与启动
前往官网下载Nginx压缩包,将其解压至电脑合适位置,例如D盘下的D:\nginx-1.21.6目录。

在该路径下直接输入cmd打开命令行,执行启动命令:
nginx.exe
或者
start nginx
关闭命令
taskkill /f /t /im nginx.exe
修改配置文件后,无需先关闭再启动,可直接重启,重启命令
nginx -s reload
Vue增加访问路径
有时需区分不同Vue项目,为此要添加前缀。不加前缀时,访问地址为http://localhost:8080/;若添加前缀cancer,访问路径则变为http://localhost:8080/cancer。需在router/index.js中修改配置,增加一个base参数。
const router = new VueRouter({
routes: routes.concat(asyncRouterMap),
base: window.publicPath ? window.publicPath + "/" : "",
mode:
process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test"
? "history"
: "hash",
});
window.publicPath即为所需的前缀,设置window.publicPath = “/cancer”;
随后执行npm run build进行打包,将打包后的文件放入Nginx路径下html文件夹中新建的cancer文件夹中。
nginx配置
server {
#前端启动端口监听
listen 8780;
#本机ip,也可以是域名
server_name 192.168.2.87;
location / {
root html;
index index.html index.htm;
}
location /cancer {
alias html/cancer;
index index.html index.htm;
try_files $uri $uri/ /cancer/index.html;
}

总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持本站。