LoginSignup
2
4

More than 5 years have passed since last update.

Lightsail×WordPressでHTTPSにリダイレクト

Last updated at Posted at 2018-09-23

httpをhttpsにリダイレクトさせるいつものやつです。

どうやらロードバランサーを通す場合はいつものリダイレクトの設定と少し書き方が違うみたいで少しハマりました。

参考にさせていただいた記事
https://qiita.com/foursue/items/58e74c4a8c946dd49e12

前提

  • インスタンス作成済み(WordPress)
  • ロードバランサー導入済み
  • SSL導入済み

作業

設定ファイルにリダイレクトの設定を追記

$ vim /opt/bitnami/apps/wordpress/conf/httpd-prefix.conf
httpd-prefix.conf
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Apacheを再起動

$ sudo /opt/bitnami/ctlscript.sh restart apache

これでできました。

Lightsail、ポチポチするだけで爆速でサーバーができました!かなりいい感じです。

次はスナップショットの自動取得をやりたいです。

追記

WordPressの管理画面に入れなかったです(泣)
ロードバランサを使う際にはWordPress側の設定が必要でした。

設定ファイルを開きます

$ vim /opt/bitnami/apps/wordpress/htdocs/wp-config.php

これをrequire_onceの直前に入れたらうまくいきました。

wp-config.php
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS'] = 'on';

参考URL
https://codex.wordpress.org/Function_Reference/is_ssl

2
4
0

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
2
4