大网数据广告活动
服务器运维问答

Ideal Setup of Apache for multiple SSL certs with SNI on a single IP

· 52CE 我爱测

I'm looking for the most efficient way to achieve this setup on Apache 2.4.33 in the Amazon Linux Distro: a single server instance (here: AWS EC2) a single associated IP two (or more) domains, each with their own SSL certificate …

问题原文

原帖链接 · bobsoap · CC BY-SA 4.0

I'm looking for the most efficient way to achieve this setup on Apache 2.4.33 in the Amazon Linux Distro:

  • a single server instance (here: AWS EC2)
  • a single associated IP

  • two (or more) domains, each with their own SSL certificate

  • one default SSL VirtualHost that applies to all others, to set such things as SSLProtocol, FilesMatch, and BrowserMatch only once

  • a dedicated VirtualHost per domain that points to the respective files and sets the document root

Is there something wrong with this setup?

1) /etc/httpd/conf.d/ssl.conf (entire file):

Listen 443 https

SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog

SSLSessionCache shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout 300

SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin

SSLCryptoDevice builtin

# default settings for all VirtualHosts
<VirtualHost *:443>

LogLevel warn

SSLProtocol all -SSLv3
SSLProxyProtocol all -SSLv3

SSLHonorCypherOrder o

#use OpenSSL default
#SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
#SSLProxyCipherSuite HIGH:MEDIUM:!aNULL:!MD5

<FilesMatch "\.(cgi|shtml|phtml|php)$">
  SSLOptions +StdEnvVars
</FilesMatch>

<Directory "/var/www/cgi-bin">
  SSLOptions +StdEnvVars
</Directory>

BrowserMatch "MSIE [2-5]" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

CustomLog logs/ssl_request_log \
    "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

2) /etc/httpd/cond.f/vhosts.conf

# foo.com

<VirtualHost *:80>
  ServerName foo.com
  ServerAlias www.foo.com
  Redirect 301 / https://foo.com
</VirtualHost>

<VirtualHost *:443>
  ServerName foo.com:443
  ServerAlias www.foo.com:443

  DocumentRoot "/var/www/foo"

  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/foo.crt
  SSLCertificateChainFile /etc/pki/tls/certs/foo.bundle
  SSLCertificateKeyFile /etc/pki/tls/private/foo.key

  ErrorLog logs/foo
  TransferLog logs/foo-acc
</VirtualHost>


# bar.com

<VirtualHost *:80>
  ServerName bar.com
  ServerAlias www.bar.com
  Redirect 301 / https://bar.com
</VirtualHost>

<VirtualHost *:443>
  ServerName bar.com:443
  ServerAlias www.bar.com:443

  DocumentRoot "/var/www/bar"

  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/bar.crt
  SSLCertificateChainFile /etc/pki/tls/certs/bar.bundle
  SSLCertificateKeyFile /etc/pki/tls/private/bar.key

  ErrorLog logs/bar
  TransferLog logs/bar-acc
</VirtualHost>

Will this work, or do I have to repeat the default setup for each dedicated domain?

已采纳解答

原帖链接 · bobsoap · CC BY-SA 4.0

I figured it out after some extensive testing:

The generic "master" VirtualHost in ssl.conf must reference a Certificate, Chain and Key, otherwise it will not work. So, for clarity and to avoid writing (and maintaining) duplicate lines across vhosts, it might be best to move this generic vhost into vhosts.conf, before the others.

Any rules specified there seem to be inherited properly by the following vhosts and don't have to be repeated.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。