nginx 配置git server http clone服务,并通过反向代理访问

2023-05-16

要做一个通过踏板机的ip进行git代码的上传与下载,所以思路不是踏板机上安装nginx反向代理,并且linux服务器也需要提供http方式的访问git,ssh方向不知道怎么进行反向代理。linux服务器也需要使用nginx进行http的设置,使用httpd设置的不好使。

一在服务器上安装git

安装git及相关依赖

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
yum install git

创建用户git

adduser git       #添加用户git
passwd git        #更改git的密码

为安全考虑需要禁止该用户shell登陆

vi /etc/passwd         
#找到git的行,将/bin/bash更换为/usr/bin/git-shell
#git:x:1000:1000::/home/git:/bin/bash
git:x:1000:1000::/home/git:/usr/bin/git-shell

#查找git-shell目录
[root@localhost bin]# find / -name git-shell
/usr/bin/git-shell
/usr/libexec/git-core/git-shell


用户证书登录

cd /home/git/
mkdir .ssh
chmod 755 .ssh
touch .ssh/authorized_keys
chmod 644 .ssh/authorized_keys

然后将所有登陆用户的公钥保存在 authorized_keys 中。
就是通过ssh_gen 生成自己的密钥COPY到authorized_keys 中一行一个。

初始化仓库 /home/git/test.git

cd /home/git
git init --bare test.git             #初始化仓库
chown -R git:git test.git        #更改所属用户

Client端获取仓库

git clone git@ip地址:/home/git/test.git

至此可以通过ssh的方式下载代码库了。

HTTP方式设置

一、配置 EPEL源

sudo yum install -y epel-release
sudo yum -y update

二、安装Nginx

sudo yum install -y nginx

安装成功后,默认的网站目录为: /usr/share/nginx/html

默认的配置文件为:/etc/nginx/nginx.conf

自定义配置文件目录为: /etc/nginx/conf.d/

三、开启端口80和443

如果你的服务器打开了防火墙,你需要运行下面的命令,打开80和443端口。

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

四、安装fcgiwrap

git clone https://github.com/gnosek/fcgiwrap.git

yum install fcgi-devel autoconf automake libtool

cd fcgiwrap && autoreconf -i && ./configure && make && make install

vim /etc/init.d/fcgiwrap

#! /bin/sh
# chkconfig: 2345 55 25
DESC="fcgiwrap daemon"
DEAMON=/usr/bin/spawn-fcgi
PIDFILE=/var/run/spawn-fcgi.pid
FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=git
FCGI_GROUP=git
FCGI_EXTRA_OPTIONS="-M 0770"
OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P $PIDFILE -- $FCGI_PROGRAM"
do_start() {
 $DEAMON $OPTIONS || echo -n "$DESC already running"
}
do_stop() {
 kill -INT `cat $PIDFILE` || echo -n "$DESC not running"
}
case "$1" in
 start)
  echo -n "Starting $DESC: $NAME"
  do_start
  echo "."
  ;;
 stop)
  echo -n "Stopping $DESC: $NAME"
  do_stop
  echo "."
  ;;
 restart)
  echo -n "Restarting $DESC: $NAME"
  do_stop
  do_start
  echo "."
  ;;
 *)
  echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
  exit 3
  ;;
esac
exit 0

chmod +x /etc/init.d/fcgiwrap
chkconfig fcgiwrap on

添加 git server 的 nginx 配置

vim /etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  localhost;
	access_log /var/log/nginx/dev.access.log;
        error_log /var/log/nginx/dev.error.log;
        #root         /usr/share/nginx/html;
	location /{
	   root /home/git/;
	}
        auth_basic "git";
       auth_basic_user_file /usr/local/nginx/conf/pass.db;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }

	location ~ /git(/.*) {
          gzip off;
          root /usr/lib/git-core;
          fastcgi_pass  unix:/var/run/fcgiwrap.socket;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend;
          fastcgi_param DOCUMENT_ROOT /usr/libexec/git-core/;
          fastcgi_param SCRIPT_NAME git-http-backend;
          fastcgi_param GIT_HTTP_EXPORT_ALL "";
          fastcgi_param GIT_PROJECT_ROOT /home/git/;
          fastcgi_param PATH_INFO $1;
 	  #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
 	}
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}
systemctl start nginx
systemctl status nginx.service

五,安装spawn-fcgi

yum install spawn-fcgi
/etc/init.d/fcgiwrap start

