docker 方式部署 nginx 下载服务器
# nginx 配置为下载服务器
# 1、nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
autoindex on;
autoindex_format html;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8,gbk;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
# 2、run.sh
docker rm -f nginx;
docker run -d --name nginx --restart always -p 80:80 -v ${PWD}/data:/usr/share/nginx/html:ro -v ${PWD}/nginx.conf:/etc/nginx/nginx.conf:ro nginx:1.20.2;
- ${PWD}/data: 表示将当前执行脚本目录下的 data 文件夹映射到容器内
- ${PWD}/nginx.conf: 表示将自定义的 nginx.conf 文件映射到容器内,并替换原有配置文件