1.创建存放下载文件目录,传入文件
# 注释:nginx服务为yum安装 [root@nginx ~]# mkdir /etc/nginx/downloadFile [root@nginx ~]# ll /etc/nginx/downloadFile/ total 32 -rw-r--r-- 1 root root 13392 Sep 24 16:09 1.gif -rw-r--r-- 1 root root 12947 Sep 24 16:13 picture.tar.gz
2.配置nginx
[root@centos7 downloadFile]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=512m;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
#include /etc/nginx/conf.d/*.conf;
server {
listen 80;
root /usr/share/nginx/html ;
proxy_cache_key $host$uri;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
location / {
root /etc/nginx/downloadFile; # 指定实际目录绝对路径
autoindex on; # 开启目录浏览功能
autoindex_exact_size off; # 关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b
autoindex_localtime on; # 开启以服务器本地时区显示文件修改日期
}
}
}
3.展示效果
#######