在Linux上用Apache搭建Git服务器

简介: 在Linux上用Apache搭建Git服务器   最近在学Linux,终于在Linux上用Apache搭建起了Git服务器,在此记录一下。 服务器:阿里云服务器 Linux版本:CentOS 6.

在Linux上用Apache搭建Git服务器

 

最近在学Linux,终于在Linux上用Apache搭建起了Git服务器,在此记录一下。

服务器:阿里云服务器

Linux版本:CentOS 6.5

Apache版本:Apache/2.2.15

Git版本:git 1.7.1

Git访问方式:基于http的基本验证(非SSL)

Apache的安装

1. 安装Apache软件:yum install httpd

2. 设置Apache在服务器启动时运行:chkconfig --levels 235 httpd on

Git的安装与配置

1. 安装git

yum install git

2. 安装 git-core(为了使用git-http-backend——支持git的CGI程序,apache支持git就靠它)

yum install git-core

3. 创建存放git repository的文件夹,比如这里是/home/git

cd /home && mkdir git && cd git

4. 创建一个空的项目

mkdir git-test && cd git-test

5. 修改上一步创建的文件夹git-test的所有者与所属群组,要让apache能读/写这个文件夹

chown -R apache:apache . 

chown命令使用帮助:每天一个linux命令(30): chown命令

Apache的配置

1. 创建用于git用户验证的帐户(用户帐户由apache管理)

1.1 创建新用户

htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>

然后输入该用户要使用的密码。

1.2 修改git-team.htpasswd文件的所有者与所属群组

chown apache:apache /etc/httpd/conf.d/git-team.htpasswd

1.3 设置git-team.htpasswd文件的访问权限

chmod 640 /etc/httpd/conf.d/git-team.htpasswd

chmod命令使用帮助:每天一个linux命令(27):linux chmod命令

2. 修改apache配置文件httpd.conf

2.1 用vim打开httpd.conf:vi /etc/httpd/conf/httpd.conf

2.2 将光标移至文件结尾:0G

2.3 添加如下的内容:

复制代码
<VirtualHost *:80>
        ServerName git.cnblogs.com
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv GIT_PROJECT_ROOT /home/git
        ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
        <Location />
                AuthType Basic
                AuthName "Git"
                AuthUserFile /etc/httpd/conf.d/git-team.htpasswd
                Require valid-user
        </Location>
</VirtualHost>
复制代码

ServerName是git服务器的域名

/home/git是代码库存放的文件夹

ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend

AuthUserFile是验证用户帐户的文件

2.4 保存并退出:x

3. 重启apache使设置生效

service httpd restart

客户端访问Git服务器

运行以下命令签出git-test项目:

git clone http://git.cnblogs.com/git/git-test

输入用户名与密码,如果输出下面的信息,就说明签出成功。

remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.

 

参考资料:

Git server setup on linux using smart HTTP

Git: HTTPS Repository + Access Control

Setting up an SSL secured Webserver with CentOS

目录
相关文章
|
10天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
13天前
|
Linux
linux下搭建tftp服务器教程
在Linux中搭建TFTP服务器,需安装`tftp-server`(如`tftpd-hpa`)。步骤包括:更新软件包列表,安装`tftpd-hpa`,启动并设置开机自启,配置服务器(编辑`/etc/default/tftpd-hpa`),添加选项,然后重启服务。完成后,可用`tftp`命令进行文件传输。例如,从IP`192.168.1.100`下载`file.txt`: ``` tftp 192.168.1.100 &lt;&lt;EOF binary put file.txt quit EOF ```
28 4
|
28天前
|
Linux Shell 网络安全
【Shell 命令集合 网络通讯 】Linux 与SMB服务器进行交互 smbclient命令 使用指南
【Shell 命令集合 网络通讯 】Linux 与SMB服务器进行交互 smbclient命令 使用指南
40 1
|
6天前
|
Linux 数据安全/隐私保护
Linux基础与服务器架构综合小实践
【4月更文挑战第9天】Linux基础与服务器架构综合小实践
1192 6
|
16天前
|
Ubuntu Linux Apache
linux下apache2更换目录
linux下apache2更换目录
|
18天前
|
Ubuntu Linux 虚拟化
【Linux】ubuntu安装samba服务器
【Linux】ubuntu安装samba服务器
|
18天前
|
Linux
Linux安装bind9搭建自己的域名服务器
Linux安装bind9搭建自己的域名服务器
11 0
|
21天前
|
网络协议 Linux 网络安全
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
17 0
|
28天前
|
Shell Linux 开发工具
【Shell 命令集合 系统管理 】Linux 查看当前Git仓库的提交历史 gitps命令 使用指南
【Shell 命令集合 系统管理 】Linux 查看当前Git仓库的提交历史 gitps命令 使用指南
14 0
|
28天前
|
网络协议 安全 Shell
【Shell 命令集合 系统设置 】Linux 从远程时间服务器获取当前日期和时间 rdate命令 使用指南
【Shell 命令集合 系统设置 】Linux 从远程时间服务器获取当前日期和时间 rdate命令 使用指南
33 0

热门文章

最新文章