前言

作为giteaForBT开发者,最近有用户遇到了一个反向代理的坑,那就是代理后能访问也能克隆,但是push数据量一大就会出现Request Entity Too Large报错,最后查了好多资料找到解决方案,特此做个记录。

默认反向代理

location  ~*
{
    proxy_pass http://localhost:3000;
    proxy_set_header        Host $host;
    proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr; # 设置请求源地址
        proxy_set_header X-Forwarded-Proto $scheme; # 设置Http协议
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
}
location /
{
    proxy_pass http://localhost:3000;
    proxy_set_header        Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr; # 设置请求源地址
    proxy_set_header X-Forwarded-Proto $scheme; # 设置Http协议
    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache

            add_header Cache-Control no-cache;
    expires 12h;
}

实测反向代理可用,需将如下代码 添 加 至 宝 塔 站 点 的 [ 伪 静 态 ] 中 即 可 \color{red}添加至宝塔站点的[伪静态]中即可 添加至宝塔站点的[伪静态]中即可,克隆的时候需要手动将localhost:替换成自己的实际域名【将服务器对外域名设置成你的实际域名(默认80端口)即可无需此步骤】即可,http代理模式下实测可提交代码。 但 是 上 面 这 个 方 法 就 是 会 出 现 p u s h 时 报 错 R e q u e s t E n t i t y T o o L a r g e \color{red}但是上面这个方法就是会出现push时报错Request Entity Too Large 但是上面这个方法就是会出现push时报错RequestEntityTooLarge

解决方法

#设置最大为提交 50M如果推送报错Request Entity Too Large则需要修改client_max_body_size
client_max_body_size 50m;

完整代理配置

client_max_body_size 50m;
location  ~*
{
    proxy_pass http://localhost:3000;
    proxy_set_header        Host $host;
    proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr; # 设置请求源地址
        proxy_set_header X-Forwarded-Proto $scheme; # 设置Http协议
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
}
location /
{
    proxy_pass http://localhost:3000;
    proxy_set_header        Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr; # 设置请求源地址
    proxy_set_header X-Forwarded-Proto $scheme; # 设置Http协议
    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache

            add_header Cache-Control no-cache;
    expires 12h;
}