【NGINX入门】2.Nginx搭建静态资源web服务器
2021-02-02 本文已影响0人
笔名辉哥

1. 摘要
本文讲解Nginx安装后,nginx搭建静态资源web服务器需要的配置内容包括location,gzip,带宽限速等配置。
2. 内容
- nginx默认会访问index.html页面. 例如如下图配置, 当访问http://172.16.204.5:90/时, 默认会访问安装目录下的mine_html目录中的index.html文件.

- 设置nginx的gzip压缩:

- nginx支持访问文件树, 效果如下(如果访问的url路径下有index.html, 默认还是会跳到index.html页面):


添加上图中的配置后, 客户端访问http://172.16.204.5:90/时, 会以树的格式展示mine_html中的所有文件. 使用这种方式可以很好的共享静态资源.
-
在生产环境中, 公网的带宽是有限的, 并发情况下各个客户端会争抢带宽资源, 为了防止访问大的静态资源对其他用户造成影响, 可以设置nginx响应的带宽. 例如如下图设置, nginx给客户端响应时会以每秒1k的速度响应。
3. 参考
(1)Nginx系列教程(2)nginx搭建静态资源web服务器
https://yq.aliyun.com/articles/752950