0
点赞
收藏
分享

微信扫一扫

nginx 当做文件服务器

陆佃 2022-02-15 阅读 177

前言

nginx 作为文件服务器。

步骤

#1.确认nginx的主配置文件nginx.conf引入了一会要配置的外部文件include /etc/nginx/conf.d/*.conf;--此处为正则绝对路径外部引入配置文件
http {
    include       /etc/nginx/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"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
	#****************确认此处外部引入了配置文件*************
    include /etc/nginx/conf.d/*.conf;
}
#2.配置文件服务server

    location /logs {#自定义访问路径,正则匹配
        alias   /var/log/nginx/;
        #alias相当于是给/logs起了个别名,即客户端访问/logs/a.txt 其实是访问服务器目录/var/log/nginx/a.txt资源。注意alias后面必须/结尾。
        #root 是根路径,与alias不同,此处如果换成root,则客户端访问/logs/a.txt其实是访问服务器/var/log/nginx/logs/a.txt资源
        autoindex on;#显示目录
        autoindex_exact_size on;#显示文件大小
        autoindex_localtime on;#显示文件时间
        allow all;
        #if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx|log)$){
        if ($request_filename ~* ^\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx|log)$){
            add_header Content-Disposition: 'p_w_upload;';#该行必须要有,不然客户端不能下载文件
         }
    }


举报

相关推荐

0 条评论