天天看點

nginx配置下載下傳檔案伺服器linux,詳細配置nginx 作為下載下傳伺服器,超簡單

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