docker-compose.yml
version: "3.9"
services:
web:
#定義主機(jī)名
container_name: mynginx
#使用的鏡像
image: nginx:1.20.1
#容器的映射端口
ports:
- 80:80
#定義掛載點(diǎn)
volumes:
- /media/jon/3.6T1:/data
- ./nginx.conf:/etc/nginx/conf.d/default.conf
#docker 重啟后檀头,容器自啟動(dòng)
restart: always
nginx.conf
server {
listen 80;
server_name localhost;
charset utf-8;
root /data; # 文件存放目錄
# 下載
location / {
autoindex on; # 啟用自動(dòng)首頁(yè)功能
autoindex_format html; # 首頁(yè)格式為HTML
autoindex_exact_size off; # 文件大小自動(dòng)換算
autoindex_localtime on; # 按照服務(wù)器時(shí)間顯示文件時(shí)間
default_type application/octet-stream;# 將當(dāng)前目錄中所有文件的默認(rèn)MIME類型設(shè)置為
# application/octet-stream
if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
# 當(dāng)文件格式為上述格式時(shí)君丁,將頭字段屬性Content-Disposition的值設(shè)置為"attachment"
add_header Content-Disposition: 'attachment;';
}
sendfile on; # 開(kāi)啟零復(fù)制文件傳輸功能
sendfile_max_chunk 1m; # 每個(gè)sendfile調(diào)用的最大傳輸量為1MB
tcp_nopush on; # 啟用最小傳輸限制功能
# aio on; # 啟用異步傳輸
directio 5m; # 當(dāng)文件大于5MB時(shí)以直接讀取磁盤的方式讀取文件
directio_alignment 4096; # 與磁盤的文件系統(tǒng)對(duì)齊
output_buffers 4 32k; # 文件輸出的緩沖區(qū)大小為128KB
# limit_rate 1m; # 限制下載速度為1MB
# limit_rate_after 2m; # 當(dāng)客戶端下載速度達(dá)到2MB時(shí)進(jìn)入限速模式
max_ranges 4096; # 客戶端執(zhí)行范圍讀取的最大值是4096B
send_timeout 20s; # 客戶端引發(fā)傳輸超時(shí)時(shí)間為20s
postpone_output 2048; # 當(dāng)緩沖區(qū)的數(shù)據(jù)達(dá)到2048B時(shí)再向客戶端發(fā)送
chunked_transfer_encoding on; # 啟用分塊傳輸標(biāo)識(shí)
}
}