资讯详情

资讯详情

通过服务器中转的git push方法

公司的机器无法访问github正好有一个阿里云的服务器用阿里云服务器搭建一个git仓库中转并且公司禁止ssh连接阿里云所以这里采用的方法比较麻烦。这里先需要在阿里云上建立一个裸仓库之后为裸仓库配置remote之后他就会自动的将发送到这个仓库的更新推送到remote上主要流程主机-http 8900 端口- nginx - relay.git裸仓库 - http -github首先是服务器-github的配置# 先跳转到需要的目录之后运行 git init --bare relay.git # relay是文件名之后推送到这个仓库配置裸仓库的remote地址git remote add origin https://github.com/.......这里需要写上用户名密码但是博主这里省略了配 post-receive 钩子自动转发 GitHubcat 地址/relay.git/hooks/post-receive EOF #!/bin/bash git push origin --all git push origin --tags EOF chmod x 地址/relay.git/hooks/post-receive接下来是主机-服务器的配置默认的话是只能接受但是不能推送所以需要打开推送的命令# 允许 HTTP 推送 cd relay.git git config http.receivepack true属主给 www-dataNginx 要读写chown -R www-data:www-data 地址/relay.git安装 fcgiwrapapt install -y fcgiwrap apache2-utils systemctl enable --now fcgiwrapnginx配置转发vim /www/server/nginx/conf/nginx.confsystemctl reload nginxserver { listen 8900; server_name ip; location ~ ^/relay\.git(/.*)?$ { fastcgi_pass unix:/var/run/fcgiwrap.socket; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; fastcgi_param GIT_PROJECT_ROOT /home/user/slay2; fastcgi_param GIT_HTTP_EXPORT_ALL ; fastcgi_param PATH_INFO $uri; fastcgi_param REMOTE_USER $remote_user; } }除此之外注意云服务器的安全组放行8900端口以及防火墙放行8900端口的tcp查看端口的监听情况ss -lntp | grep 8900主机的配置主机的配置很简单只要和服务器可以连接即可git remote add ... git push relay
觉得有用,分享给同行:

为您的企业打造数字门面

稳重轻奢商务风格,端正雅致视觉,长效耐看不易过时。

立即咨询 →