美文网首页
nginx配置文件服务器

nginx配置文件服务器

作者: Joncc | 来源:发表于2024-06-22 18:34 被阅读0次

docker-compose.yml

version: "3.9"
services:
   web:
     #定义主机名
     container_name: mynginx
     #使用的镜像
     image: nginx:1.20.1
     #容器的映射端口
     ports:
       - 80:80
     #定义挂载点
     volumes:
       - /media/jon/3.6T1:/data
       - ./nginx.conf:/etc/nginx/conf.d/default.conf
     #docker 重启后,容器自启动
     restart: always

nginx.conf

server {
    listen 80;
    server_name  localhost;
    charset utf-8;
    root    /data;                  # 文件存放目录

    # 下载
    location / {
        autoindex on;                         # 启用自动首页功能
        autoindex_format html;                # 首页格式为HTML
        autoindex_exact_size off;             # 文件大小自动换算
        autoindex_localtime on;               # 按照服务器时间显示文件时间

        default_type application/octet-stream;# 将当前目录中所有文件的默认MIME类型设置为
                                              # application/octet-stream

        if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
            # 当文件格式为上述格式时,将头字段属性Content-Disposition的值设置为"attachment"
            add_header Content-Disposition: 'attachment;';
        }
        sendfile on;                          # 开启零复制文件传输功能
        sendfile_max_chunk 1m;                # 每个sendfile调用的最大传输量为1MB
        tcp_nopush on;                        # 启用最小传输限制功能

#       aio on;                               # 启用异步传输
        directio 5m;                          # 当文件大于5MB时以直接读取磁盘的方式读取文件
        directio_alignment 4096;              # 与磁盘的文件系统对齐
        output_buffers 4 32k;                 # 文件输出的缓冲区大小为128KB

#       limit_rate 1m;                        # 限制下载速度为1MB
#       limit_rate_after 2m;                  # 当客户端下载速度达到2MB时进入限速模式
        max_ranges 4096;                      # 客户端执行范围读取的最大值是4096B
        send_timeout 20s;                     # 客户端引发传输超时时间为20s
        postpone_output 2048;                 # 当缓冲区的数据达到2048B时再向客户端发送
        chunked_transfer_encoding on;         # 启用分块传输标识
    }
}

相关文章

网友评论

      本文标题:nginx配置文件服务器

      本文链接:https://www.haomeiwen.com/subject/xdqlcjtx.html