1.拉取nginx镜像
docker pull nginx
2.创建文件夹
mkdir -p /home/nginx/www /home/nginx/logs /home/nginx/conf /home/nginx/cert
3.创建配置文件
vi /home/nginx/conf/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
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;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/nginx/cert/oscar9213.cn.crt;
ssl_certificate_key /etc/nginx/cert/oscar9213.cn.key;
server_name oscar9213.cn;
location / {
root /usr/share/nginx/html/;
}
}
}
4.部署nginx
docker run -d --name nginx -p 8080:80 -v /home/nginx/www:/usr/share/nginx/html -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx -v /home/nginx/cert:/etc/nginx/cert nginx