Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documents for Gitea behind reverse proxy. Fix some small bugs (some URLs are generated without sub-path) #17320

Merged
merged 6 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/content/doc/usage/reverse-proxies.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ server {
listen 80;
server_name git.example.com;

location /git/ { # Note: Trailing slash
proxy_pass http://localhost:3000/; # Note: Trailing slash
# Note: Trailing slash
location /git/ {
# Note: Trailing slash
proxy_pass http://localhost:3000/;
}
}
```

Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
Then you **MUST** set something like `[server] ROOT_URL = http://git.example.com/git/` correctly in your configuration.

## Nginx and serve static resources directly

Expand Down Expand Up @@ -139,11 +141,10 @@ If you want Apache HTTPD to serve your Gitea instance, you can add the following
ProxyRequests off
AllowEncodedSlashes NoDecode
ProxyPass / http://localhost:3000/ nocanon
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
```

Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.

If you wish to use Let's Encrypt with webroot validation, add the line `ProxyPass /.well-known !` before `ProxyPass` to disable proxying these requests to Gitea.

Expand All @@ -161,13 +162,12 @@ In case you already have a site, and you want Gitea to share the domain name, yo
AllowEncodedSlashes NoDecode
# Note: no trailing slash after either /git or port
ProxyPass /git http://localhost:3000 nocanon
ProxyPassReverse /git http://localhost:3000
</VirtualHost>
```

Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
Then you **MUST** set something like `[server] ROOT_URL = http://git.example.com/git/` correctly in your configuration.

Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.

## Caddy

Expand Down
19 changes: 10 additions & 9 deletions docs/content/doc/usage/reverse-proxies.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ server {
listen 80;
server_name git.example.com;

location /git/ { # Note: Trailing slash
proxy_pass http://localhost:3000/; # Note: Trailing slash
# 注意: /git/ 最后需要有一个路径符号
location /git/ {
# 注意: 反向代理后端 URL 的最后需要有一个路径符号
proxy_pass http://localhost:3000/;
}
}
```

然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。
然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项

## 使用 Apache HTTPD 作为反向代理服务

Expand All @@ -56,7 +58,6 @@ server {
ProxyRequests off
AllowEncodedSlashes NoDecode
ProxyPass / http://localhost:3000/ nocanon
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
```

Expand All @@ -74,13 +75,12 @@ server {
Allow from all
</Proxy>
AllowEncodedSlashes NoDecode
# Note: no trailing slash after either /git or port
# 注意: 路径和 URL 后面都不要写路径符号 '/'
ProxyPass /git http://localhost:3000 nocanon
ProxyPassReverse /git http://localhost:3000
</VirtualHost>
```

然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。
然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项

注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`

Expand All @@ -100,8 +100,9 @@ git.example.com {

```
git.example.com {
proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/
# 注意: 路径 /git/ 最后需要有路径符号
proxy /git/ http://localhost:3000
}
```

然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。
然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
// Miscellaneous
if setting.API.EnableSwagger {
m.Get("/swagger", func(ctx *context.APIContext) {
ctx.Redirect("/api/swagger")
ctx.Redirect(setting.AppSubURL + "/api/swagger")
})
}
m.Get("/version", misc.Version)
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/org/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func IsMember(ctx *context.APIContext) {
}
}

redirectURL := setting.AppURL + "api/v1/orgs/" + ctx.Org.Organization.Name + "/public_members/" + userToCheck.Name
redirectURL := setting.AppSubURL + "/api/v1/orgs/" + ctx.Org.Organization.Name + "/public_members/" + userToCheck.Name
ctx.Redirect(redirectURL, 302)
}

Expand Down
3 changes: 2 additions & 1 deletion routers/web/user/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"strings"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -86,7 +87,7 @@ func getNotifications(c *context.Context) {
// redirect to last page if request page is more than total pages
pager := context.NewPagination(int(total), perPage, page, 5)
if pager.Paginater.Current() < page {
c.Redirect(fmt.Sprintf("/notifications?q=%s&page=%d", c.FormString("q"), pager.Paginater.Current()))
c.Redirect(fmt.Sprintf("%s/notifications?q=%s&page=%d", setting.AppSubURL, url.QueryEscape(c.FormString("q")), pager.Paginater.Current()))
return
}

Expand Down