[英]How to use Let's Encrypt with Docker container based on the Node.js image
[英]Creating Let's Encrypt Certificate & Certbot Within Docker Image
我有一個 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;
}
試試jwilder nginx 反向代理,它會自動創建 Let's Encrypt 證書。 我建議你使用 Docker 撰寫:
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
生成證書
我有一個 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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.