问题原文
原帖链接 · Mezbah · CC BY-SA 4.0
In the Nginx configuration, trying to load ssl_certificate dynamically but
using $ssl_server_name variable
ssl_certificate /etc/letsencrypt/live/$ssl_server_name/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$ssl_server_name/privkey.pem;
getting this permission errors
│2019/09/22 08:29:42 [error] 7714#7714: *3 cannot load certificate "/etc/letsencrypt/live/example.com/fullchain.pem": BIO_new_file() failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/etc/letsencrypt/live/example.com/fullchain.pem','r') error:2006D002:BIO routines:BIO_new_file:system lib) while SSL handshaking, client: , server: 0.0.0.0:443
but without using variable, its working !
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
is there any way to load ssl_certificate based on server_name dynamically?
tried few reference but still unable to solve.
- nginx config using variable in ssl_certificate path throws permissions error
- https://trac.nginx.org/nginx/ticket/1744
社区高分解答
原帖链接 · curial · CC BY-SA 4.0
Just adding the response here in case anyone runs in to the same issue.
When nginx starts, it starts as root. If you are not using variables the certificate files can be loaded at this point (as root).
However if you are using variables, the loading of these files needs to wait until the request arrives, at which point nginx is no longer running as root bus as the user you've specified in the .conf. And it looks like this user is not able to read those files.
This is the reason it works without variables (opening files as root) and it doesn't when using them (trying to open files as another user).
You just need to make the nginx user be able to read those files.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
