繁体   English   中英

Docker WSL2 SSL 本地证书 HTTPS

[英]Docker WSL2 SSL certificate for local HTTPS

I'm running Windows 10 Pro and WSL2 (using Ubuntu 20.4) and want to set docker up so that I can dev locally using https .

在我的 windows /etc/hosts中,我设置了以下别名。

127.0.0.1 api.myapp.local
127.0.0.1 client.myapp.local
127.0.0.1 admin.myapp.local

# Added by Docker Desktop
192.168.5.81 host.docker.internal
192.168.5.81 gateway.docker.internal

# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

我在 WSL 中检查了我的/etc/hosts并确认更改已自动保留。

在我的docker-compose文件中,我有以下两个服务 A)创建证书 B)将它们安装到我的nginx容器

version: "3"

networks:
  myapp:
    driver: bridge

services:
  # Build certificates for nginx.
  mkcert:
    container_name: mkcert
    image: vishnunair/docker-mkcert
    environment: 
      domain: client.myapp.local,admin.myapp.local
    volumes:
      - ./nginx/certs-enabled/:/root/.local/share/mkcert
  nginx:
    volumes:
      - ./nginx/certs-enabled/:/etc/nginx/certs
      - ./nginx/logs:/var/log/nginx
      - ./nginx/sites-enabled:/etc/nginx/conf.d
    container_name: nginx
    depends_on:
      - mkcert
    image: nginx:1.19
    command: nginx -g "daemon off;"
    networks:
      - ${NETWORK}
    ports:
      - 80:80
      - 443:443

安装到./nginx/certs-enabled的证书已成功安装到容器中,我将生成的rootCA.pem admin.myapp.pem client.myapp.pem证书安装到 windows Trusted Root Certificates中。 还生成了rootCA-key.pem admin.myapp-key.pem, client.myapp-key.pem ,但我不安装这些,因为我不认为这是必需的?

我重新启动了我的电脑,如果我访问https://admin.myapp.local例如,我收到以下错误: 在此处输入图像描述 让我感到困惑的是,用于该本地域的证书是一个过期的 VMWare 证书,但我没有将 VMWare 与 docker 一起使用(据我所知,它是通过虚拟机管理程序运行的,而且我我还为该域配置/安装了适当的证书)

Nginx 配置完整性

server {
    listen 80;
    listen [::]:80;

    server_name client.myapp.local default_server;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;

    ssl_certificate /etc/nginx/certs/client.myapp.local.pem;
    ssl_certificate_key /etc/nginx/certs/client.myapp.local-key.pem;

    server_name client.myapp.local;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    include /etc/nginx/snippets/myapp-common.conf;
}

这非常令人沮丧,我从我的机器上卸载了 VMWare 并重新启动,现在一切正常。 解析主机时一定有冲突

暂无
暂无

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

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