CentOS下配置apache+gitweb

GitWeb支持多个版本库,可以对多个版本库进行目录浏览(包括历史版本),可以查看文件内容,查看提交历史,提供搜索及 RSS feed支持,也可以提供目录文件的打包下载等。可以看https://git.kernel.org/上的GitWeb示例。
 
1,使用yum安装Apache服务(安装配置文件的默认路径为/etc/httpd/conf/httpf.conf
     yum -y install httpd
 
2,配置防火墙,开启80端口供客户端浏览
     vim /etc/sysconfig/iptables
     添加下面的红色字体的一行:
     -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
     # Firewall configuration written by system-config-firewall
     # Manual customization of this file is not recommended.
  *filter
  :INPUT ACCEPT [0:0]
  :FORWARD ACCEPT [0:0]
  :OUTPUT ACCEPT [0:0]
  -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  -A INPUT -p icmp -j ACCEPT
  -A INPUT -i lo -j ACCEPT
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
  -A INPUT -j REJECT --reject-with icmp-host-prohibited
  -A FORWARD -j REJECT --reject-with icmp-host-prohibited
 
配置完毕之后重启防火墙
service iptables restart
 
3,启动Apache服务
     service httpd start
     返回如下信息:
          Starting httpd: httpd: apr_sockaddr_info_get() failed for tong
          httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
     注意:在这里是可以启动的,但是报错,因为Apache服务器的配置文件中还没有添加ServerName参数。
 
4,添加主机名并添加到Apache配置文件的ServerName参数中
     查看主机名命令:hostname
     编辑Apache配置文件
          vim /etc/httpd/conf/httpd.conf
          找到#ServerName www.example.com:80
          改成ServerName {hostname}:80
          
          #ErrorLog logs/error_log  #注释此行,添加下面这行
          ErrorLog "|rotatelogs /var/log/httpd/error_log%Y%m%d.log 86400 480"  #每天单独生成一个日志文件
          #CustomLog logs/access_log common  #注释此行,添加下面这行
          CustomLog "|rotatelogs /var/log/httpd/access_log%Y%m%d.log 86400 480" common  #每天单独生成一个日志文件       
 
     重启Apache服务
          service httpd restart
 
 
5,使用yum安装gitweb,默认安装路径为/var/www/git,配置文件路径为/etc/gitweb.conf
     yum install gitweb
     git的配置参照《Git服务器安装-SSH协议篇》
     
     编辑gitweb配置文件
     vim /etc/gitweb.conf
     找到
     #our $projectroot = "/var/lib/git";
     改成
     $projectroot = "/home/git";#git仓库的上级目录,根据自己实际情况来
     
6,配置Apache
  vim /etc/httpd/conf/httpd.conf
     最后一行添加如下内容
    #配置gitweb
<VirtualHost *:80>
    ServerName gitserver
    DocumentRoot /var/www/git
    <Directory /var/www/git >
        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
        AllowOverride All
        order allow,deny
        Allow from all
        AddHandler cgi-script cgi
        DirectoryIndex gitweb.cgi
    </Directory>
</VirtualHost>
保存,重启Apache服务
service httpd restart
 
 
7,可能出现的问题
     经过上面的配置后,客户端浏览http://serverip ,就可以浏览我们配置的所有git仓库了,如果页面显示404 projects found,那么注意两个问题:
     1,git仓库以及上级目录的权限,755
     2,关闭RELinux服务
          setenforece 
原文地址:https://www.cnblogs.com/startcaft/p/6698258.html