[Nginx] NginxでGitリポジトリを共有

Oct 31, 2018   #Nginx  #Git 

環境

  • Windows 10

  • Windows Subsystem for Linux (Ubuntu)

概要

NginxでGitリポジトリを共有したい。

必要なモジュールのインストール

sudo apt-get install nginx fcgiwrap spawn-fcgi

fcgiwrap.socketを作成

/var/run/fgciwrap.socket
[Unit]
Description=fcgiwrap Socket

[Socket]
ListenStream=/run/fcgiwrap.sock

[Install]
WantedBy=sockets.target
permissionを変更
sudo chmod 666 fcgiwrap.socket

/etc/nginx/sites-available/defaultを編集

server {
    listen 80 default_server;
    listen [::]:80 default_server;

+    location ~ ^/git/.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
+        client_max_body_size 0;
+        fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
+        include fastcgi.conf;
+        fastcgi_pass unix:/var/run/fcgiwrap.socket;
+        fastcgi_split_path_info ^(/git)(/.*);
+        fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
+        fastcgi_param GIT_PROJECT_ROOT /var/www/git;
+        fastcgi_param GIT_HTTP_EXPORT_ALL "";
+        fastcgi_param PATH_INFO $fastcgi_path_info;
+        fastcgi_param REMOTE_USER $remote_user;
+    }
}

Nginx起動

sudo service nginx start

fcgiwrap起動

sudo /etc/init.d/fcgiwrap start

Gitリポジトリ作成

sudo mkdir /var/www/git
sudo git init --bare --shared=group /var/www/git/hoge.git
sudo git config --file /var/www/git/hoge.git/config http.receivepack true
sudo chgrp -R www-data /var/www/git/hoge.git