docker部署nginx并实现反向代理添加ssl证书
1. docker-compose文件
先不做volumes 启动容器
成功后将容器内目录cp到宿主机再做volume操作
1 2 3 4 5
| docker cp nginx:/usr/share/nginx/html ./ngin/html docker cp nginx:/usr/share/nginx/key ./nginx/key docker cp nginx:/var/log/nginx ./nginx/logs docker cp nginx:/etc/nginx/nginx.conf ./nginx/nginx.conf docker cp nginx:/etc/nginx/conf.d ./nginx/conf.d
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| version: '3' services: nginx: restart: always container_name: nginx image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:nginx-latest ports: - 80:80 - 443:443 volumes: - ./nginx/html:/usr/share/nginx/html - ./nginx/key:/usr/share/nginx/key - ./nginx/logs:/var/log/nginx - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/conf.d:/etc/nginx/conf.d environment: - NGINX_PORT=80 - TZ=Asia/Shanghai privileged: true
|
2.nginx配置反向代理 配置文件
将ssl key文件上传到相应目录即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| server { listen 80; listen [::]:80; server_name localhost;
location / { root /usr/share/nginx/html; index index.html index.htm; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
}
server { listen 443 ssl; server_name localhost; root /usr/share/nginx/html; index index.html index.htm; ssl_certificate /usr/share/nginx/key/ssl.crt; ssl_certificate_key /usr/share/nginx/key/ssl_nopass.key; ssl_session_timeout 5m; ssl_prefer_server_ciphers on; location / { proxy_pass http://58.40.166.66:8080; } error_page 404 /404.html; location = /40x.html { }
error_page 500 502 503 504 /50x.html; location = /50x.html { } }
|