Docker(Nginx + SSL)安装,挂载
拉取镜像docker pull nginx:latest新建本地挂载文件启动并挂载docker run -d --name my-nginx \-p 443:443 \-p 80:80 \-v /data/nginx/html:/usr/share/nginx/html \-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \-v /data/
·
拉取镜像
docker pull nginx:latest
启动并挂载
docker run -d --name my-nginx \
-p 443:443 \
-p 80:80 \
-v /data/nginx/html:/etc/nginx/html \
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /data/nginx/ssl:/ssl \
-v /data/nginx/logs:/var/log/nginx \
-d docker.io/nginx
# 详解
-d : 后台运行容器
--name: 为容器指定一个名称
-p 443:443 映射端口443,用于https请求
-p 80:80 映射端口80,用于http请求
-v 挂载,将docker内的文件映射到本地
以上分别指定了静态文件路径、nginx配置、ssl证书路径、nginx日志
nginx配置文件
#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;
server {
listen 80;
server_name www.abc.com abc.com;
rewrite ^(.*) https://$host$1 permanent;
}
# HTTPS server
#
server {
listen 443 ssl;
server_name www.axbing.com;
# ssl文件路径,此处为docker容器内路径,实际路径为配置的挂载路径
ssl_certificate /ssl/test.crt;
ssl_certificate_key /ssl/test.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)