项目打包-nginx-基本使用(windows环境下)

81 阅读1分钟

项目打包-nginx-基本使用

1.png

执行打包命令

npm run build:prod

得到dist文件包

windows-安装-nginx

nginx.org/en/download…

2.png

3.png

windows环境下nginx部署启动项目

1. 将打包的文件放置到安装目录/html下

把打包之后的文件,放在html目录下:

4.png

2. windows版本启动服务

5.png

5.png

双击图标

6.png

nginx解决history的404问题

修改配置文件

windows下的配置文件

7.png

location / {
   try_files $uri $uri/ /index.html;
}
nginx配置代理解决生产环境跨域问题

修改配置文件

8.png

location /prod-api  {
  #  proxy_pass https://heimahr-t.itheima.net;
  proxy_pass https://heimahr.itheima.net/api;
}

注意:

千万要注意任务管理器中只能打开一个nginx进程,不然最新的配置无法生效.