【问题标题】:Creating Let's Encrypt Certificate & Certbot Within Docker Image在 Docker 映像中创建 Let's Encrypt 证书和 Certbot
【发布时间】:2020-09-25 04:44:48
【问题描述】:

我有一个 Vue.js 应用程序,它在 docker 映像中与 Nginx 一起运行。我遵循了一些教程,但没有一个对我申请 Let's Encrypt 认证有帮助。如何使用我的配置在 docker 文件中创建证书?

Dockerfile:

FROM alpine:3.7

RUN apk add --update nginx nodejs

RUN mkdir -p /tmp/nginx/web
RUN mkdir -p /var/log/nginx
RUN mkdir -p /var/www/html

COPY nginx_config/nginx.conf /etc/nginx/nginx.conf
COPY nginx_config/default.conf /etc/nginx/conf.d/default.conf

WORKDIR /tmp/nginx/web

COPY . .

RUN npm install

RUN npm run build

RUN cp -r dist/* /var/www/html

RUN chown nginx:nginx /var/www/html

CMD ["nginx", "-g", "daemon off;"]

nginx_config文件夹:

default.conf:

server {
  location / {
      root /var/www/html;
      try_files $uri $uri/ /index.html;
  }
}

nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    sendfile        off;

    keepalive_timeout  60;

    gzip  on;
    gzip_static on;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_proxied  any;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;

    include /etc/nginx/conf.d/*.conf;
}

【问题讨论】:

    标签: node.js docker vue.js nginx


    【解决方案1】:

    试试jwilder nginx 反向代理,它会自动创建 Let's Encrypt 证书。我建议你使用 Docker Compose:

      your_container:
        image: your_image
        environment:
          - VIRTUAL_HOST=your_domain
          - LETSENCRYPT_HOST=your_domain
          - LETSENCRYPT_EMAIL=your_email
          - VIRTUAL_PORT=port_you_want_to_expose
    
      nginx-proxy:
        image: jwilder/nginx-proxy
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - "./vhost.d:/etc/nginx/vhost.d"
          - "/var/run/docker.sock:/tmp/docker.sock:ro"
          - "./certs:/etc/nginx/certs"
    
      letsencrypt-nginx-proxy-companion:
        image: jrcs/letsencrypt-nginx-proxy-companion
        volumes:
          - "/var/run/docker.sock:/var/run/docker.sock:ro"
        volumes_from:
          - "nginx-proxy"
    

    只需运行docker-compose up,它就会生成证书

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 2017-07-05
      • 2017-05-22
      • 1970-01-01
      • 2021-06-20
      • 2020-04-25
      • 2022-08-10
      相关资源
      最近更新 更多