1、在官网下载安装包,安装。
2、修改nginx配置(配置前端路径、后端接口路径和端口等信息)
3、cmd打开命令窗口,cd到nginx的安装目录下,启动nginx
4、查看nginx进程列表
tasklist /fi "imagename eq nginx.exe"
5、终止nginx进程
taskkill /f /pid 9320 /pid 3068
终止所有进程:
taskkill /fi "imagename eq nginx.EXE" /f
6.browser history
模式打包的单页面项目部署到nginx
location / {
root html;
index index.html;
# url 切换时始终返回index.html
try_files $uri /index.html;
}
如果浏览器访问地址:http://localhost:8001/test
那么$uri就是/test,try_files会到root文件里找/test文件,显然没有这个文件,因为这是单页面应用的路由路径,所以try_files就访问/index.html,发送一个内部请求http://localhost:8001/index.html,加载index.html之后,单页面的router就能起作用并匹配我们输入的/test
路由,从而显示正确的test页面
注意事项:
(1)上传文件的时候,出现413报错,原因是 请求体缓存区配置不够大,在相应请求路径设置 请求体缓存区大小:
client_max_body_size 10m; #表示最大上传10M,需要多大设置多大。
nginx配置参数:
1、alias和root
root的处理结果是:root路径+location路径
alias的处理结果是:使用alias路径替换location路径
alias是一个目录别名的定义,root则是最上层目录的定义。
还有一个重要的区别是alias后面必须要用“/”结束,否则会找不到文件的。。。而root则可有可
参考来源于:
https://www.nginx.cn/4658.html