cnetos nginx apache git服务器

git

[TOC]

cnetos nginx apache git服务器

参考:

Configure Git Server with HTTP on CentOS 8
Git: HTTPS Repository + Access Control
在Linux上用Apache搭建Git服务器

在centos上搭建git http服务器,试验了gitlib,没有成功(组件比较庞大),并且gitlib没有提供arrch64架构安装包。
后来决定采用git+apache的方式(git+nginx配置比较复杂),使用nginx做反向代理(我的80端口已经被nginx占用)

基本步骤:

  • 安装git,apache
sudo yum install git git-core httpd
  • 配置git仓库存储目录GIT_DIR,(apache配置中GIT_PROJECT_ROOT使用)

仓库初始化脚本:/usr/sbin/git-create-repo

#!/bin/bash
GIT_DIR="/home/git"
REPO_NAME=$1
mkdir -p "${GIT_DIR}/${REPO_NAME}.git"
cd "${GIT_DIR}/${REPO_NAME}.git"
git init --bare &> /dev/null
touch git-daemon-export-ok
cp hooks/post-update.sample hooks/post-update
git config http.receivepack true
git config http.uploadpack true
git update-server-info
chown -Rf apache:apache "${GIT_DIR}/${REPO_NAME}.git"
echo "Git repository '${REPO_NAME}' created in ${GIT_DIR}/${REPO_NAME}.git" 
sudo chmod +x /usr/sbin/git-create-repo
  • 创建git验证账户
sudo htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd 
sudo chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
sudo chmod 640 /etc/httpd/conf.d/git-team.htpasswd
#注:添加用户指令
sudo htpasswd -b /etc/httpd/conf.d/git-team.htpasswd  
  • 修改/etc/httpd/conf/http.conf,增加git虚拟路径
Listen 8089

# 文件末尾追加

        ServerName git.cnblogs.com
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv GIT_PROJECT_ROOT /home/git
        ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
        
                AuthType Basic
                AuthName "Git"
                AuthUserFile /etc/httpd/conf.d/git-team.htpasswd
                Require valid-user
        

  • 修改nginx 配置文件
    csdn: 关于使用Git的时候出现"HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large"的解决方法
# nginx.conf
client_max_body_size 2m;

server {
    listen 80
    ……
    location ^~ /git/{
        proxy_pass http://127.0.0.1:8089/git/;
    }
    ……
}
  • 测试
sudo git-create-repo test
git clone http://localhost/git/test.git

你可能感兴趣的:(cnetos nginx apache git服务器)