nginx做文件服务器
[root@vm ~]# docker run -itd --name file -p 80:80 nginx
[root@vm ~]# docker exec -it file cat /etc/nginx/nginx.conf
... include /etc/nginx/conf.d/*.conf;
[root@vm ~]# docker exec -it file ls /etc/nginx/conf.d/
default.conf
[root@vm ~]# docker exec -it file cat /etc/nginx/conf.d/default.conf
server {
listen 80;
...
创建配置
[root@vm ~]# cat file.conf
server {
listen 8080;
server_name localhost;
location /files {
alias /mnt;
autoindex on; # 开启索引功能,以便可以看到文件列表
autoindex_exact_size off; # 显示文件大小
autoindex_localtime on; # 显示文件时间
# 设置访问权限,可以是特定的IP或IP段,这里允许所有
allow all;
# deny 192.168.1.1; # 禁止特定的IP或IP段
# 设置访问日志
#access_log /var/log/nginx/files_access.log;
#error_log /var/log/nginx/files_error.log;
}
}
# 启动服务
[root@vm ~]# docker run -itd --name file -p 8080:8080 -v /mnt:/mnt -v ./file.conf:/etc/nginx/conf.d/file.conf nginx
[root@vm ~]# touch /mnt/test.file
# 访问
http://10.1.0.11:8080/files/