setup wordpress on oracle cloud

最終更新日

目次
1. Let's Encrypt
2. Security Rules
3. iptables
4. nginx
5. wp-config.php

oracle cloud上で、ubuntu 16.04 を利用してこのblogをあげている。

今後のためのメモ

Let’s Encrypt

domain 認証でSSLの証明書を取得。

docker container で簡単。

docker run -it --rm --name certbot \
  -v "$(pwd)/etc/letsencrypt:/etc/letsencrypt" \
  -v "$(pwd)/var/lib/letsencrypt:/var/lib/letsencrypt" \
  certbot/certbot \
  certonly --manual -d *.ドメイン名 \
  -m メイルアドレス \
  --agree-tos \
  --manual-public-ip-logging-ok \
  --preferred-challenges dns-01 \
  --server https://acme-v02.api.letsencrypt.org/directory

結果として、こんな出力。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.ドメイン名 with the following value:

xxxxxxxxxxQxxxxxxxxxxxxxxxxxxxxxxxxxxqxxxxxxx

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

指定された value を DNSのTXTレコードとして設定すればOK。

あとは、dockerを起動したカレントディレクトリにある以下のファイルを、後述のnginx を起動するサーバ上に移動しておく。

./etc/letsencrypt/archive/{ドメイン名}/privkey{n}.pem
./etc/letsencrypt/archive/{ドメイン名}/fullchain{n}.pem

Security Rules

Oracle Cloud の管理画面で、 Network Securty Group の設定で 443 port を公開しておく。

iptables

/etc/iptables/rules.v4 にhttps の許可を設置しておく。

# CLOUD_IMG: This file was created/modified by the Cloud Image build process
# iptables configuration for Oracle Cloud Infrastructure

# See the Oracle-Provided Images section in the Oracle Cloud Infrastructure
# documentation for security impact of modifying or removing these rule

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [463:49013]
:InstanceServices - [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p udp --sport 123 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A OUTPUT -d 169.254.0.0/16 -j InstanceServices
...

nginx

ssl の設定をしておく。

下記は、docker container を利用して、 localhost:8080 にwordpress サーバが待ち受けしている例。

##
# server configuration
#
server {
        # SSL configuration
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        server_name サーバ名;
        ssl on;
        ssl_protocols              TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers  on;
        ssl_ciphers                'ECDHE+RSAGCM:ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:!aNULL!eNull:!EXPORT:!DES:!3DES:!MD5:!DSS';
        ssl_certificate            /etc/letsencrypt/live/ドメイン名/fullchain.pem;
        ssl_certificate_key        /etc/letsencrypt/live/ドメイン名/privkey.pem;
        location / {
                proxy_pass    http://localhost:8080/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;

                proxy_redirect   off;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Proto https;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect http:// https://;
        }
}

wp-config.php

外部からSSLを受けて、nginx のreverse proxy で内部のhttp server(wordpress) に転送しているため、wordpressは自分のことを http サービスだと思っている。

wp-config.php に https サービスであることを記述追加しておく。

$_SERVER['HTTPS'] = 'on';

シェアする