[gogs]求一个Nginx反向代理的可用配置

2023-12-15 763 views
6

因为放在开发板上面,暴露在外网,我需要用Nginx反代Gogs, 但是因为开发板性能不太强,Nginx经常超时。

我用的master分支的代码,gogs 0.6.7.0829 Beta

我现在的配置是

server {
    listen      443 ssl spdy;
    include /etc/nginx/ssl.conf;
    server_name _;

    proxy_set_header   Host              $http_host;
        proxy_set_header   X-Real-IP         $remote_addr;

        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Frame-Options   SAMEORIGIN;

    proxy_redirect  off;

    keepalive_timeout 60;
    sendfile on;
    send_timeout 600s;

        location /git/ {
        client_body_buffer_size 32K;
        client_max_body_size 300M;

        proxy_send_timeout  86400s;
        proxy_read_timeout          86400s;
            proxy_connect_timeout   86400s;
        proxy_pass  http://gogs/;
    }

}

可用看见 超时时间得设置非常长 而 client_max_body_size 的话,和postBuffer 的设置有关;

另外

我想镜像github上的源时超时了

2015/09/01 16:51:55 [...routers/repo/repo.go:91 handleCreateError()] [E] MigratePost: git clone --mirror: Process execution timeout
[Macaron] Completed /repo/migrate 500 Internal Server Error in 43m43.314713378s

而在我自己提交代码的时候有一堆的 401 不知道正不正常

[Macaron] Started GET /goagent/goagent.git/info/refs?service=git-upload-pack for 58.210.145.74
[Macaron] Completed /goagent/goagent.git/info/refs?service=git-upload-pack 401 Unauthorized in 77.58497ms
[Macaron] Started GET /goagent/goagent.git/info/refs?service=git-upload-pack for 58.210.145.74
[Macaron] Completed /goagent/goagent.git/info/refs?service=git-upload-pack 401 Unauthorized in 21.30125ms
[Macaron] Started GET /goagent/goagent.git/info/refs?service=git-upload-pack for 58.210.145.74
[Macaron] Completed /goagent/goagent.git/info/refs?service=git-upload-pack 200 OK in 1.982112301s

还有

不知道是不是放在二级目录下面的原因,自己镜像自己的源时,似乎没法获取Username

[Macaron] Started POST /repo/migrate for 192.168.8.1
2015/09/01 17:00:11 [T] action.NewRepoAction: goagent/dd
[Macaron] Started GET /niphor/memo.git/info/refs?service=git-upload-pack for 192.168.8.1
[Macaron] Completed /niphor/memo.git/info/refs?service=git-upload-pack 401 Unauthorized in 21.199794ms
2015/09/01 17:00:24 [...routers/repo/repo.go:91 handleCreateError()] [E] MigratePost: git clone --mirror: Cloning into bare repository '/opt/gogs/data/gogs-repositories/goagent/dd.git'...
fatal: could not read Username for 'https://dev.4do.in': No such device or address

[Macaron] Completed /repo/migrate 500 Internal Server Error in 13.304859111s

最后:

https://github.com/gogits/gogs/blob/master/models/user.go#L183

gravatar 默认链接开头是//所以,这么写所有gravatar 的头像都显示不出来了

回答

2

不过看我上面的日志好像超时了快43分钟了....

今天我用master分支的又编译了一次

gravatar 头像的好了

迁移外部仓库,克隆本机源,还是报相同的错误 比如要镜像的地址是:https://dev.mydomain.xxx/git/niphor/memo.git

[Macaron] Started GET /niphor/memo/info/refs?service=git-upload-pack for 192.168.8.1
[Macaron] Completed /niphor/memo/info/refs?service=git-upload-pack 401 Unauthorized in 38.035006ms
2015/09/04 20:16:48 [...routers/repo/repo.go:91 handleCreateError()] [E] MigratePost: git clone --mirror: Cloning into bare repository '/somepalce/gogs/data/gogs-repositories/goagent/memo2.git'...
fatal: could not read Username for 'https://dev.mydomain.xxx': No such device or address

[Macaron] Completed /repo/migrate 500 Internal Server Error in 11.679977243s
[Macaron] Started GET /img/500.png for 192.168.8.1
[Macaron] [Static] Serving /img/500.png
[Macaron] Completed /img/500.png 200 OK in 4.17621ms

另外 不能 克隆 git格式的URL? 比如:git@github.com:niphor/hexo-theme-light-kai.git,会提示URL不正确

above all 这 issue 本意是求一个Nginx的最佳配置...

1
server {
        listen 443 ssl;
        server_name try.gogs.io;
        ssl_certificate /etc/ssl/startssl/gogs.io.unified.crt;
        ssl_certificate_key /etc/ssl/startssl/gogs.io-decrypted.key;

        #要缓存文件的后缀,可以在以下设置。
        location ~ .*\.(gif|jpg|png|css|js)(.*) {
                proxy_pass http://localhost:3001;
                expires 3d;
        }

        location / {
                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_pass http://localhost:3001$request_uri;
        }
}

server {
        listen 80;
        server_name try.gogs.io;
        return 301 https://$host$request_uri;
}
5

谢谢回复,真是神速

不过在开发板上面和在服务器上面完全没法比, try.gogs.io用1s不到能镜像一个源,我BananaPro的开发板上面要15s以上... 超时没法避免...

另外 commit: 7ec991326d550957b278475057965e197f6e0324 e5b105e513cb8bfe728c451525d1d9fd7d0979eb

我看是修复migrate api的,但是我还是会500,是没完全修复吗?

9

是这样 我建了个 组织A 然后我镜像我自己的源到 组织A, 拥有者选择 组织A 必须输入账户和密码,不然就500了 因为我在ini里设置了REQUIRE_SIGNIN_VIEW = true