1.目录/文件准备
生成一个容器并拷贝出相应的文件和目录
docker run --name nginx -p 80:80 -d nginx
docker cp nginx:/etc/nginx/nginx.conf /home/site/conf/
docker cp nginx:/etc/nginx/conf.d /home/site/
2.上传相应ssl文件到目录下
scp xxxx.pem user@100.111.222.333:/home/site/ssl
scp xxxx.key user@100.111.222.333:/home/site/ssl
3. 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;
server {
listen 443 ssl;
server_name www.guobao.art;
ssl_certificate /etc/nginx/ssl/xxxx.pem;
ssl_certificate_key /etc/nginx/ssl/xxxx.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADM:!RC4;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.guobao.art;
rewrite ^(.*)$ https://$server_name$1 permanent;
location / {
index index.html index.htm;
}
}
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;
}
4.docker生成容器
docker run -it -p 80:80 -p 443:443 -v /home/site/webfile:/usr/share/nginx/html -v /home/site/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/site/cert:/etc/nginx/ssl -v /home/site/conf.d:/etc/nginx/conf.d -v /home/site/log:/var/log/nginx --privileged=true -d --restart=always nginx