六、receivepack

cd /home/git/test.git/
git config http.receivepack true

vim /etc/selinux/config

selinux=disabled

#重启系统
reboot

七,设置密码

yum -y install httpd-tools
mkdir /usr/local/nginx/conf/
cd /usr/local/nginx/conf/
htpasswd -c pass.db git

#输入密码

八,设置iptables

iptables -P INPUT ACCEPT
iptables -F
service iptables save


iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -s 127.0.0.1 -j ACCEPT
iptables -P INPUT DROP
service iptables save

九,下载代码

在安装有nginx的windows踏板机上下载代码

git clone http://localhost/git/test.git

以上方式在阿里云和虚拟机上都测试通过。

十,windows nginx配置


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream github {
	    server linux_server_ip;#要连接的代码服务器地址
	    keepalive 16;
    }
    server {
        listen       80;
        server_name  localhost;

        charset utf-8;

        #access_log  logs/host.access.log  main;

        #location / {
         #   root   html;
      #      index  index.html index.htm;
     #   }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
        location /{
	client_max_body_size 1024m;
	proxy_set_header Host linux_server_ip;#要连接的代码服务器地址
	#proxy_set_header X-Real-IP $remote_addr;
	#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_hide_header Strict-Transport-Security;
	proxy_pass http://github;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

nginx 配置git server http clone服务,并通过反向代理访问 的相关文章

  • Time of flight cameras(TOF carmeras)

    TOF cameras Time Of flight 新型3D图像传感器 xff0c 该传感器使用红外线或者光脉冲来估计光线从发射到检测到的时间延迟来测量距离
  • 求逆矩阵的方法

    一般求逆矩阵的方法有两种 xff0c 伴随阵法和初等变换法 但是这两种方法都不太适合编程 伴随阵法的计算量大 xff0c 初等变换法又难以编程实现 适合编程的求逆矩阵的方法如下 xff1a 1 对可逆矩阵A进行QR分解 xff1a A 61
  • 柯西列

    柯西列 xff1a 无穷数列 xff0c x1 x2 xn xn 43 1 当n为无穷大时 xff0c xn与xn 43 1的距离无穷小
  • Dynamic Feature Learning for Partial Face Recognition (CVPR 2018)

    破题 xff1a 本文提出的模型是Dynamic Feature Learning xff08 DFL xff09 本人要做的事情是Partial Face Recognition xff08 PFR xff09 摘要 xff1a DFL由
  • 安装Docker Desktop报错WSL 2 installation is incomplete的问题(解决报错)

    我们安装Docker Desktop的时候 他会问我们是否需要使用WSL2 基于Windows的Linux子系统 如果我们不适用 就会使用Hyper v虚拟机运行 不过相比于虚拟机 子系统在性能方面更加出色 在我们选择使用WSL2之后 并且
  • vs2013报错:error MSB8020: The build tools for v141 (Platform Toolset = ‘v141‘) cannot be found.

    vs2013报错 xff1a error MSB8020 The build tools for v141 Platform Toolset 61 v141 cannot be found T 原因 xff1a 该项目使用vs2017创建
  • Debian系统更新apt源

    docker search了一个tomcat的镜像 xff0c 发现是Debian系统 xff0c 里面啥啥命令都没有 xff0c 使用的这个难受啊 xff0c 于是 xff0c 强迫症犯了 xff0c 要安装相应软件 xff0c 在容器里
  • Isaac Gym(一)在Ubuntu20.04.1中安装Isaac Gym

    在Ubuntu20 04 1中安装Isaac Gym 前提1 安装 Conda1 1 下载Anaconda3安装文件1 2 运行1 3 设置路径 2 安装 Isaac Gym2 1 下载Isaac Gym安装文件2 2 解压并删除安装包2
  • 在rviz中出现For frame [laser]: Fixed Frame [laser_link] does not exist

    参考 xff1a 链接 一 激光雷达在rviz中没有显示扫描数据 二 解决方法 topic报frame transform之类错误 xff0c 就有两个办法 xff1a 1 把global fixed frame设成topic自己所在的坐标
  • ubuntu安装nerd font字体

    步骤 1 下载nerd font字体文件到某个文件夹 在网址https www nerdfonts com font downloads xff0c 找到JetBrainsMono xff0c DroidSansMono xff0c Dej
  • OpenStack计费项目CloudKitty的强化及运用

    本文转自Openstack中国社区Openstack计费项目CloudKitty的强化及运用 本文作者 xff1a Li Xiangjun 在OpenStack开发社区向 Big Tent 模式全面转型之际 xff0c 一个新的项目 Clo
  • Winpcap数据包的抓取及还原

    winpcap技术手册 xff0c 除了安装文件里doc文件下有个帮助 xff0c 这里在给一个 xff1a http www ferrisxu com WinPcap html index html 这里我们用pcap next ex 函
  • 柱面坐标变换

    在图像拍摄点固定的情况下 xff0c 对图像做柱面投影变换 xff0c 再进行配准会得到较为理想的效果 如图所示 xff0c 点P在相机所处的坐标系下的坐标为 xff0c 在像素坐标系下表示为P xff08 x xff0c y xff09
  • 几行Python代码教你zip打包

    码农一方面是码代码 xff0c 另一方面是布署服务 xff0c 传到服务器时 xff0c 文件数据较多时 xff0c 直接通过文件传输概率性会丢失文件 xff0c 最好是先压成zip包 xff0c 再传输 但是 xff0c zip包中的文件
  • 推荐一款强大的OCR工具

    大家好 xff0c 我是 jonssonyan xff0c 今天我想向大家介绍一款强大的 OCR 工具 Umi OCR 以下是它的开源地址 Umi OCR GitHub xff1a https github com hiroi sora U
  • ArXiv简介以及论文提交

    arXiv网站简介 arXiv是一个收集物理学 数学 计算机科学 生物学与数理经济学的论文预印本的网站 其中arXiv发音同 archive xff0c 因为 X 代表希腊字母 xff0c 国际音标为 kai 它于1991年8月14日成立
  • Vue中axios请求报错

    问题 xff1a axios请求成功但是还是进入catch 在请求后端接口后 xff0c 发现请求成功了 xff0c 但是却报错了 在经过排查之后 xff0c 发现后端返回的数据结构更改了 xff0c 所以导致成功的代码块内部出现错误 xf
  • lsnrctl command not found

    在linux安装完oracle时 当你遇到lsnrctl command not found等问题都不能用时 会有几种情况 1 首先你先查看下环境变量里面有没有加入oracle的配置 执行 echo ORACLE HOME 没有的话 你执行
  • CNC加工中心程序代码大全,你还不收藏吗?

    数控程序中字母的含义 O xff1a 程序号 xff0c 设定程序号 N xff1a 程序段号 xff0c 设定程序顺序号 G xff1a 准备功能 X Y Z xff1a 尺寸字符 xff0c 轴移动指令 A B C U V W xff1
  • 413 Request Entity Too Large(请求实体太大)

    最近开发时遇到了上传失败的情况 xff0c 提示 xff1a 413 Request Entity Too Large xff08 请求实体太大 xff09 因为上传通过代理服务器Nginx xff0c 因此可以 修改代理服务器Nginx

随机推荐

  • Photos(PHFetchResultChangeDetails)

    Photos PHChange Photos PHObjectChangeDetails Photos PHFetchResultChangeDetails PHFetchResultChangeDetails主要用于记录PHFetchRe
  • 远程桌面连接的时候 屏幕一闪就没了 然后不能连接上

    重启本地两个远程服务组件Remote Desktop Services和Remote Desktop Services usermode Port Redirector 如果还不行 xff0c 按下面的试试 启动注册表编辑器 Regedt3
  • 关于codeforces比赛规则介绍(转载)

    Codeforces 简称 cf 所以谈论cf的时候经常被误会成TX的那款游戏 网址 codeforces com 这是一个俄国的算法竞赛网站 由来自萨拉托夫州立大学 由Mike Mirzayanov领导的一个团队创立和维护 是一个举办比赛
  • 自制书立

    店里卖的书立简直贵的离谱 xff0c 不就是一个直角的铁片吗 xff0c 要那么多钱 索性自己做一个 xff0c 就用最便宜的衣架 xff0c 不到一元钱搞定 xff01 把衣架弯成直角 换个角度 xff0c 再来一张 完事了 xff0c
  • 连载:面向对象葵花宝典:思想、技巧与实践(27) - 动态模型设计

    类模型 指导我们如何声明类 xff0c 动态模型 指导我们如何实现类 xff01 动态模型设计一般都是在类模型设计完成后才开始 xff0c 因为动态模型设计的时候一般都需要用到类模型中的类 相对类模型来说 xff0c 动态模型要相对简单一些
  • C语言经典100题——输出“魔方阵“

    lt 1 gt 题目描述 输出 魔方阵 xff0c 所谓魔方阵是指它的每一行 每一列和对角线之和均相等 例如 xff1a 8 1 6 3 5 7 4 9 2 要求输出1 n 2的自然数构成的魔方阵 lt 2 gt 思路分析 将1放在第1行中
  • MFC中调用std::cout

    std cout很好用 xff0c 但是在MFC中 xff0c 一般的变量值输出MessageBox 来显示 xff0c 很不方便 下面就实战一下利用std cout来输出 1 利用VC 6 0 MFC App Wizard新建一个基于对话
  • estimatedRowHeight 与 self sizing cells

    estimatedRowHeight 为什么要引入estimatedRowHeight呢 xff1f 顾名思义就是预估高度 在预估高度之前 xff0c 与高度相关的属性及方法比较常用的有以下两个 xff1a rowHeight 这个属性适合
  • linux小白 折腾debian8笔记1 --Debian 8 安装与初步配置

    前言 我只是一个普通的使用linux的小白 xff0c 初步的使用ubuntu xff0c 开始折腾起Debian8 在折腾的过程中学到了不少的东西 xff0c 有感而发 xff0c 记录一下 ps 我是用我的Hp笔记本装的 因此个人不同的
  • iOS高德地图路径选择

    新公司的一个物流项目用到了高德地图的路径规划导航 之前没用过高德的路径规划 xff0c 最麻烦的是画出路径 xff0c 以及多路径情况下的点击选择路径 其实画出路径的算法在高德地图的相关demo里面有 xff0c 只要抠出来就行 我要说的是
  • 今日解决新安装的centos 8安装MYSQL提示未找到匹配的参数: mysql-community-server

    今日新安装的centos在安装mysql community server时一直报错 xff1a root 64 centos8 yum repos d yum y install mysql community server 上次元数据过
  • ios学习--给UITableViewCell动态调整高度

    在网上看到有人如此实现动态调整高度 xff1a 点击 不至于为了获取高度创建一个不需要的cell 主要有两个地方需要调整高度 xff0c 一个是自己创建的UILabel或其它 xff0c 另一个就是cell的高度 在创建cell的地方只需要
  • 【HTML5】-04 图片与链接

    图片与链接 xff1a lt DOCTYPE html gt lt html gt lt head gt lt title gt 第二页 lt title gt lt head gt lt body gt lt p gt 1 图片插入 xf
  • lanzous.com网站无法访问求解决

    一般的分享链接是https XXXXX lanzous com sssss 直接把前面的https XXXXX lanzous com改成https pan lanzou com就行 最后链接样式就是https pan lanzous co
  • C++风格_格式

    1 行长度 每一行代码字符数不超过 80 xff08 这个数是Google的指南中的 xff09 80 个字符是最大值 如果无法在不伤害易读性的条件下进行断行 那么注释行可以超过 80 个字符 这样可以方便复制粘贴 例如 带有命令示例或 U
  • TCP Server处理多Client请求的方法—非阻塞accept与select

    参看基于TCP UDP的socket代码 xff0c 同一时间Server只能处理一个Client请求 xff1a 在使用当前连接的socket和client进行交互的时候 xff0c 不能够accept新的连接请求 为了使Server能够
  • jupyter notebook下识别出虚拟环境

    在需要的虚拟环境里安装 conda span class token function install span c conda forge ipykernel 这样启动jupyter notebook就可以看到了 也可以在安装虚拟环境时就
  • VMware Ubuntu20.04设置共享文件夹

    虚拟机设置好共享文件夹后进入系统可能会找不到 xff0c 这时需要经过如下操作才能在系统中看到 vmware hgfsclient 可以在Terminal里显示出已经设置好的共享文件夹 span class token function s
  • Vim技巧-多行缩进

    向前或向后缩进4个空格 按shift 43 v组合键进入Visual Line模式 xff0c 可使用方向键选择多行 xff1b 按 lt 或 gt xff0c 进行向前或向后缩进 注 xff1a 有些设置为缩进一个Tab单位 向前或向后缩
  • nginx 配置git server http clone服务,并通过反向代理访问

    要做一个通过踏板机的ip进行git代码的上传与下载 xff0c 所以思路不是踏板机上安装nginx反向代理 xff0c 并且linux服务器也需要提供http方式的访问git xff0c ssh方向不知道怎么进行反向代理 linux服务器也