• liunx(Ubuntu)安装git服务端及nginx实现http访问git


    参考 https://www.pianshen.com/article/9462214176/

    http://www.360doc.com/content/17/1030/11/412471_699395136.shtml

    1.安装git 这里暂时不考虑gitlab ,因为是私人研究用的,暂时不需要管理后台

    apt install git

    2.设置git主目录, 并新建git帐号 (归属于git组) 且将git权限添加到主目录

    mkdir -p /usr/local/gitrepository
    useradd -g git git
     chown -R git:git  /usr/local/gitrepository

    3.创建配置中心仓库

    cd /usr/local/gitrepository
    mkdir config-repo
    
    # git初始化
    
    git init --bare config-repo/
    
    # 再次设置权限
    chown -R git:git config-repo

    4.这时从客户端的tortoiseGit上已经可以git clone 该项目了

    url:  git@192.168.1.22:usr/local/gitrepository/config-repo

    但是如果想用IP地址访问 如 http://192.168.1.22:8080/config-repo 那么就需要 下面的步骤了

    5.安装 nginx 

    apt install nginx

    安装好的目录在 /etc/nginx/

    6.安装 fcgiwrap  (即通过访问一个 http 请求,运行一下某台远程机器上的一个 shell 脚本)

    apt install fcgiwrap

    7. 找到对应的 配置文件

    先找到对应的git-http-backend  和  fcgiwrap.socket  文件的位置 (可以用find / -name git-http-backend 命令查找)

     在我的机器上位置分别在  /usr/lib/git-core/git-http-backend  和 /run/fcgiwrap.socket 

    8.配置nginx.conf文件 , /etc/nginx/nginx.conf 

    在http项目下增加 server 模块

    server {
            listen       8000;
            server_name  localhost;
    
            root /usr/local/gitrepository;
            auth_basic off;
            auth_basic_user_file off;
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
        location ~ (/.*) {
           
            fastcgi_pass  unix:/run/fcgiwrap.socket;
            fastcgi_connect_timeout 24h;
            fastcgi_read_timeout 24h;
            fastcgi_send_timeout 24h;
            fastcgi_param SCRIPT_FILENAME  /usr/lib/git-core/git-http-backend;
            fastcgi_param PATH_INFO         $1;
            fastcgi_param GIT_HTTP_EXPORT_ALL "";
            fastcgi_param GIT_PROJECT_ROOT  /usr/local/gitrepository;
            fastcgi_param REMOTE_USER $remote_user;
            include fastcgi_params;
        }

    其中 fastcgi_pass  和  fastcgi_param SCRIPT_FILENAME  对应的值,就是在第7步找到的配置文件地址

    9.重启nginx

    /usr/sbin/nginx -s stop

    /usr/sbin/nginx

    10.在客户端使用 git clone  

     地址为: http://192.168.1.22:8080/config-repo  (config-repo默认只支持读取权限,所以这里只支持fetch/pull等读取操作) 这些操作对于配置中心来说是足够了

    一般情况都是可以的

    11.如果要使用密码来验证就需要在nginx.conf里如下配置了

            auth_basic "git";
            auth_basic_user_file /etc/nginx/conf.d/pass.db;

    pass.db 通过 https://tool.lu/htpasswd/ 来生成 

    如用户名 git ,密码 1234567! 使用 Crypt方式 生成 结果为  git:MTMw57.B1VYIY  (注意密码只有前8位有效,超出8位的会被忽略)

    然后保存到  /etc/nginx/conf.d/pass.db 文件中

    echo "git:MTMw57.B1VYIY" >> pass.db
  • 相关阅读:
    waitkey();
    一、数组--删除排序数组中的重复项
    core组件进阶
    opencv数据结构与基本绘图
    highGUI图形用户界面
    合并两个有序链表
    字符串
    内存
    9位运算
    8设备文件
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/12937226.html
Copyright © 2020-2023  润新知