简体   繁体   English

Apache VirtualHost多域多个SSL

[英]Apache VirtualHost multiple domain multiple SSL

Hi I have the following use case, I have an application (let's call it foobar) on a remote server /var/www/foobar and I have the following Apache VirtualHost conf 嗨我有以下用例,我有一个应用程序(让我们称之为foobar)在远程服务器/ var / www / foobar上我有以下Apache VirtualHost conf

<VirtualHost *:80>
  DocumentRoot /var/www
  # This is to redirect http traffic to https
  Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost *:443>
  SSLEngine On
  SSLCertificateFile /etc/ssl/certs/example.com.crt
  SSLCertificateKeyFile /etc/ssl/private/example.com.key
  SSLCertificateChainFile /etc/ssl/certs/example.com.bundle.crt

  ServerName example.com:443
  DocumentRoot /var/www/foobar
</VirtualHost>

And its working all fine. 它的工作一切都很好。 Now suppose I have another domain example2.com and I want it to point to the same foobar application. 现在假设我有另一个域example2.com,我希望它指向相同的foobar应用程序。 My current thinking is create another VirtualHost below, something like this 我目前的想法是在下面创建另一个VirtualHost,就像这样

<VirtualHost *:443>
  SSLEngine On
  SSLCertificateFile /etc/ssl/certs/example2.com.crt
  SSLCertificateKeyFile /etc/ssl/private/example2.com.key
  SSLCertificateChainFile /etc/ssl/certs/example2.com.bundle.crt

  ServerName example2.com:443
  DocumentRoot /var/www/foobar
</VirtualHost>

But I was wondering is this the correct way of doing stuff like this? 但我想知道这是做这样的事情的正确方法吗? I need both domains to be "independent" so I didn't make a permanent redirect from example2.com to example.com 我需要两个域都是“独立的”所以我没有从example2.com永久重定向到example.com

You can do something like below,You can use the server alias for this, Also I don't see anything wrong in having 2 virtual hosts as well. 您可以执行以下操作,您可以使用服务器别名,此外我也没有看到有2个虚拟主机的错误。

<VirtualHost *:443>
    ServerName example1.com
    ServerAlias example2.com
    SSLEngine on
    SSLCertificateFile  /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/testlink

</VirtualHost>

If you are getting unable to get a certificate error, you can create a certificate with a wildcard CN. 如果您无法获得证书错误,则可以使用通配符CN创建证书。 eg : *.com this will match both example1.com and example2.com. 例如: *.com这将匹配example1.com和example2.com。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM