Nginx.conf
user root; worker_processes 1; error_log /var/log/Nginx/error.log warn; pid /var/run/Nginx.pid; events { worker_connections 1024; } 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; }
Nginx-file-server.conf
server { listen 8081; #端口 server_name localhost; #服务名 charset utf-8; # 避免中文乱码 root /data; #显示的根索引目录,注意这里要改成你自己的,目录要存在 location / { autoindex on; #开启索引功能 autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb) autoindex_localtime on; # 显示本机时间而非 GMT 时间 } }
启用8081作为文件服务器端口
运行命令:
docker run -d -p 8081:8081 --name file-server -v $(pwd):/data -v $(pwd)/Nginx.conf:/etc/Nginx/Nginx.conf -v $(pwd)/Nginx-file-server.conf:/etc/Nginx/conf.d/Nginx-file-server.conf Nginx
命令将宿主的当前目录挂载到容器的/data目录,并挂载conf配置文件,启动Nginx
或者直接运行以下命令
curl -s https://files-cdn.cnblogs.com/files/nihaorz/start-Nginx-file-server.sh | bash
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。