docker-compose 简单搭建nginx的ssl环境

Posted zoer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker-compose 简单搭建nginx的ssl环境相关的知识,希望对你有一定的参考价值。

docker-compose 简单搭建nginx的ssl环境

说明:docker-compose实现nginx通过https访问,入门级示例

1、docker-compose.yml内容

version: "3"
services:
 nginx:
  restart: always
  container_name: nginx
  image: nginx:1.16.0
  ports:
   - 80:80
   - 443:443
  environment:
    TZ: Asia/Shanghai
  volumes:
   - ./nginx/conf.d:/etc/nginx/conf.d
   - ./nginx/log:/var/log/nginx
   - ./nginx/html:/usr/share/nginx/html
   - ./nginx/cert:/etc/nginx/cert
   - ./nginx/nginx.conf:/etc/nginx/nginx.conf

2、nginx.conf内容

server {
        listen 443 ssl http2;
        server_name  _;
        root html;
        index index.html index.htm;
        ssl_certificate   cert/******.pem;
        ssl_certificate_key  cert/******.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

3、将证书放到./nginx/cert下,即可实现https访问

以上是关于docker-compose 简单搭建nginx的ssl环境的主要内容,如果未能解决你的问题,请参考以下文章

Docker-compose搭建nginx负载均衡

halo搭建炫酷个人博客快速部署:docker+docker-compose+nginx

简单的docker-compose编写介绍(包含 nginx+tomcat 实例演示)

简单的docker-compose编写介绍(包含 nginx+tomcat 实例演示)

简单的docker-compose编写介绍(包含 nginx+tomcat 实例演示)

vernemq 集群 docker-compose 搭建简单试用