docker配置Nginx总结
1、首先拉取相关的镜像:
命令:docker pull nginx

2、创建目录和文件,为容器挂载做准备
创建如下目录和文件夹

在conf文件夹下,添加默认配置,也可自定义
命令:vim nginx.conf
nginx.conf
# user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
# 包括当前目录下的conf.d文件夹的所有配置
include ./conf.d/*.conf;
}
在conf.d文件夹下,创建默认配置
命令:vim default.conf
default.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html;
}
}
3、创建运行容器
命令:docker run --name mynginx -p 80:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d -d nginx:latest
配置了nginx.conf,html页面logs的挂载
检测:挂载成功


浙公网安备 33010602011771号