在nginx中使用通配符证书的多个SSL虚拟主机

Modified on: Sat, 25 May 2019 04:40:02 +0800

我有两个主机名共享同一个域名,我想通过HTTP提供服务。我有一个通配符SSL证书并创建了两个vhost配置:

主持人A

listen      127.0.0.1:443 ssl;
server_name     a.example.com;
root        /data/httpd/a.example.com;
ssl_certificate /etc/ssl/wildcard.cer;
ssl_certificate_key /etc/ssl/wildcard.key;

主持人B

listen      127.0.0.1:443 ssl;
server_name     b.example.com;
root        /data/httpd/b.example.com;
ssl_certificate /etc/ssl/wildcard.cer;
ssl_certificate_key /etc/ssl/wildcard.key;

但是,我为任一主机名提供相同的vhost。

作者:vincent.io

最佳答案

您需要从ssl listen / configuration部分分割vhost:

听力部分:

server {
  listen              127.0.0.1:443 default_server ssl;
  server_name         _;
  ssl_certificate     /etc/ssl/wildcard.cer;
  ssl_certificate_key /etc/ssl/wildcard.key;
}

现在是vhosts:

server {
  listen      127.0.0.1:443;
  server_name a.example.com;
  root        /data/httpd/a.example.com;
}

server {
  listen      127.0.0.1:443;
  server_name b.example.com;
  root        /data/httpd/b.example.com;
}
作者:Teftin

相关问答

添加新评论