LoginSignup
0
0

More than 3 years have passed since last update.

FreeBSD12.1+apacheでgitサーバ(smart http)

Last updated at Posted at 2020-06-25

gitレポジトリのサーバを立てるにあたり、プロトコルはsshでいいや、と思っていたのだけど、意外とhttpプロトコルでの設定も簡単にできるとのこと。

とりあえず、試してみました。

環境

  • VirtualBox on ubuntu20.04
  • FreeBSD 12.1

上記の環境で、インストールしてネットワークが接続できるところまで設定し終わっている事を前提とします。

設定

apacheとgitのインストール。

pkg install apache24 git

apacheの設定。
/usr/local/etc/apache24/Include/000-default.conf」というファイルを作成して、設定します。

/usr/local/etc/apache24/Include/000-default.conf
<VirtualHost *:80>
    ServerName hoge.example.com

    SetEnv GIT_PROJECT_ROOT /var/html/git
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git /usr/local/libexec/git-core/git-http-backend
    <Location /git>
        AuthName "Git Repository"
        AuthType Basic
        AuthUserFile /usr/local/etc/apache24/git.passwd
        Require valid-user
    </Location>
</VirtualHost>

/etc/rc.conf」で、apacheサービスを有効設定にします。

/etc/rc.conf
apache24_enable="YES"

パスワードファイルを作成します。
以下のコマンドを実行すると、パスワードを尋ねられるので、入力します。

htpasswd -c /usr/local/etc/apache24/git.passwd katsuko

レポジトリを作成します。

mkdir -p /var/html/git
git init --bare --shared /var/html/git/project.git
cd /var/html/git/project.git
git update-server-info
chown -R www:www .

サービスを起動します。

service apache24 start

これで、他のクライアントから「git clone http://katsuko@hoge.example.com/git/project.git」でクローンができる…と思いきや、

fatal: repository 'http://hoge.example.com/git/project.git/' not found

とのエラーが。
ふと「/usr/local/etc/apache24/httpd.conf」を見てみると、

/usr/local/etc/apache24/httpd.conf
<IfModule !mpm_prefork_module>
        #LoadModule cgid_module libexec/apache24/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
        #LoadModule cgi_module libexec/apache24/mod_cgi.so
</IfModule>

というように、mod_cgiがコメントアウトされているので、このコメントを外してやりましょう。
いやー、CGI動かすの久々なんで、ちょっと悩みましたよ。

ちなみに、「Options ExecCGI」は要らないのかな、と思ったのだけど、apacheのマニュアルによると、必要なのは「ScriptAlias」の指定以外でCGIを動かす場合のようです。


続き。

0
0
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
0
0