nginxを使用してhttpアクセス用のgitサーバーを構築します

通常、gitのインストールが完了した後、sshプロトコルを使用してgitサーバーをプルおよびプッシュします。httpプロトコルを使用する必要がある場合は、httpコンテナーと追加の構成が必要です。ここでは、nginxがhttpコンテナとして使用されています。

まず、gitnginxをインストールしてから、libfcgi-dev、autoconf、libtool、automakeをインストールする必要があります。具体的なプロセスについては、https: //www.nginx.com/resources/wiki/startを参照してください。 / topics / examples / fcgiwrap /

ソースコードを介してインストールする場合は、対応するソースコードをダウンロードする必要があります。ソースコードのパスは次のとおりです。

libfcgiソースコードautoconfソースコードlibtoolソースコードautomakeソースコード

fcgio.cpp:50:14:エラー:「EOF」がこのスコープで宣言されていない場合、libfcgiのインストール時にオーバーフロー(EOF)エラーが発生することに注意してください。前に、#include <stdio.h>、fcgio.cppを追加する必要があります。 fcgio.cppのlibfcgiディレクトリ内

https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/の   インストールプロセスには、主に次の点に注意する必要があります。

1. fcgiwrapをインストールする前に、pkg-configをインストールする必要があります

 pkg-configソースコード

設置方法

./configure --with-internal-glib
make
make install

2.起動スクリプトのbinパスが正しい必要があり、スクリプトの実行許可を与えることを忘れないでください

我的fcgiwrap在/usr/local/sbin/目录下,所以 $bin_path修改为$bin_path='/usr/local/sbin/fcgiwrap'

3.起動スクリプトをrc.localの下に置き、起動するたびに自動的に起動するようにします

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/usr/local/sbin/sshd
/usr/local/nginx/sbin/nginx
/etc/init.d/fcgiwrap
exit 0

このスクリプトを実行します

root@ubuntu:/# /etc/init.d/fcgiwrap 
root@ubuntu:/#
root@ubuntu:/# ps aux | grep fcg
root       2174  0.0  0.1   6444  1324 pts/1    S    15:59   0:00 /usr/local/sbin/fcgiwrap
root      14500  0.0  0.0   6444   672 pts/1    S    16:58   0:00 /usr/local/sbin/fcgiwrap
root      14502  0.0  0.2  15956  2228 pts/1    S+   16:59   0:00 grep --color=auto fcg
root@ubuntu:/#

起動後、cgi.sockファイルが/ tmpディレクトリに生成されます。起動ユーザーがrootであることに注意してください。

インストールが完了しました。今度はnginxを構成する必要があります

confディレクトリのnginx.confファイルに次の設定を追加します

 server {
        listen      8000;
        server_name localhost;
        root /home/git/repo;

        client_max_body_size 100m;

        auth_basic "git";
        auth_basic_user_file /usr/local/nginx/conf/pass.db;

        location ~(/.*) {
           fastcgi_pass  unix:/tmp/cgi.sock;
           fastcgi_param SCRIPT_FILENAME   /usr/local/libexec/git-core/git-http-backend;
           fastcgi_param PATH_INFO         $1;
           fastcgi_param GIT_HTTP_EXPORT_ALL "";
           fastcgi_param GIT_PROJECT_ROOT  /home/git/repo;
           fastcgi_param REMOTE_USER $remote_user;
           include fastcgi_params;
        }
     }

listen 8000は、ポート8000​​でリッスンすることを意味します

server_namelocalhostはドメイン名localhostを表します

root / home / git / repoは、要求されたパスが/ home / git / repoの下で一致することを意味します

たとえばhttp:// localhost:8000 /blog.gitと一致するディレクトリは/home/git/repo/blog.gitです。

auth_basic "git"は、ユーザー名がgitとして検証されることを意味します(検証が不要な場合は、記入してください)

auth_basic_user_file /usr/local/nginx/conf/pass.dbは、gtpasswdによってgitとそのパスワード用に生成されたキーファイルです。htpasswdがインストールされていない場合は、オンライン生成を使用してファイルをここにコピーできます(確認する必要がない場合は記入してください)

オンラインでURLを生成するhttp://tool.oschina.net/htpasswd

 

 

root@ubuntu:/usr/local/nginx/conf# echo "git:AWoU4Acdd8XLM" >> pass.db
root@ubuntu:/usr/local/nginx/conf#

もう1つ注意すべき点は、fastcgi_param SCRIPT_FILENAME / usr / local / libexec / git-core / git-http-backendです。パスが正しい場合、git-http-backendがどこにあるかわからない場合は、検索できます。 。

fastcgi_pass unix:/tmp/cgi.sockは、以前に起動スクリプトを実行した後に生成されたファイルパスです。

ファイルを保存してnginxを再起動します

root@ubuntu:/usr/local/nginx/conf# ps aux | grep nginx
root       2229  0.0  0.0  22444   456 ?        Ss   16:11   0:00 nginx: master process ../sbin/nginx
root       2230  0.0  0.3  22836  3052 ?        S    16:11   0:00 nginx: worker process
root      14546  0.0  0.2  15956  2172 pts/1    S+   17:23   0:00 grep --color=auto nginx
root@ubuntu:/usr/local/nginx/conf#

ワーカープロセスのユーザーはrootであり、nginxのデフォルトはnobodyであることに注意してください。構成を変更してくださいnginx.conf

最初の行に追加

#user  nobody;
user  root;
worker_processes  1;

再起動すると、git関連の操作にhttpプロトコルを使用できるようになります

Administrator@WL /d/workspace/wl/study/service/email-service (master)
$ git clone http://192.168.245.128:8000/blog.git
Cloning into 'blog'...
Username for 'http://192.168.245.128:8000': git
Password for 'http://[email protected]:8000':
remote: Counting objects: 2312, done.
remote: Compressing objects: 100% (1573/1573), done.
remote: Total 2312 (delta 680), reused 2114 (delta 594)R
Receiving objects: 100% (2312/2312), 8.88 MiB | 0 bytes/s, done.
Resolving deltas: 100% (680/680), done.

参照https://blog.csdn.net/bb2210083/article/details/82455747 

       https://www.howtoforge.com/tutorial/ubuntu-git-server-installation/

おすすめ

転載: blog.csdn.net/name_is_wl/article/details/86705032