标签归档:Gitea

Gitea删除ruuner后,再次启用

从Gitea删除runner,你的runner会记录一个文件 data/.runner 像下面的内容

{
  "WARNING": "This file is automatically generated by act-runner. Do not edit it manually unless you know what you are doing. Removing this file will cause act runner to re-register as a new runner.",
  "id": 1,
  "uuid": "9915f68d-7d47-4731-b329-aa53ff8ba01f",
  "name": "runner1",
  "token": "276147af85ea87c3fce5caeef0c93012e6486e89",
  "address": "http://192.168.50.117:3000",
  "labels": [
    "runner1:host"
  ]
}

这个文件在runner的容器里面,去删除掉,就会重新注册了

Gitea 非标准端口配置代理注意点

这是官方给的例子:

server {
    ...
    location / {
        client_max_body_size 512M;
        proxy_pass http://localhost:3000;
        proxy_set_header Connection $http_connection;
        proxy_set_header Upgrade $http_upgrade;
        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 X-Forwarded-Proto $scheme;
    }
}

你访问Gitea的域名为非标端口(80,443)时,需要在Host上加上端口

server {
    ...
    location / {
        proxy_set_header Host $host:你的端口;
        ...
    }
}

原因是源码里取访问host时,没有取 X-Forwarded-For,而是取的Header里的Host

源码文件:modules/httplib/url.go 及内容处:

func GuessCurrentHostURL(ctx context.Context) string {
	req, ok := ctx.Value(RequestContextKey).(*http.Request)
	if !ok {
		return strings.TrimSuffix(setting.AppURL, setting.AppSubURL+"/")
	}
	// If no scheme provided by reverse proxy, then do not guess the AppURL, use the configured one.
	// At the moment, if site admin doesn't configure the proxy headers correctly, then Gitea would guess wrong.
	// There are some cases:
	// 1. The reverse proxy is configured correctly, it passes "X-Forwarded-Proto/Host" headers. Perfect, Gitea can handle it correctly.
	// 2. The reverse proxy is not configured correctly, doesn't pass "X-Forwarded-Proto/Host" headers, eg: only one "proxy_pass http://gitea:3000" in Nginx.
	// 3. There is no reverse proxy.
	// Without an extra config option, Gitea is impossible to distinguish between case 2 and case 3,
	// then case 2 would result in wrong guess like guessed AppURL becomes "http://gitea:3000/", which is not accessible by end users.
	// So in the future maybe it should introduce a new config option, to let site admin decide how to guess the AppURL.
	reqScheme := getRequestScheme(req)
	if reqScheme == "" {
		return strings.TrimSuffix(setting.AppURL, setting.AppSubURL+"/")
	}
	// X-Forwarded-Host has many problems: non-standard, not well-defined (X-Forwarded-Port or not), conflicts with Host header.
	// So do not use X-Forwarded-Host, just use Host header directly.
	return reqScheme + "://" + req.Host # 就是这里
}

分析过程就不写了,官方也说了为什么要取这个值,所以注意一下就好