You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve reverse proxy documents and clarify the AppURL guessing behavior (#31003) (#31020)
Backport #31003 by wxiaoguang
Fix#31002
1. Mention Make sure `Host` and `X-Fowarded-Proto` headers are correctly passed to Gitea
2. Clarify the basic requirements and move the "general configuration" to the top
3. Add a comment for the "container registry"
4. Use 1.21 behavior if the reverse proxy is not correctly configured
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Copy file name to clipboardExpand all lines: docs/content/administration/reverse-proxies.en-us.md
+49-43
Original file line number
Diff line number
Diff line change
@@ -17,15 +17,35 @@ menu:
17
17
18
18
# Reverse Proxies
19
19
20
+
## General configuration
21
+
22
+
1. Set `[server] ROOT_URL = https://git.example.com/` in your `app.ini` file.
23
+
2. Make the reverse-proxy pass `https://git.example.com/foo` to `http://gitea:3000/foo`.
24
+
3. Make sure the reverse-proxy does not decode the URI. The request `https://git.example.com/a%2Fb` should be passed as `http://gitea:3000/a%2Fb`.
25
+
4. Make sure `Host` and `X-Fowarded-Proto` headers are correctly passed to Gitea to make Gitea see the real URL being visited.
26
+
27
+
### Use a sub-path
28
+
29
+
Usually it's **not recommended** to put Gitea in a sub-path, it's not widely used and may have some issues in rare cases.
30
+
31
+
To make Gitea work with a sub-path (eg: `https://common.example.com/gitea/`),
32
+
there are some extra requirements besides the general configuration above:
33
+
34
+
1. Use `[server] ROOT_URL = https://common.example.com/gitea/` in your `app.ini` file.
35
+
2. Make the reverse-proxy pass `https://common.example.com/gitea/foo` to `http://gitea:3000/foo`.
36
+
3. The container registry requires a fixed sub-path `/v2` at the root level which must be configured:
37
+
- Make the reverse-proxy pass `https://common.example.com/v2` to `http://gitea:3000/v2`.
38
+
- Make sure the URI and headers are also correctly passed (see the general configuration above).
39
+
20
40
## Nginx
21
41
22
-
If you want Nginx to serve your Gitea instance, add the following `server` section to the `http` section of `nginx.conf`:
42
+
If you want Nginx to serve your Gitea instance, add the following `server` section to the `http` section of `nginx.conf`.
23
43
24
-
```
25
-
server {
26
-
listen 80;
27
-
server_name git.example.com;
44
+
Make sure `client_max_body_size` is large enough, otherwise there would be "413 Request Entity Too Large" error when uploading large files.
28
45
46
+
```nginx
47
+
server {
48
+
...
29
49
location / {
30
50
client_max_body_size 512M;
31
51
proxy_pass http://localhost:3000;
@@ -39,37 +59,35 @@ server {
39
59
}
40
60
```
41
61
42
-
### Resolving Error: 413 Request Entity Too Large
43
-
44
-
This error indicates nginx is configured to restrict the file upload size,
45
-
it affects attachment uploading, form posting, package uploading and LFS pushing, etc.
46
-
You can fine tune the `client_max_body_size` option according to [nginx document](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size).
47
-
48
62
## Nginx with a sub-path
49
63
50
-
In case you already have a site, and you want Gitea to share the domain name, you can setup Nginx to serve Gitea under a sub-path by adding the following `server` section inside the `http` section of `nginx.conf`:
64
+
In case you already have a site, and you want Gitea to share the domain name,
65
+
you can setup Nginx to serve Gitea under a sub-path by adding the following `server` section
66
+
into the `http` section of `nginx.conf`:
51
67
52
-
```
68
+
```nginx
53
69
server {
54
-
listen 80;
55
-
server_name git.example.com;
56
-
57
-
# Note: Trailing slash
58
-
location /gitea/ {
70
+
...
71
+
location ~ ^/(gitea|v2)($|/) {
59
72
client_max_body_size 512M;
60
73
61
-
# make nginx use unescaped URI, keep "%2F" as is
74
+
# make nginx use unescaped URI, keep "%2F" as-is, remove the "/gitea" sub-path prefix, pass "/v2" as-is.
62
75
rewrite ^ $request_uri;
63
-
rewrite ^/gitea(/.*) $1 break;
76
+
rewrite ^(/gitea)?(/.*) $2 break;
64
77
proxy_pass http://127.0.0.1:3000$uri;
65
78
66
79
# other common HTTP headers, see the "Nginx" config section above
Then you **MUST** set something like `[server] ROOT_URL = http://git.example.com/git/` correctly in your configuration.
90
+
Then you **MUST** set something like `[server] ROOT_URL = http://git.example.com/gitea/` correctly in your configuration.
73
91
74
92
## Nginx and serve static resources directly
75
93
@@ -93,7 +111,7 @@ or use a cdn for the static files.
93
111
94
112
Set `[server] STATIC_URL_PREFIX = /_/static` in your configuration.
95
113
96
-
```apacheconf
114
+
```nginx
97
115
server {
98
116
listen 80;
99
117
server_name git.example.com;
@@ -112,7 +130,7 @@ server {
112
130
113
131
Set `[server] STATIC_URL_PREFIX = http://cdn.example.com/gitea` in your configuration.
114
132
115
-
```apacheconf
133
+
```nginx
116
134
# application server running Gitea
117
135
server {
118
136
listen 80;
@@ -124,7 +142,7 @@ server {
124
142
}
125
143
```
126
144
127
-
```apacheconf
145
+
```nginx
128
146
# static content delivery server
129
147
server {
130
148
listen 80;
@@ -151,6 +169,8 @@ If you want Apache HTTPD to serve your Gitea instance, you can add the following
151
169
ProxyRequests off
152
170
AllowEncodedSlashes NoDecode
153
171
ProxyPass / http://localhost:3000/ nocanon
172
+
ProxyPreserveHost On
173
+
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
154
174
</VirtualHost>
155
175
```
156
176
@@ -172,6 +192,8 @@ In case you already have a site, and you want Gitea to share the domain name, yo
172
192
AllowEncodedSlashes NoDecode
173
193
# Note: no trailing slash after either /git or port
174
194
ProxyPass /git http://localhost:3000 nocanon
195
+
ProxyPreserveHost On
196
+
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
175
197
</VirtualHost>
176
198
```
177
199
@@ -183,7 +205,7 @@ Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.
183
205
184
206
If you want Caddy to serve your Gitea instance, you can add the following server block to your Caddyfile:
185
207
186
-
```apacheconf
208
+
```
187
209
git.example.com {
188
210
reverse_proxy localhost:3000
189
211
}
@@ -193,7 +215,7 @@ git.example.com {
193
215
194
216
In case you already have a site, and you want Gitea to share the domain name, you can setup Caddy to serve Gitea under a sub-path by adding the following to your server block in your Caddyfile:
195
217
196
-
```apacheconf
218
+
```
197
219
git.example.com {
198
220
route /git/* {
199
221
uri strip_prefix /git
@@ -371,19 +393,3 @@ gitea:
371
393
This config assumes that you are handling HTTPS on the traefik side and using HTTP between Gitea and traefik.
372
394
373
395
Then you **MUST** set something like `[server] ROOT_URL = http://example.com/gitea/` correctly in your configuration.
374
-
375
-
## General sub-path configuration
376
-
377
-
Usually it's not recommended to put Gitea in a sub-path, it's not widely used and may have some issues in rare cases.
378
-
379
-
If you really need to do so, to make Gitea works with sub-path (eg: `http://example.com/gitea/`), here are the requirements:
380
-
381
-
1. Set `[server] ROOT_URL = http://example.com/gitea/` in your `app.ini` file.
382
-
2. Make the reverse-proxy pass `http://example.com/gitea/foo` to `http://gitea-server:3000/foo`.
383
-
3. Make sure the reverse-proxy not decode the URI, the request `http://example.com/gitea/a%2Fb` should be passed as `http://gitea-server:3000/a%2Fb`.
384
-
385
-
## Docker / Container Registry
386
-
387
-
The container registry uses a fixed sub-path `/v2` which can't be changed.
388
-
Even if you deploy Gitea with a different sub-path, `/v2` will be used by the `docker` client.
389
-
Therefore you may need to add an additional route to your reverse proxy configuration.
// If no scheme provided by reverse proxy, then do not guess the AppURL, use the configured one.
67
+
// At the moment, if site admin doesn't configure the proxy headers correctly, then Gitea would guess wrong.
68
+
// There are some cases:
69
+
// 1. The reverse proxy is configured correctly, it passes "X-Forwarded-Proto/Host" headers. Perfect, Gitea can handle it correctly.
70
+
// 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.
71
+
// 3. There is no reverse proxy.
72
+
// Without an extra config option, Gitea is impossible to distinguish between case 2 and case 3,
73
+
// then case 2 would result in wrong guess like guessed AppURL becomes "http://gitea:3000/", which is not accessible by end users.
74
+
// So in the future maybe it should introduce a new config option, to let site admin decide how to guess the AppURL.
0 commit comments