参考:https://blog.csdn.net/qq_33454884/article/details/89212702
启动闪退:https://blog.csdn.net/weixin_66383346/article/details/132622156
1.下载安装nginx 下载地址:https://nginx.org/en/download.html windows版 :nginx/Windows-1.27.0
解压后必须放在没有中文,没有空格的目录中
2.启动nginx,直接双击nginx.exe 或者 cmd进入安装目录,执行命令:start nginx ,然后访问 http://localhost/ ,会出现 Welcome to nginx! 就成功了。
这个版本默认端口号80,很可能已经被占用,被占用就没法正常启动,需要修改配置文件 /conf/nginx.conf 把端口改成空闲的,然后加上端口再访问 http://localhost:88/
注意:安装目录文件夹必须具有写入权限,不然也没法启动,nginx要写日志的。
server { listen 88; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #后面还有其他配置,我只截取了这些... }
3.nginx常用命令
启动服务:start nginx 退出服务:nginx -s quit 强制关闭服务:nginx -s stop 重载服务:nginx -s reload (重载服务配置文件,类似于重启,服务不会中止) 验证配置文件:nginx -t 使用配置文件:nginx -c "配置文件路径" 使用帮助:nginx -h
4.部署前端项目,比如我的前端项目发布后的目录是 D:\VueSite
修改nginx.conf的location 的 root 配置,指定前端项目的目录;index 是用来指定首页的,vue编译完了首页就是index.html 这里不用改。
然后执行命令 nginx -s reload 重启nginx ,访问 http://localhost:88/ 就可以正常访问vue项目了
server { listen 88; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root D:\VueSite; index index.html index.htm; } #后面还有其他配置,我只截取了这些... }
5.nginx同时部署多个前端项目,只需要配置多个server节点,端口改成不一样的,这样就可以了。
server { listen 88; server_name localhost; location / { root D:\VueSite; index index.html index.htm; } } server { listen 89; server_name localhost; location / { root D:\VueSite2; index index.html index.htm; } } server { listen 90; server_name localhost; location / { root D:\VueSite3; index index.html index.htm; } }
标签:index,Vue,nginx,部署,server,Nginx,html,location,localhost From: https://www.cnblogs.com/xsj1989/p/18260169