You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

跳板服务器下PHP服务器连接GitHub执行git pull故障求助

解决跳板服务器后PHP服务器连GitHub git pull挂起的问题

先确认核心连通性问题

在PHP服务器上执行以下命令,验证能否直接访问GitHub:

  • 测试HTTPS端口:telnet github.com 443
  • 测试SSH端口:telnet github.com 22
    如果命令挂起无响应,说明PHP服务器无法直接访问GitHub,必须通过跳板服务器转发流量,这是导致git操作挂起的根本原因。

方法一:配置SSH方式(推荐,无需重复验证)

你已完成SSH密钥的生成与GitHub配置,只需添加跳板转发规则即可:

  1. 在PHP服务器的~/.ssh/config文件中添加配置(文件不存在则新建):
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519  # 你生成的密钥文件路径
    # 跳板支持新版OpenSSH时用这条
    ProxyJump 跳板用户名@跳板IP:跳板SSH端口
    # 跳板是旧版OpenSSH时改用这条
    # ProxyCommand ssh -W %h:%p 跳板用户名@跳板IP:跳板SSH端口
  1. 保存后测试连通性:
    ssh -T git@github.com
    若返回Hi 你的GitHub用户名! You've successfully authenticated, but GitHub does not provide shell access.,说明配置生效,此时执行git pull即可正常拉取代码。

方法二:配置HTTPS方式

如果坚持使用HTTPS,需要让git通过跳板代理访问:

  1. 先通过SSH建立本地隧道,将本地端口流量转发到跳板:
    ssh -L 1080:github.com:443 跳板用户名@跳板IP

  2. 配置git使用该代理(可全局或仅针对GitHub):

# 全局代理配置
git config --global https.proxy http://localhost:1080
git config --global http.proxy http://localhost:1080

# 仅针对GitHub的代理配置(推荐)
git config --global http.https://github.com.proxy http://localhost:1080
git config --global https.https://github.com.proxy http://localhost:1080
  1. 拉取代码时,推荐使用GitHub个人访问令牌(PAT)代替密码:在GitHub的「Settings->Developer settings->Personal access tokens」生成令牌,权限勾选repo,输入令牌即可完成验证。

额外注意事项

  • 先确认跳板服务器本身能正常访问GitHub(在跳板上测试git pull或ssh -T git@github.com),若跳板也无法访问,需先解决跳板的网络问题。
  • 使用SSH方式时,建议将PHP服务器的公钥添加到跳板服务器的~/.ssh/authorized_keys中,实现免密登录跳板,避免每次git操作都输入跳板密码。

内容的提问来源于stack exchange,提问作者Potney Switters

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 00:05:03