詳細配置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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章