nginx代理gitee

背景

若干台agv设备,这些设备都是没有公网的(无法访问百度等)。

一台服务器(ubuntu20.04)有线可以公网,无线可以实现内部通信(agv,plc等设备)。

目的

agv每一次更新代码,拉取代码等都需要切换到有公网的网络,多台agv设备切来切去很麻烦。现在要实现agv通过服务器的nginx代理gitee拉取代码。

代理服务器配置步骤

更新源

bash 复制代码
sudo apt update

下载nginx

bash 复制代码
sudo apt install nginx

配置nginx

bash 复制代码
sudo nano /etc/nginx/site-available/gitee_proxy

配置文件内容

bash 复制代码
server {
    listen 80;   #端口这里自己定义,80被用了就用别的
    server_name 192.168.50.80;

    location / {
        proxy_pass https://gitee.com;
        proxy_set_header Host gitee.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
    }
}

创建符号链接以启用新配置

bash 复制代码
sudo ln -s /etc/nginx/sites-available/gitee_proxy /etc/nginx/sites-enabled/

检查nginx配置是否正确

bash 复制代码
sudo nginx -t

重启nginx使配置生效

bash 复制代码
sudo systemctl restart nginx

AGV等其他需要代理到gitee的设备操作

bash 复制代码
git remote set-url origin http://192.168.50.80/username/repository.git
#这里的192.168.50.80就是ngixn配置server_name,ip为无网的服务器的ip
#这里的git请求由192.168.50.80服务器代理转发到gitee

检查设置是否成功

git remote -v 输出为++++http://192.168.50.80/用户名/仓库.git 则无问题++++

++++此时直接拉代码 就会提示输入用户名与密码 完成代码拉取++++

增加代理

拉取代码发现速度比较慢,网上查找后说要给gitee增加代理

git config --global https.proxy http://192.168.50.80:80

git config --global https.proxy https://192.168.50.80:80

克隆代码

git init

git clone http://192.168.50.80/repository.git

相关推荐
兔C20 小时前
Linux 命令行入门学习资料 day_2
linux·运维·服务器
枕星而眠21 小时前
【数据结构】红黑树入门指南
运维·数据结构·c++·后端
snow@li1 天前
深入理解内核与操作系统的关系
运维·服务器·microsoft
大E帝国子民11 天前
OpenCloudOS Server 9 安装 Nginx 完整指南
前端·网络·nginx
星融元asterfusion1 天前
高效网卡部署与自动化运维:EasyRoCE Toolkit NC 配置指南
运维·自动化
prettybug1251 天前
OBS背景音乐_气氛实战指南
运维·服务器
无足鸟ICT1 天前
【RHCA+】管道符
linux·运维·服务器
老约家的可汗1 天前
Linux的库制作和原理
linux·运维·服务器
技术民工之路1 天前
RAG 在真实业务项目落地全流程(从需求到上线运维)
运维
leoZ2311 天前
Skill 技能系统完全指南(四):实战 Skill——DevOps 部署
运维·devops