Setup a private http/nginx based GIT server

原文:http://aaba.me/blog/2014/03/setup-a-private-http-nginx-based-git-server.html

https://doomzhou.github.io/git/linux/2016/03/30/git-over-http-by-nginx.html

参考:http://beginor.github.io/2016/03/12/http-git-server-on-nginx.html

? Downgrade Lightroom 5 catalog back to Lightroom 4 | Home | jsp tag属性的动态求值 ?

March 22, 2014

Setup a private http/nginx based GIT server

搭建一个私有的GIT服务器,我们的需求不多:

  • http访问,使用nginx
  • web浏览界面
  • 简单的http base验证

操作系统为某个发行版的debian, 很多无关的细节都会略过,会有一些简单nginx的fastcgi配置说明。

查了很多资料,得出这些结论:

  • 使用git-http-backend 支持客户端访问,支持smart HTTP protocol
  • 使用gitweb 支持浏览器访问
  • 以上两个模块是普通的cgi,需要用fcgiwrap包装成fast-cgi
  • 可以使用nginx的fast-cgi支持
  • nginx的fast-cgi是代理,真正的fastcgi进程需要使用spawn-fcgi启动

启动spawn-fcgi

这里指定了监听的端口(9001),进程(2个,可以根据实际需要增加),最后一个参数是fcgiwrap的位置

spawn-fcgi -a 127.0.0.1 -p 9001 -F 2 /usr/local/sbin/fcgiwrap

