LoginSignup
15
20

More than 5 years have passed since last update.

CentOS 7.3 で WebDAV の構築

Posted at

はじめに

  • まずはじめにそんなに立派な記事ではない。
  • しかもこれは私が理解した内容をまとめた記事に過ぎない。

WebDAV とは

  • HTTP を使ってファイルサーバを実現するプロトコル。
  • Apache に付属のモジュールを有効化することで使えるようになる。
  • Windows や Mac からOS標準の仕組みでもってつなぐことができる。
  • ユーザごとのディスククォータ(サイズ制限)はかけられない。

構築動機

  • git リモートリポジトリのインターネット上への構築
    • 会社からのアクセスでファイアウォールに弾かれないこと
      • -> git(port:9148) ssh(port:22) はこの段階で落ちる。
      • -> http(port:80) https(443) だけが残る。
    • 経路上暗号化されること
      • -> http が落ちて https しか選択肢がなくなる。
    • git push できること
      • -> http(s) の git リモートリポジトリは多くの場合 pull のみ。
      • -> push するには WebDAV を使うしかなくなるようだ。
      • 参考:4.1 Git サーバー - プロトコル
    • 誰が push してきたか身元を確認できること
      • クライアント証明書 / WebDAV の認証のいずれかを使うはず。
      • この辺は構築しながら調べたい。

構築

WevDAV の構築

WebDAV 用のフォルダを作る

  • 将来的にはここに git の bare リポジトリを作り込む。
  • 従ってフォルダ名を /home/repos-git01 とする。
  • ユーザを apache グループも apache パーミッションは 770 に設定する。
# mkdir        /home/repos-git01
# chown apache /home/repos-git01
# chgrp apache /home/repos-git01
# chmod 770    /home/repos-git01
# ls    -ld    /home/repos-git01/
drwxr-xr-x 2 apache apache 42  6月 17 10:34 /home/repos-git01/

Apache で WebDAV を有効にする

  • CentOS 7.3 ではすでに有効になっている。
  • 自動インクルードされる設定ファイル /etc/httpd/conf.modules.d/00-dav.conf にちゃんとこう書いてある。
# cat /etc/httpd/conf.modules.d/00-dav.conf 
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dav_lock_module modules/mod_dav_lock.so

WebDAV 用のフォルダを Apache からアクセス可能にする

  • WebDAV用の設定ファイルを用意しそこに書き込んでいく。
#  vi /etc/httpd/conf.d/dav.conf
  • Apache設定ファイルに /home/repos-git01/ を認識させる。
Alias /repos-git01/ "/home/repos-git01/"
  • アクセス許可を設定する。
<Directory /home/repos-git01>
    <RequireAny>
        Require method GET POST OPTIONS
        Require valid-user
    </RequireAny>
</Directory>
  • テストのために index.html を作成する。
# date | tee /home/repos-git01/index.html
  • ブラウザで確認する。見られればOK。
http://this.is.your.server.name/repos-git01/
  • index.html は消しておく
# rm -i /home/repos-git01/index.html

WebDAV の設定を書き込む

  • 先ほどのファイルを開く。
# vi /etc/httpd/conf.d/dav.conf
  • WebDAV のロックファイルを指定する。
  • (ユーザ「apache」が書き込める場所であること)。
DAVLockDB "/tmp/WebDAV.lock"
  • DAV に使う旨を書き込む。
<Directory /home/repos-git01>
    DAV On
  • Macでは認証なしではDAVはセキュリティ上つながらないポリシぽいので認証設定する。
<Directory /home/repos-git01>
    DAV On
    AuthType Basic
    AuthName WebDAV
    AuthUserFile /etc/httpd/conf/.htpasswd
  • 結果的にこんな設定ファイルになった。
DAVLockDB "/tmp/WebDAV.lock"
Alias /repos-git01/ "/home/repos-git01/"
<Directory /home/repos-git01>
    DAV On
    AuthType Basic
    AuthName WebDAV
    AuthUserFile /etc/httpd/conf/.htpasswd
    <RequireAny>
        Require method GET POST OPTIONS
        Require valid-user
    </RequireAny>
</Directory>
  • 認証用のユーザリストを作っておく。
  • (仮にユーザ dav パスワード dav とした)
htpasswd -b -c /etc/httpd/conf/.htpasswd dav dav
  • Apache を再起動する。
$ sudo systemctl restart httpd

動作確認する

  • Windows などから「Webフォルダ作成」で、実際にファイルの読み書きができるかどうかを試してみよう。

https の設定

パッケージのダウンロード

# yum -y install openssl 
# yum -y install mod_ssl 

Apache 設定ファイルの書き換え

# vi /etc/httpd/conf.d/ssl.conf 
  • 59行目:コメント解除
    • DocumentRoot "/var/www/html"
  • 60行目:コメント解除しサーバー名指定
    • ServerName this.is.your.server.name:443
  • 75行目:変更
    • SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2
  • Apache を再起動する。
$ sudo systemctl restart httpd

ファイアウォールをはずす

# firewall-cmd --add-service=https --permanent
# firewall-cmd --reload 

動作確認

  • オレオレ証明書である旨の警告が出る。
  • 例外を承認すると通常通りのトップページが現れるはず。
https://this.is.your.server.name/
  • WebDAV サーバとしても HTTPS でつながるはず
https://this.is.your.server.name/repos-git01/

git リポジトリの作成

  • パッケージの追加
# yum install git
  • ベアリポジトリの作成
# cd /home/repos-git01/
# git init --bare --shared
  • git でオレオレ証明書をOKにする。
$ git config --global http.sslVerify false
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