简体   繁体   English

如何使用 docker-nginx-certbot 创建我的域(包括 www)的 SSL 证书?

[英]How do I create a SSL certificate my domain including www using docker-nginx-certbot?

I'm serving a website using nginx via docker compose using this container.我正在通过 docker 使用容器编写使用 nginx 为网站提供服务。

If I follow the instructions, the container only generates a SSL certificate I name in the nginx.conf如果我按照说明操作,容器只会生成我在 nginx.conf 中命名的 SSL 证书

ssl_certificate     /etc/letsencrypt/live/www.devenv.ai/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.devenv.ai/privkey.pem;

but not for devenv.ai .但不适用于devenv.ai How do I get the container to automatically create a certificate for both www.devenv.ai and devenv.ai ?如何让容器自动为www.devenv.aidevenv.ai创建证书?

You need to read the explanation how letsencrypt generates the certificate .您需要阅读letsencrypt如何生成证书的说明。

One approach is to get a wildcard certificate for devenv.ai , but this is question for system admins and beyond scope of stackowerflow, so you can research Super User, Server Fault or Ask Ubunty.一种方法是获取devenv.ai的通配符证书,但这是系统管理员和 stackowerflow 的 scope 之外的问题,因此您可以研究超级用户、服务器故障或询问 Ubunty。

If you treat them as two separate domains, then to get the separate certificates (one for each domain), you need to have your agent listening on the HTTPS port (443) on both of the domains that you will try to get it certified.如果您将它们视为两个单独的域,那么要获得单独的证书(每个域一个),您需要让您的代理在您将尝试获得认证的两个域上侦听HTTPS端口 (443)。

This means, you need to:这意味着,您需要:

  1. Set the DNS for both names to point to same IP address.将两个名称的 DNS 设置为指向相同的 IP 地址。 Using alias for www.devenv.ai to point to devenv.ai would be the good approach.使用www.devenv.ai的别名指向devenv.ai将是一个好方法。
  2. Create 2 server configurations in the nginx container, for each domain separately.nginx容器中为每个域分别创建 2 个服务器配置。 With the container you had specified, easiest approach is to have 2 separate configuration files in the conf.d .使用您指定的容器,最简单的方法是在conf.d中有 2 个单独的配置文件。 This way you will have 2 domains running on nginx and you can decide either to keep them both, or to redirect one of them to the other one.这样,您将在 nginx 上运行 2 个域,您可以决定保留它们,或者将其中一个重定向到另一个。

This can be extended to more than one domain just by adding configuration files.只需添加配置文件,就可以将其扩展到多个域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM