LoginSignup
52
49

More than 5 years have passed since last update.

SSL でも VirtualHost (Apache2.2)

Last updated at Posted at 2014-07-25

Apache2.2 の VirtualHost を SSL を使うサイトにも適用

追記

コメントで指摘を受けたとおり、この設定は Apache2.2 までで有効な設定です。
Apache2.3 以降(多分 2.4 以降を使うのが一般的だとは思うけど)ではこの設定を書くことなく NameVirtualHost を適用することが可能です。

This directive currently has no effect.

とあるので、2.4 では設定があってもエラーにはならないようですが。
(多分今後のバージョンアップでは完全に撤廃されてエラーになるんだろうな)

普通の VirtualHost の設定

Apache の VirtualHostを適用する時、SSL を使わない場合

NameVirtualhost *:80

と設定してから

<VirtualHost *:80>
    ServerName virtualhost.example.com
    DocumentRoot /var/www/virtualhost.example.com

    ErrorLog logs/virtualhost_error_log
    CustomLog logs/virtualhost_access_log combined env=!no_log
</VirtualHost>

SSL のついたサイトの VituralHost の設定

SSL を使うサイトでは以下のように設定すれば良いのだけど、それだけじゃ不十分.

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

    SSLEngine on
    SSLCertificateFile /path/to/file.crt
    SSLCertificateKeyFile /path/to/file.key

    ErrorLog logs/sslvirtual_error_log
    CustomLog logs/sslvirtual_access_log combined env=!no_log
</VirtualHost>

意外と意識から抜けてたけど

NameVirtualhost *:443

この記述も入れておかないと VirtualHost は設定できないので忘れないように.

52
49
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
52
49