LoginSignup
8
6

More than 3 years have passed since last update.

GCPで1clickデプロイしたwordpressをSSL化する方法

Last updated at Posted at 2018-11-03

この記事が一番参考になった。

ほぼ和訳しただけだが、自分用のメモとして残しておく。

1. SSHでサーバーに接続する

GCPはこれが楽。個

2. CertBot Clientをインストールする

$ wget https://dl.eff.org/certbot-auto && chmod a+x certbot-auto

3. 証明書を作成する

1pagezen.com部分は各々で取得したドメインで設定

$ ./certbot-auto certonly --webroot -w /var/www/html/ -d 1pagezen.com -d www.1pagezen.com

/etc/letsencrypt/live/1pagezen.com/fullchain.pem

上記のディレクトリに秘密鍵がインストールされる。

※ wwwを設定しない場合は、入れると上手くインストールされなかった。 末尾の-d 1pagezen.comは削除してもいいかも。

4. 証明書を設定する

$ sudo vi /etc/apache2/sites-available/default-ssl.conf

下記の記述をdefault-ssl.confの一番上にペースト。

default.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

次に、証明書の所在を明示する。デフォルトで設定されている記述が同ファイルにあるため、コメントアウト。
生成した証明書の所在を下記のように追加。

SSLCertificateFile "/etc/letsencrypt/live/1pagezen.com/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/1pagezen.com/privkey.pem"
SSLCertificateChainFile "/etc/letsencrypt/live/1pagezen.com/chain.pem"

5. httpsリダイレクトを設定する

$ sudo vi /etc/apache2/sites-available/wordpress.conf

既存での記述が3行あるが、それは削除。
代わりに下記を追加。例に倣って、1pagezen.comは各々が取得したドメインで設定。

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

ServerName www.1pagezen.com
ServerAlias 1pagezen.com
Redirect permanent / https://www.1pagezen.com/

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

6. Apatcheを再起動する

sudo a2ensite default-ssl
sudo a2enmod ssl
sudo service apache2 restart

自分の場合は、最後のコマンドはserviceではなくsystemctlをコマンドを使用。

sudo systemctl restart apache2

restartの前に、reloadしろとか言われるが、それはよしなにやる。

7. WordpressのURLをアップデートする

wordpressの設定画面に入って、http://部分をhttps://に変更して設定はおしまい。

8
6
2

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
8
6