【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
相关推荐
weixin_4454766834 分钟前
Docker 在 Ubuntu(国内网络)安装及问题解决总结
网络·ubuntu·docker
一点晖光2 小时前
docker配置npm环境变量出现问题
docker·容器·npm
写代码的橘子n2 小时前
IPV6复习(基础入手版)
运维·服务器·网络
一分半心动2 小时前
windows docker desktop 安装VibeVoice
运维·docker·容器
向日葵.3 小时前
中间件交接文档
linux·运维·服务器
LucidX3 小时前
Docker核心操作实战
运维·docker·容器
隔壁阿布都3 小时前
Docker Compose中的网络管理
运维·docker·容器
TG:@yunlaoda360 云老大3 小时前
华为云国际站代理商TaurusDB的读写分离是如何实现的?
服务器·数据库·华为云
_oP_i3 小时前
开源项目 SQLBot Dockerfile、docker-compose.yaml、Dockerfile-base 三个文件直接的关系
docker
Blurpath3 小时前
什么是 ISP 代理?双 ISP 代理又是什么?一文讲清原理与应用场景
服务器·网络·ip代理·静态代理·住宅代理