debian默认的fcgiwrap好像有些问题,按照别人的[经验](http://stackoverflow.com/questions/14304922/nginx-fcgiwrapper-error-cannot-get-script-name)自己安装了一个。 这里启动的fcgiwrap进程监听在9001端口,nginx使用fastcgi的协议和它们交互,执行的真正脚本通过fcgi参数传过来,稍后就会配置到。 **安装好git, gitweb,创建git目录**

mkdir /data/git

修改 /etc/gitweb.conf ,gitweb需要知道代码放在哪里

# path to git projects (.git)
$projectroot = "/data/git";

**配置nginx** 配置文件里提到的auth_basic_user_file文件,可以用htpasswd(apache2)生成

server {
    listen       80;
    server_name  my_git_server.com;

    # gitweb的非cgi资源
    location ~ \.(png|css|js)$ {
        root /usr/share/gitweb;
    }
    # gitweb
    location /gitweb {
        auth_basic "Restricted";
        auth_basic_user_file /path_to_passwd;
        # fcgiwrap is set up to listen on this host:port
        fastcgi_pass  127.0.0.1:9001;
        include       fastcgi_params;
        # fcgiwrapper执行这个文件
        fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/index.cgi;
    }

    # git client
    location / {
        auth_basic "Restricted";
        auth_basic_user_file /path_to_passwd;
        # fcgiwrap is set up to listen on this host:port
        fastcgi_pass  127.0.0.1:9001;
        include       fastcgi_params;
        # fcgiwrapper执行这个文件
        fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
        # export all repositories under GIT_PROJECT_ROOT
        fastcgi_param GIT_HTTP_EXPORT_ALL "";
        # git目录
        fastcgi_param GIT_PROJECT_ROOT    /data/git;
        fastcgi_param PATH_INFO         $1;
        # 把用户带上,否则push会失败
        fastcgi_param REMOTE_USER    $remote_user;
    }
}

按照上面步骤,一个基本可用的GIT就准备好了,如果你遇到了一些问题,比如,访问gitweb返回403错误,一般都出现在fcgiwrapper的执行上,可以把spawn-fcgi使用-n参数启动,看错误输出。

新建项目

在/data/git目录

$ mkdir my-new-repo.git
$ cd my-new-repo.git
$ git --bare init

切换到gitweb,就可以看到了。如果要提交代码,记得检查spawn-fcgi启动的用户要有写入/data/git目录权限。

---------------------------------------------------------------------------------------------------------------------------------------------

在 Ubuntu 系统上配置 Nginx Git 服务器

多年前发表过一篇在 Windows 系统上配置 Apache Git 服务器的博文, 主要是用 Apache 的 Basic 认证 + git-http-backend 实现, 现在需要在公司的 vps 上再部署一个类似的简单 git 服务器, 这次的软件环境如下:

  • Ubuntu 14.04.4 LTS
  • nginx/1.4.6 (Ubuntu)
  • git version 1.9.1

使用 git-http-backend 搭建 git 服务的原理都是类似的, 主要是利用 web 服务器 (apache/nginx) 进行用户认证, 并将用户信息传递给 CGI 程序 git-http-backend , 从而实现通过 http 完成 git 操作。

安装 git-core、 nginx 和 fcgiwrap

输入下面的命令安装需要的这三个软件包:

apt-get install git-core nginx fcgiwrap

配置 nginx

我的目的是在 nginx 的默认网站下添加一个虚拟目录 /git/ , 通过访问 /git/xxx.git 的形式来访问服务器上的 xxx.git 代码库, 这就需要修改一下 nginx 默认网站的配置文件 /etc/nginx/sites-available/default , 添加下面的信息:

# 配置以 /git 开始的虚拟目录
location ~ /git(/.*) {
    # 使用 Basic 认证
    auth_basic "Restricted";
    # 认证的用户文件
    auth_basic_user_file /etc/nginx/passwd;
    # FastCGI 参数
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;
    fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    # git 库在服务器上的跟目录
    fastcgi_param GIT_PROJECT_ROOT    /var/git-repos;
    fastcgi_param PATH_INFO           $1;
    # 将认证用户信息传递给 fastcgi 程序
    fastcgi_param REMOTE_USER $remote_user;
    # 包涵默认的 fastcgi 参数;
    include       fastcgi_params;
    # 将允许客户端 post 的最大值调整为 100 兆
    max_client_body_size 100M;
}

创建 nginx 认证用户文件

参考 nginx ngx http auth basic module , 用户认证文件格式如下:

# comment
name1:password1
name2:password2:comment
name3:password3

可以使用 htpasswd 命令创建用户, 如果服务器上没有这个命令的话, 可以输入命令 apt-get install apache2-utils 来安装这个命令, 安装了这个命令之后, 就可以使用它来创建认证用户了, 比如要创建用户 user1, 输入命令如下:

htpasswd /etc/nginx/passwd user1

然后根据提示输入密码就可以了。

创建 git 代码库

上面配置的 git 跟目录是 /var/git-repos , 我们在这个目录下初始化一个空的代码库, 命令如下:

cd /var/git-repos
git init --bare test.git

注意检查一下 test.git 的权限, 如果权限不足的话, 使用这个命令设置一下权限:

chmod a+rw -R test.git

重启 nginx 并测试

输入命令重启 nginx 并测试 git 服务:

nginx -s reload
git clone http://server-name/git/test.git
时间: 2024-08-01 21:33:54

Setup a private http/nginx based GIT server的相关文章

Setup Git Server in CentOS 6.3

0. Environment: Server machine: CentOS 6.3 x86 Client machine: Windows 10 Pro x86_64 1. Install ssh server [server machine shell]#yum install openssh openssh-server#chkconfig sshd on #/etc/init.d/sshd start 2. Create user git [server machine shell] #

centos 安装git server

1.yum install lrzsz wget git 2.安装gitosis:gitosis为Git用户权限管理系统,通过管理服务端的/home/git/.ssh/authorized_key文件来执行对用户权限的管理,是一个python模块包 #yum install python python-setuptools #git clone git://github.com/res0nat0r/gitosis.git #cd gitosis/ #python setup.py install

ubuntu Gitolite管理git server代码库权限

公司代码库用Git,全部用SSH认证,多个代码库多个用户,权限管理是个头疼的问题,今天终于有空测试下Gitolite, Gitolite是在Git之上的一个授权层,依托sshd或者httpd来进行认证.(概括:认证是确定用户是谁,授权是决定该用户是否被允许做他想做的事情). Gitolite允许你定义访问许可而不只作用于仓库,而同样于仓库中的每个branch和tag name.你可以定义确切的人(或一组人)只能push特定的"refs"(或者branches或者tags)而不是其他人.

centos6 配置 nginx + fcgiwrap + git

安装源 wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh epel-release*rpm yum install fcgi-devel spawn-fcgi -y 编译安装fcgiwrap git clone git://github.com/gnosek/fcgiwrap.git cd fcgiwrap autoreconf -i ./configure make m

CentOS 7 下 JDK1.8+Maven+Nginx+MySql+Git+Redis环境安装

CentOS 7 下 JDK1.8 Maven Nginx MySql Git Redis环境安装 安装目录准备 新建data目录,用来放下载的软件 mkdir -p /data 切换到该data目录 cd /data JDK1.8安装 JDK下载 如果需要用户密码,注册一个即可 用winSCP上传到服务器data目录下 解压文件 tar -zxvf jdk-8u211-linux-x64.tar.gz Maven安装 maven下载 wget http://mirrors.gigenet.co

已经在Git Server服务器上导入了SSH公钥,可用TortoiseGit同步代码时,还是提示输入密码?

GitHub虽好,但毕竟在国内访问不是很稳定,速度也不快,而且推送到上面的源码等资料必须公开,除非你给他交了保护费:所以有条件的话,建议大家搭建自己的Git Server.本地和局域网服务器都好,不信你试试,那速度,怎一个爽字了得! 默认情况下,使用TortoiseGit同步代码,每次都需要输入用户名和密码,但为了方便可以在客户端创建ssh密钥,用于服务器端和客户端的认证(详细过程大家可参考这里),但有时会出现“ 已经在Git Server服务器上导入了SSH公钥,可用TortoiseGit同步

Git Server搭建

本文原文出处: http://blog.csdn.net/bluishglc/article/details/49310125 严禁任何形式的转载,否则将委托CSDN官方维护权益! 1 参考 所有相关细节均可以从该文档出获取: http://git.oschina.net/progit/4-%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git.html# 2 安装 Git并不存在Server端和Clint端之分,在Git Server上安装的也还是G

.net版Git Server --- bonobo

官网地址: https://bonobogitserver.com/ Demo: http://demo.bonobogitserver.com/Home/LogOn  登入admin:admin Code: https://github.com/jakubgarfield/Bonobo-Git-Server  安装 以下步骤是在 Windows 2008 Server and IIS 7下的安装.对于更高版本的平台也同样适用 (Windows Server 2012 and IIS 8.0+)

Bonbo Git Server

Install This page covers simple Bonobo Git Server installation. Be sure to check prerequisites page before installation and for other sections visit the documentation page. The following steps covers an installation with Windows 2008 Server and IIS 7