安装环境:
nginx: https://nginx.org/en/download.html 根据环境下载对应版本
在指定目录解压即可使用。
打包Vue项目:
npm run build 打包文件在dist目录下
部署项目:
将dist目录下打包文件迁移至nginx html目录下
修改配置:
根据实际情况修改nginx conf目录下 nginx.conf配置文件
例如:
listen:监听端口
server_name: 服务域名 域名可以配置多个,以空格分隔
允许其他项目跨域访问 可以通过在location下设置add_header实现
add_header 'Access-Control-Allow-Origin' '*';
设置代理访问 可以通过在location下设置proxy_pass实现
proxy_pass 'http://xxx.xxx.xx.xx:端口'
启动项目:
切换到nginx.exe目录下,通过start nginx 启动项目
重新加载配置文件:
nginx -s reload
停止项目:
nginx -s stop