LoginSignup
15
20

More than 1 year has passed since last update.

Dynamic DNS と https化 (ownCloud + Raspberry Pi 続き)

Last updated at Posted at 2016-04-17

Overview

2021/11/5:

  • mydnsのlogin記載の更新
  • let's encryptでのcertbotの追加

前回、ownCloud + Raspberry Pi で Google Drive代替 storage を 構築してみる では、ownCloudを、Ubuntu Mate 15.10 on Raspberry Pi3に構築しましたが、外から使うには、DNS対応と、https対応がないと心もとない感じですので、それのsetup編です。

dynamic DNSを利用する

私の場合は、mydns.jpを利用しました。
example.mydns.jpのような形でアクセス可能です。

cronで定期的にIP addressを更新する

mydns.jpは一定期間アクセスがないと、登録したnameが消失しますし、IP addressは通常変わり得ますので、cronで毎回loginして、IP addressを更新します。

$ cronbtab -e
*/10 * * * * wget -q -O /dev/null https://mydns123456:abcdefghijkl@ipv4.mydns.jp/login.html

のような感じで、ID/passwordで、curlとかwgetで定期ログインできるようにしましょう。

owncloudの設定

/var/www/owncloud/config/config.php
<?php
$CONFIG = array (
..snip..
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'example.mydns.jp',
    2 => 'www.example.mydns.jp',
  ),

こんな感じで、trusted_domainsに設定しましょう。

https化

let's encryptが、無料でhttpsの証明書を発行してくれるので、それを使わせてもらいます。

まず、これを実行する前に、routerの設定で、443(https)をあけておきましょう。
また、

$ sudo ufw allow 443
$ sudo ufw allow 80
$ sudo systemctl restart apache2

などで、443(https)と80(http)を開けておきましょう。

/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
</VirtualHost>
/etc/apache2/ports.conf
Listen 80

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

certbotのinstall

$ sudo apt-get install snapd
$ sudo snap install core; sudo snap refresh core
$ sudo snap install --classic certbot
$ ln -s /snap/bin/certbot /usr/bin/certbot
$ sudo certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: aaa.xxx.mydns.jp
2: bbb.xxx.mydns.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 
Requesting a certificate for drive.tsurudaya.mydns.jp and www.tsurudaya.mydns.jp

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/aaa.xxx.mydns.jp/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/bbb.xxx.mydns.jp/privkey.pem
This certificate expires on 2022-02-04.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

..snip..

上のように、自動で今後cert renewしてくれるので、crontabで設定する必要は無いです

ほか

それでは、enjoy.

15
20
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
15
20