Skip to content

Commit e18ea9e

Browse files
Update documents for Gitea behind reverse proxy. Fix some small bugs (some URLs are generated without sub-path) (#17320)
* Apache `ProxyPassReverse` only works for Location, Content-Location and URI headers on HTTP redirect responses, it causes more problems than it resolves. Now all URLs generated by Gitee have the correct prefix AppSubURL. We do not need to set `ProxyPassReverse`. * fix url param * use AppSubURL instead of AppURL in api/v1 Co-authored-by: techknowlogick <techknowlogick@gitea.io>
1 parent 5588529 commit e18ea9e

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

docs/content/doc/usage/reverse-proxies.en-us.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ server {
4343
listen 80;
4444
server_name git.example.com;
4545
46-
location /git/ { # Note: Trailing slash
47-
proxy_pass http://localhost:3000/; # Note: Trailing slash
46+
# Note: Trailing slash
47+
location /git/ {
48+
# Note: Trailing slash
49+
proxy_pass http://localhost:3000/;
4850
}
4951
}
5052
```
5153

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

5456
## Nginx and serve static resources directly
5557

@@ -139,11 +141,10 @@ If you want Apache HTTPD to serve your Gitea instance, you can add the following
139141
ProxyRequests off
140142
AllowEncodedSlashes NoDecode
141143
ProxyPass / http://localhost:3000/ nocanon
142-
ProxyPassReverse / http://localhost:3000/
143144
</VirtualHost>
144145
```
145146

146-
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
147+
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.
147148

148149
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.
149150

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

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

170-
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
170+
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.
171171

172172
## Caddy
173173

docs/content/doc/usage/reverse-proxies.zh-cn.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ server {
3737
listen 80;
3838
server_name git.example.com;
3939
40-
location /git/ { # Note: Trailing slash
41-
proxy_pass http://localhost:3000/; # Note: Trailing slash
40+
# 注意: /git/ 最后需要有一个路径符号
41+
location /git/ {
42+
# 注意: 反向代理后端 URL 的最后需要有一个路径符号
43+
proxy_pass http://localhost:3000/;
4244
}
4345
}
4446
```
4547

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

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

@@ -56,7 +58,6 @@ server {
5658
ProxyRequests off
5759
AllowEncodedSlashes NoDecode
5860
ProxyPass / http://localhost:3000/ nocanon
59-
ProxyPassReverse / http://localhost:3000/
6061
</VirtualHost>
6162
```
6263

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

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

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

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

101101
```
102102
git.example.com {
103-
proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/
103+
# 注意: 路径 /git/ 最后需要有路径符号
104+
proxy /git/ http://localhost:3000
104105
}
105106
```
106107

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

routers/api/v1/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
576576
// Miscellaneous
577577
if setting.API.EnableSwagger {
578578
m.Get("/swagger", func(ctx *context.APIContext) {
579-
ctx.Redirect("/api/swagger")
579+
ctx.Redirect(setting.AppSubURL + "/api/swagger")
580580
})
581581
}
582582
m.Get("/version", misc.Version)

routers/api/v1/org/member.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func IsMember(ctx *context.APIContext) {
159159
}
160160
}
161161

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

routers/web/user/notification.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"net/url"
1112
"strings"
1213

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

0 commit comments

Comments
 (0)