チェ・ゲバムラの日記

脱犬の道を目指す男のブログ

さくらVPSで設定中にSSLがきかない(80,443ポートの共存virtualhostの書き方も)

基本はapachectl configtestしたときのエラー文を調べたらわかるけども。

 

可能性1

mod_sslがインストールされてないかも。

# yum -y install mod_ssl
で、apache再起動すればおk。

 

可能性2

Listen 443が2つ読み込まれてるとか。

自分で書く必要ない

 

んで一応Vhostの書き方的には

NameVirtualHost *:80

NameVirtualHost *:443

 

<VirtualHost *:80>
ServerName any
Redirect / https://xxxxxxxxx.jp/
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/html/xxxxxxxxx.jp
ServerName xxxxxxxxx.jp
ErrorLog logs/error_log_xxxxxxxxx.jp
CustomLog logs/access_log_xxxxxxxxx.jp combined

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule /.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
<Directory "/var/www/html/xxxxxxxxx.jp">
Options -Indexes
AllowOverride All
</Directory>
</VirtualHost>

 

<VirtualHost *:443>
DocumentRoot /var/www/html/xxxxxxxxx.jp
ServerName xxxxxxxxx.jp
SSLEngine on
SSLCertificateChainFile /etc/httpd/ssl_xxxxxxxxx/2016/ssl.xxxxxxxxx2016.cer
SSLCertificateFile /etc/httpd/ssl_xxxxxxxxx/2016/ssl.xxxxxxxxx2016.crt
SSLCertificateKeyFile /etc/httpd/ssl_xxxxxxxxx/2016/ssl.xxxxxxxxx2016.key
ErrorLog logs/error_log_xxxxxxxxx.jp
CustomLog logs/access_log_xxxxxxxxx.jp combined
<Directory "/var/www/html/xxxxxxxxx.jp">
Options -Indexes
AllowOverride All
</Directory>
</VirtualHost>

 

 

太字のとこが大事なとこかな。

これでSSL対応もできたし、80ポートでアクセスされたらhttpsにリダイレクトされるようになった。

こんな感じでよさそう。