基于nginx搭建文件下载服务器

Administrator
发布于 2020-11-16 / 540 阅读 / 0 评论 / 1 点赞

基于nginx搭建文件下载服务器

基础镜像 nginx:1-alpine

修改nginx文件

http {


    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    client_max_body_size 356m;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

server {
        listen       80 default_server;
        server_name  localhost;
        root /opt;
        location / {
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime  on;
            alias /opt/;
            if ($request_filename ~* ^.*?\.(json|gz|zip|exe)$){
               add_header Content-Disposition attachment;
              }
       }
      }

}

编写 Dockerfile 文件

FROM nginx:1-alpine
COPY apple-app-site-association.json /opt
RUN chmod 777 /opt -R
COPY nginx.conf /etc/nginx/
CMD ["nginx", "-g", "daemon off;"]

构建镜像

docker build -t file:1 .

部署此镜像,可以挂载文件路径 使用-v 命令

docker run -d -v host路径:/opt -p 8088:80 file:1 

使用主机ip:8088 访问,
image.png


评论