HTTP服务器 - Nginx
Docker Hub:https://hub.docker.com/_/nginx
# 常用操作
# 拷贝配置
# 启动
docker run --name tmp-nginx-container -d nginx
# 拷贝临时容器的Nginx默认配置
docker cp tmp-nginx-container:/etc/nginx/conf.d/ <宿主机路径> # 宿主机路径无需写conf.d
# 删除容器
docker rm -f tmp-nginx-container
笔记
nginx 的主配置为 /etc/nginx/nginx.conf
,配置中包含 include /etc/nginx/conf.d/*.conf
,因此只需将域名配置添加到 /etc/nginx/conf.d/
目录下即可。
# 正式启动
docker run \
--name <容器名称> \
-v <挂载卷|宿主机路径>:/usr/share/nginx/html:ro \
-v <挂载卷|宿主机路径>:/etc/nginx/conf.d:ro \
-d \
-p 80:80 \
nginx
# 参考配置
# HTTP
server {
listen 80;
server_name 1.abc.com;
root /usr/share/nginx/html/1.abc.com;
location / {
try_files $uri $uri/ =404;
}
}
# HTTPS
上次更新: 2023/10/15, 14:40:55