【DOCKER】基于DOCKER的服务之nginx文件下载服务器

1. 创建数据卷文件夹

bash 复制代码
mkdir -p ${HOME}/.docker/volumes/nginx_file/download

2. 创建配置文件

bash 复制代码
vim ${HOME}/.docker/volumes/nginx_file/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 {
    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   65;
    types_hash_max_size 2048;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            root    /usr/share/nginx/html/download;
        autoindex on;    #开启索引功能
        autoindex_exact_size off;  #关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
        autoindex_localtime on;   #显示本机时间而非 GMT 时间
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

3. 拉取镜像与创建容器

bash 复制代码
# 拉取镜像
docker pull nginx

# 创建容器
docker run                                             \
--detach                                               \
--publish 51080:80                                     \
--name=nginx_file                                      \
--restart=always                                       \
--privileged=true                                      \
--volume /var/run/docker.sock:/var/run/docker.sock     \
--volume ${HOME}/.docker/volumes/nginx_file/nginx.conf:/etc/nginx/nginx.conf \
--volume ${HOME}/.docker/volumes/nginx_file/download:/usr/share/nginx/html/download \
nginx

# 浏览器中输入:
# http://172.17.0.1:51080
相关推荐
learning-striving10 小时前
华为云欧拉操作系统的服务器实例中手工部署 Docker
linux·运维·服务器·docker·容器·华为云
戴西软件10 小时前
戴西软件入选2026年安徽省制造业数智化转型服务商名单
java·大数据·服务器·前端·人工智能
小此方10 小时前
Re:Linux系统篇(十五)工具篇 ·六:GDB 调试从底层逻辑到高阶实战
linux·运维·服务器·chrome
修己xj19 小时前
别再让Docker占满你的硬盘!一篇搞定docker system所有命令
docker
咚为19 小时前
比AccessLog更全面的原生Nginx 日志记录
运维·nginx·junit
我星期八休息19 小时前
Linux系统编程—基础IO
linux·运维·服务器·c语言·c++·人工智能·算法
Shingmc319 小时前
【Linux】数据链路层
linux·服务器·网络
a7520662820 小时前
零基础实操:小龙虾 AI OpenClaw 接入 Kimi 详细步骤
运维·服务器
KK溜了溜了20 小时前
Python从入门到精通
服务器·开发语言·python