OshiHa.com

ConoHaでAlpine Linux 3.8

Nginx でサブドメインの追加(複数サイトの運営)

2018/09/01  2018/09/01

◆◇◆ 【衝撃価格】VPS512MBプラン!月額630円/1時間1円【ConoHa】 ◆◇◆

公開用の WEBサイトを2つで運用するため、サブドメイン(バーチャルホスト)を設定する。

1. サブドメイン用の SSL証明書を取得

alpine:~$ sudo rc-service nginx stop
alpine:~$ sudo certbot certonly --standalone -d *****.oshiha.com -d www.*****.oshiha.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for *****.oshiha.com
http-01 challenge for www.*****.oshiha.com
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/*****.oshiha.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/*****.oshiha.com/privkey.pem
   Your cert will expire on 2018-11-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

2. バーチャルホストの設定

$ sudo cp /etc/nginx/conf.d/default /etc/nginx/conf.d/*****.conf
$ sudo vi /etc/nginx/conf.d/*****.conf
server {
        listen 80;
        server_name *****.oshiha.com;
        return  301 https://*****.oshiha.com$request_uri;
}

server {
        listen 80;
        listen 443;
        server_name www.*****.oshiha.com;
        return 301 https://*****.oshiha.com$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name *****.oshiha.com;

        ssl_certificate     /etc/letsencrypt/live/*****.oshiha.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/*****.oshiha.com/privkey.pem;

        root /var/www/html2;
        index index.html;

        location / {
            try_files $uri $uri/ =404;

            ssi  on;
            ssi_last_modified on;
        }
}

3. 再起動

alpine:~$ sudo rc-service nginx restart

◆◇◆ 【衝撃価格】VPS512MBプラン!月額630円/1時間1円【ConoHa】 ◆◇◆

ConoHa VPSの攻略
Alpine Linux 3.8

TOP