u23*_*3d7 5 nginx ssl-certificate docker dockerfile lets-encrypt
我有一个 Flask 应用程序,前面有 nginx 反向代理服务器。我已将我的应用程序部署在 Digital Ocean Droplet 上。我创建了一个具有 root 权限的用户,并使用该用户通过 HTTPS 运行我的应用程序。我一直遇到位于以下路径中的 .pem 文件的权限问题:/etc/letsencrypt/live/my-domain-name.com。我现在要做的就是在终端中使用 sudo 命令将这些文件复制到我的项目文件夹,然后在 nginx Dockerfile 中再次将它们复制到 /etc/nginx 并在配置文件中给出此路径。但是,这并不理想,因为我希望自动续订我的 SSL 证书。我尝试使用chown -R user:user/etc/letsencrypt等命令更改根用户的权限,但没有任何效果。我收到此错误:
nginx: [emerg] BIO_new_file("/etc/letsencrypt/live/my-domain-name.com/fullchain.pem") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/my-domain-name.com/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?我希望能够使用 /live/my-domain-name 路径访问 .pem 文件,并能够在证书过期时续订我的证书,而无需使用 root 用户。任何帮助将不胜感激。谢谢。
项目conf文件:
server {
listen 80;
server_name my-domain-name.com www.my-domain-name.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name my-domain-name.com www.my-domain-name.com;
ssl_certificate /etc/nginx/fullchain.pem;
ssl_certificate_key /etc/nginx/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://app:8000;
proxy_ssl_server_name on;
# Do not change this
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
rewrite ^/static(.*) /$1 break;
root /static;
}
}
Run Code Online (Sandbox Code Playgroud)
Nginx Dockerfile:
FROM nginx:1.13.3
EXPOSE 80
EXPOSE 443
RUN rm /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/
RUN rm /etc/nginx/conf.d/default.conf
COPY project.conf /etc/nginx/conf.d/
COPY fullchain.pem /etc/nginx/
COPY privkey.pem /etc/nginx/
Run Code Online (Sandbox Code Playgroud)
我认为这不是最佳做法。您也不应该使用 root 用户访问您的 Droplet
您应该使用具有 sudo 授予权限的新用户设置 Droplet,并完全删除 root 访问权限,如本指南中所述: https ://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16 -04
然后,您应该使用 certbot nginx 插件验证 Droplet 并存储 SSL 证书,如下所述:https:
//www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-在 ubuntu-16-04 上
上一篇指南的第 5 步解释了更新证书部分。
归档时间: |
|
查看次数: |
2219 次 |
最近记录: |