我的服务器运行在LEMP堆栈Ubuntu 16.04和最后一个版本的nginx上
我已经在我的服务器上为以下域和子域安装了SSL证书: example.com , domain1.example.com和一切工作正常。
我想为domain2.example.com创build一个新的证书
为此,我尝试了这个命令:
sudo certbot --nginx -d example.com -d domain1.example.com -d domain2.example.com --expand
在/etc/nginx/sites-enabled/example.com中找不到set(['www.example.com','* .example.com','example.com'))的证书或密钥指令。 VirtualHost没有被修改。
server { # SSL configuration listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; include snippets/ssl-example.com.conf; include snippets/ssl-params.conf; root /var/www/laravel/public; index index.php index.html index.htm; server_name example.com *.example.com www.example.com ; }
我究竟做错了什么 ? 我如何重新创build证书来添加domain2 ?
这是我必须做的。
certbot certificatesfind现有的certbot certificates expand的证书 sudo certbot certonly --cert-name example.com -d example.com -d domain1.example.com -d domain2.example.com --expand来更新证书sudo certbot certonly --cert-name example.com -d example.com -d domain1.example.com -d domain2.example.com --expand 。 2: Place files in webroot directory (webroot) webroot ,这是我/var/www/laravel 对我来说,我进入了/etc/nginx/sites-enabled文件夹,并手动删除了错误的sym-linked虚拟主机文件,我以为我之前已经删除。 惊喜,他们仍然在那里。 所以请确保在该文件夹中执行sudo rm -rf [filename] 。 然后通过sudo nginx -s reload重新启动nginx sudo nginx -s reload并再次运行certbot命令,并且应该是GTG。
最好的方法之一是使用webroot插件(描述https://certbot.eff.org/#centosrhel7-other )。 我build议遵循下面的方法:
将以下位置指令添加到主机(服务器块),您要通过certbot进行处理并获取证书:
location /.well-known { root /usr/share/nginx/html; }
安装certbot
certbot certonly命令 /usr/share/nginx/html (如位置指令根目录)。 /etc/letsencrypt/live/youdomain.com/fullchain.pemfind您的证书。 添加到服务器块:
ssl on; ssl_certificate /etc/letsencrypt/live/youdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/youdomain.com/privkey.pem;
这就是所有;)之后,您可以通过运行certbot renew命令轻松更新证书。
怎么运行的?
当我们添加位置指令时,我们为/.well-known位置select自定义根文件夹。 Certbot在.well-known目录和外部authentication服务器(ACME CA)里面创build文件检查这个文件夹中的文件。 如果您pipe理多个域或使用nginx作为代理(!),那么为/.well-known位置使用一个通用根是非常有用的,因为在这种情况下,您可能没有使用nginx的计算机上的根目录(例如,您已经安装了nginx一个VPS作为安装在另一个VPS上的Apache的代理)。
祝你好运。