溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

nginx 配置文件下載及在線瀏覽

發(fā)布時(shí)間:2020-06-18 09:28:29 來源:網(wǎng)絡(luò) 閱讀:12969 作者:ckl893 欄目:建站服務(wù)器

nginx 配置文件下載及在線瀏覽

1.主配置文件

# vim nginx.conf
user  nginx;
worker_processes  2;
worker_rlimit_nofile 65535;
error_log  /usr/local/nginx/logs/error.log warn;
pid        /usr/local/nginx/logs/nginx.pid;

events {
    use epoll;
    worker_connections  4096;
    multi_accept on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" $http_x_forwarded_for';

    server_tokens off;
    sendfile        on;
    tcp_nopush  on;
    tcp_nodelay on;


    keepalive_timeout  65;
    client_header_timeout 20;
    client_body_timeout 20;
    send_timeout 30;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 4;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;


    include        fastcgi_params;
    include /usr/local/nginx/conf/vhosts/*.conf;
}

2.下載配置文件

# vim toms-file.conf 
server {
    listen 80;
    server_name  10.1.1.222;
    access_log /data/logs/file_seedeer.log main;
    index    index.html index.htm index.php;
    root   /pdf_data/pdf;

    access_log_bypass_if ($remote_addr ~* '^100.97') and;
    access_log_bypass_if ($request ~* "HEAD / HTTP/1.0");
    access_log  /usr/local/nginx/logs/api_toms.log;
    charset utf-8;

    location / {
         autoindex on;  
         autoindex_exact_size on;  
         autoindex_localtime on; 
         if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
            add_header Content-Disposition: 'p_w_upload;';
         }
    }
    

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3)$ {
        expires      30d;
    }
 
    location ~ .*\.(js|css)?$ {
        expires      30d;
    }
}

3.說明

location / {
         autoindex on;  
         autoindex_exact_size on;  
         autoindex_localtime on; 
         if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
            add_header Content-Disposition: 'p_w_upload;';
         }
    }

 以上配置允許的文件格式后綴,文件可以打開,可以下載。

charset utf-8; //支持的字符集,不然漢字會(huì)亂碼

4.測(cè)試文件預(yù)覽及下載

nginx 配置文件下載及在線瀏覽

nginx 配置文件下載及在線瀏覽


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI