centos 7 x64
1)
yum -y install nginx
2)
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 {
use epoll;
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"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
types_hash_max_size 2048;
charset utf-8;
server_tokens off;
server_names_hash_bucket_size 128;
client_header_buffer_size 4;
client_header_timeout 60;
client_body_timeout 60;
large_client_header_buffers 16 512k;
client_max_body_size 5g;
gzip on;
gzip_min_length 1024;
gzip_buffers 16 32k;
gzip_proxied any;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript;
limit_conn_zone $binary_remote_addr zone=one:2048m;
#共使用2048M的内存来对于IP传输开销
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 54656;
server_name IP地址;
location / {
root /etc/nginx/html/download;
if ($request_filename ~* ^.*?\.(sh||shell|py|perl|pl|go|mp3|mp4|jpg|jpeg|bmp|gif|dmg|tar|xls|rpm|pxt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
#配置if实现下载而不是直接在浏览器打开
add_header Content-Disposition: 'attachment';
}
autoindex on; #开启索引功能
autoindex_exact_size off; #关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
autoindex_localtime on; #显示本机时间而非 GMT 时间
sendfile on;
tcp_nopush on;
expires 1h;
#allow 192.168.4.0/24; #允许4段的所有地址访问
#allow 192.168.5.0/24; #允许5段的所有地址访问
#deny all; #禁止全部
}
error_page 404 /404.html;
location = /404.html{
root html;
}
error_page 500 501 502 503 504 505 /50x.html;
location = /50x.html{
root html;
}
}
}
3)
mkdir -p /etc/nginx/html/download/
cp /usr/share/nginx/html/*0*.html /etc/nginx/html/
4)
将需要下载的文件放到/etc/nginx/html/download
5)
nginx -c /etc/nginx/nginx.conf
6)
http://IP地址:54656