Table of contents
1. Background
During our work, there are many large images or installation packages, etc., which take up a lot of space on our local computer, and the download speed is slow. Building a file server can efficiently store files and download with wget.
2. Operation steps
1. Download the nginx installation package and install it (compile and install)
//下载nginx安装包,nginx官网地址:http://nginx.org/
wget http://nginx.org/download/nginx-1.13.7.tar.gz
//安装nginx依赖包
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
//创建nginx安装目录并解压安装包
mv nginx-1.13.7 nginx /usr/local/
tar -zxvf nginx-1.13.7.tar.gz
//进入nginx目录,安装证书,并安装nginx
mv nginx-1.13.7 nginx
cd nginx
//执行命令 考虑到后续安装ssl证书 添加两个模块
./configure --with-http_stub_status_module --with-http_ssl_module
//make安装nginx
make && make instal l
//启动nginx
./nginx
2. Modify the nginx.cof configuration file
//进入conf目录
cd /usr/local/nginx/conf
//修改nginx.conf
vim nginx.conf
server {
listen 80;
server_name localhost;
charset utf-8;
root /home/downloads; # 文件存放目录
# 下载
location / {
autoindex on; # 启用自动首页功能
autoindex_format html; # 首页格式为HTML
autoindex_exact_size off; # 文件大小自动换算
autoindex_localtime on; # 按照服务器时间显示文件时间
default_type application/octet-stream;# 将当前目录中所有文件的默认MIME类型设置为
# application/octet-stream
if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
# 当文件格式为上述格式时,将头字段属性Content-Disposition的值设置为"attachment"
add_header Content-Disposition: 'attachment;';
}
sendfile on; # 开启零复制文件传输功能
sendfile_max_chunk 1m; # 每个sendfile调用的最大传输量为1MB
tcp_nopush on; # 启用最小传输限制功能
# aio on; # 启用异步传输
directio 5m; # 当文件大于5MB时以直接读取磁盘的方式读取文件
directio_alignment 4096; # 与磁盘的文件系统对齐
output_buffers 4 32k; # 文件输出的缓冲区大小为128KB
# limit_rate 1m; # 限制下载速度为1MB
# limit_rate_after 2m; # 当客户端下载速度达到2MB时进入限速模式
max_ranges 4096; # 客户端执行范围读取的最大值是4096B
send_timeout 20s; # 客户端引发传输超时时间为20s
postpone_output 2048; # 当缓冲区的数据达到2048B时再向客户端发送
chunked_transfer_encoding on; # 启用分块传输标识
}
}
3. Restart nginx
//进入启动目录
cd /usr/local/nginx/sbin/
//重启nginx
./nginx -s reload
3. Effect
1. Effect picture (browser access http://+ip)
2. Simulate other servers to download files from the file server wget (oh my god, 93M/S)