Nginx 核心配置-作为下载服务器配置
Nginx核心配置-作为下载服务器配置
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.无限速版本的下载服务器
1>.查看主配置文件
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf/nginx.conf
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000; events {
worker_connections 100000;
use epoll;
accept_mutex on;
multi_accept on;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
charset utf-8; #开启长连接后,返回客户端的会话保持时间为60s,单次长连接累计请求达到指定次数请求或65秒就会被断开,后面的60为发送给客户端应答报文头部中显示的超时时间设置为60s:如不设置
客户端将不显示超时时间。 keepalive_timeout 65 60; #在一次长连接上所允许请求的资源的最大数量
keepalive_requests 3; #导入其他路径的配置文件
include /yinzhengjie/softwares/nginx/conf.d/*.conf;
} [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]#
2>.查看子配置文件
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/share.conf
server {
listen 80;
server_name node101.yinzhengjie.org.cn; location / {
root /yinzhengjie/data/web/nginx/static;
index index.html;
} location /download {
root /yinzhengjie/data/web/nginx;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
}
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]#
3>.创建测试数据
[root@node101.yinzhengjie.org.cn ~]# mkdir -pv /yinzhengjie/data/web/nginx/download
mkdir: created directory ‘/yinzhengjie/data/web/nginx/download’
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll
total 3338920
-rw-r--r-- 1 root root 3419052032 Oct 6 2016 cn_windows_7_ultimate_with_sp1_x64_dvd_618537.iso
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# mv cn_windows_7_ultimate_with_sp1_x64_dvd_618537.iso /yinzhengjie/data/web/nginx/download/
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cp /etc/passwd /etc/mtab /etc/sysctl.conf /etc/fstab /yinzhengjie/data/web/nginx/download/
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/data/web/nginx/download/
total 3338936
-rw-r--r-- 1 root root 3419052032 Oct 6 2016 cn_windows_7_ultimate_with_sp1_x64_dvd_618537.iso
-rw-r--r-- 1 root root 541 Dec 17 14:41 fstab
-r--r--r-- 1 root root 2205 Dec 17 14:41 mtab
-rw-r--r-- 1 root root 1145 Dec 17 14:41 passwd
-rw-r--r-- 1 root root 735 Dec 17 14:41 sysctl.conf
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
4>.重新加载nginx的配置文件
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep ngin | grep -v grep
root 2840 1 0 09:37 ? 00:00:00 nginx: master process nginx
nginx 4769 2840 0 14:12 ? 00:00:00 nginx: worker process
nginx 4770 2840 0 14:12 ? 00:00:00 nginx: worker process
nginx 4771 2840 0 14:12 ? 00:00:00 nginx: worker process
nginx 4772 2840 0 14:12 ? 00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -s reload
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep ngin | grep -v grep
root 2840 1 0 09:37 ? 00:00:00 nginx: master process nginx
nginx 4991 2840 11 14:42 ? 00:00:00 nginx: worker process
nginx 4992 2840 10 14:42 ? 00:00:00 nginx: worker process
nginx 4993 2840 11 14:42 ? 00:00:00 nginx: worker process
nginx 4994 2840 10 14:42 ? 00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]#
5>.访问nginx的下载站点
6>.下载一个大文件,并观察下载的网速
二.限速版本的下载服务器
1>.编辑子配置文件
[root@node101.yinzhengjie.org.cn ~]# vim /yinzhengjie/softwares/nginx/conf.d/share.conf
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/share.conf
server {
listen 80;
server_name node101.yinzhengjie.org.cn; location / {
root /yinzhengjie/data/web/nginx/static;
index index.html;
} location /download {
root /yinzhengjie/data/web/nginx;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
limit_rate 10k;
}
}
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]#
2>.重新加载配置文件
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root 2840 1 0 09:37 ? 00:00:00 nginx: master process nginx
nginx 4991 2840 0 14:42 ? 00:00:00 nginx: worker process
nginx 4992 2840 0 14:42 ? 00:00:00 nginx: worker process
nginx 4993 2840 0 14:42 ? 00:00:00 nginx: worker process
nginx 4994 2840 0 14:42 ? 00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -s reload
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root 2840 1 0 09:37 ? 00:00:00 nginx: master process nginx
nginx 5023 2840 10 14:48 ? 00:00:00 nginx: worker process
nginx 5024 2840 10 14:48 ? 00:00:00 nginx: worker process
nginx 5025 2840 10 14:48 ? 00:00:00 nginx: worker process
nginx 5026 2840 10 14:48 ? 00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]#
3>.打开网页并下载上次的那个大文件,观察下载速度,如下图所示
三.生产环境关于搭建下载网站的建议
1>.相关参数配置说明
autoindex on;
自动索引功能,即在没有index.html文件的存在下,列出root目录下的所有文件,但不包括隐藏文件。、 autoindex_exact_size on;
计算文件确切大小(单位bytes),off只显示大概大小(单位kb、mb、gb) autoindex_localtime on;
显示本机时间而非GMT(格林威治)时间 limit_rate rate;
限制响应给客户端的传输速率,单位是bytes/second,默认值0表示无限制限速与不限速的对比:
2>.生产环境中限速和不限速的下载站点应用场景
不限速下载站点应用场景:
一般是公司内部员工使用,下载速度是没有必要限制了,因为同一个公司应该很少存在别人攻击咱们的显现,不过话又说回来,害人之心不可有,防人之心不可无啊,若干有人要离职前搞点事情的我们运维还是得防着点的,比如某某写了脚本恶意下载导致公司内网交换机传输带宽上线,导致员工无法正常办公的情况,可以考虑使用上网行为管理等工具或者是在交换机每个端口限速,当然还得对网络情况进行监控,一旦有问题我们运维人员立马收到消息,可以很快就处理掉这种情况。 限速下载站点的应用场景:
这种下载速度限制一般我们在公网上跑服务,害怕有人而已攻击咱们的下载站点,比如写个死循环开启N多个线程同时下载咱们下载站点的一个大文件,这样你会发现自己的带宽就这样被浪费啦~因此限速是有必要的。
Nginx 核心配置-作为下载服务器配置的更多相关文章
- Nginx 核心配置-作为上传服务器配置
Nginx 核心配置-作为上传服务器配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.关键参数说明 client_max_body_size 1m: 设置允许客户端上传单 ...
- Nginx 核心配置-新建一个web站点
Nginx 核心配置-新建一个web站点 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Nginx基础配置常用参数说明 [root@node101.yinzhengjie.or ...
- Nginx 核心配置详解
目录 Nginx 核心配置详解 Nginx 四层访问控制: Nginx账户认证功能: 自定义错误页面: 自定义访问日志: 检测文件是否存在: 长连接配置: 作为下载服务器配置: 作为上传服务器: 其他 ...
- Nginx 核心配置-根目录root指令与别名alias指令实战案例
Nginx 核心配置-根目录root指令与别名alias指令实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.试验环境说明 1>.虚拟机环境说明 [root@nod ...
- Nginx 核心配置-可优化配置参数
Nginx 核心配置-可优化配置参数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.nginx的官网查看指令帮助信息方法 1>.打开nginx的官网(https://ng ...
- Nginx 核心配置-长连接配置
Nginx 核心配置-长连接配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.长连接配置参数说明 keepalive_timeout number; 设定保持连接超时时长,0 ...
- Nginx 核心配置-检测文件是否存在
Nginx 核心配置-检测文件是否存在 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. try_files会按顺序检查文件是否存在,返回第一个找到的文件或文件夹(结尾加斜线表示为文件 ...
- Nginx 核心配置-自定义日志路径及清空日志注意事项
Nginx 核心配置-自定义日志路径及清空日志注意事项 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.关于日志清空注意事项 1>.nginx服务写访问日志是基于acces ...
- Nginx 核心配置-自定义错误页面
Nginx 核心配置-自定义错误页面 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 生产环境中错误页面一般都是UI或开发工程师提供的,他们已经在软件中定义好了,我们这里就简单写个h ...
随机推荐
- yum 初始化国内
修改为阿里源备份默认的yum源文件 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 下载阿里 ...
- [1018NOIP模拟赛]
题目描述 Description 精灵王国要同侵略 $ Bzeroth $ 大陆的地灾军团作战了. 众所周知,精灵王国有 \(N\) 座美丽的城市,它们以一个环形排列在$ Bzeroth$ 的大陆上. ...
- Nginx主配置文件说明
#运行用户 user nobody; #启动进程,通常设置成和cpu的数量相等 worker_processes ; #全局错误日志及PID文件 #error_log logs/error.log; ...
- impala入门
一.概述 Impala 是参照google 的新三篇论文Dremel(大批量数据查询工具)的开源实现,功能类似shark(依赖于hive)和Drill(apache),impala 是clouder ...
- [LeetCode] 269. Alien Dictionary 另类字典
There is a new alien language which uses the latin alphabet. However, the order among letters are un ...
- 第02组 Alpha冲刺(4/6)
队名:無駄無駄 组长博客 作业博客 组员情况 张越洋 过去两天完成了哪些任务 摸鱼 提交记录(全组共用) 接下来的计划 沟通前后端成员,监督.提醒他们尽快完成各自的进度 学习如何评估代码质量 准备Al ...
- Spring 常犯的十大错误,这坑你踩过吗?
阅读本文大概需要 9 分钟. 1.错误一:太过关注底层 我们正在解决这个常见错误,是因为 “非我所创” 综合症在软件开发领域很是常见.症状包括经常重写一些常见的代码,很多开发人员都有这种症状. 虽然理 ...
- 推荐一款移动端日历App吉日历
推荐一款移动端日历App吉日历 一 应用描述 万年历.日历.农历.黄历.假期安排.天气预报.记事提醒便捷查看,一目了然! 二 功能介绍: 1.万年历:精美的日期展示,完整的节日日历随意查看,节假日.休 ...
- AtomicReference示例
对引用类型的原子性操作 /** * *对引用变量的原子操作 note: *在java中对引用类型的变量,赋值是原子性的,为什么还要有atomicReference,假如要对一个引用类型进行比较,设置等 ...
- Linux(centOS6.5)安装RabbitMQ
第一.下载erlang和rabbitmq-server的rpm: wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.c ...