:::info 视频演示 https://www.bilibili.com/video/BV1MR4y1p7cf/ :::

nginx 配置

  1. cat > nginx.conf << EOF
  2. #默认为nobody, 会返回 403 权限错误
  3. user root;
  4. #是否显示文件目录 on显示 off 关闭显示
  5. autoindex on;
  6. # 显示文件确切大小 on 显示字节单位 off 显示出文件的大概大小,单位是KB或者MB或者GB
  7. autoindex_exact_size on;
  8. #默认为off,显示的文件时间为GMT时间 ;改为on后,显示的文件时间为文件的服务器时间
  9. autoindex_localtime on;
  10. #显示的字符集
  11. charset utf-8,gbk;
  12. # 让浏览器不保存临时文件
  13. add_header Cache-Control no-store;
  14. # 请求文件是下载而不是显示内容
  15. # add_header Content-Disposition attachment;
  16. #服务配置
  17. server{
  18. listen 80; # 监听端口 ,也可以加上IP地址,如,listen 127.0.0.1:8080;
  19. #server_name _; #定义网站域名,可以写多个,用空格分隔。
  20. #匹配规则,在server{}里可以有很多location配置段
  21. #root/alias 是指定文件路径的两种方式 alias 相当于重定向路径
  22. #使用alias,目录名后面一定要加“/”
  23. location / { # location 后面跟的搜索路径
  24. root /usr/share/nginx/file; #指定文件服务地址 这里的目录是 yml 文件里配置的映射目录
  25. }
  26. location /tmp { # 访问 IP:port/tmp
  27. alias /tmp;
  28. }
  29. }
  30. EOF

docker-compose.yml

  1. cat > docker-compose.yml << 'EOF'
  2. version: "3.7"
  3. services:
  4. fileshare:
  5. image: nginx:1.21.1-alpine
  6. container_name: fileshare
  7. restart: always
  8. environment:
  9. TZ: Asia/Shanghai
  10. ports:
  11. - 8080:80
  12. volumes:
  13. - $PWD/nginx.conf:/etc/nginx/conf.d/default.conf
  14. - /data:/usr/share/nginx/file
  15. EOF