Skip to content

Commit f805c3b

Browse files
committed
fix
1 parent 68d5c18 commit f805c3b

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

docs/content/administration/reverse-proxies.en-us.md

+35-35
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,35 @@ menu:
1717

1818
# Reverse Proxies
1919

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 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 sure Gitea sees 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+
If you really need to do so, to make Gitea work with sub-path (eg: `https://common.example.com/gitea/`),
32+
here are the 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. If you'd like to use container registry, the container registry uses a fixed sub-path `/v2` in the root, which is unchangeable and required by container registry standard.
37+
- Make 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+
2040
## Nginx
2141

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`.
43+
44+
And make sure `client_max_body_size` is large enough, otherwise there would be "413 Request Entity Too Large" error when uploading large files.
2345

2446
```
2547
server {
26-
listen 80;
27-
server_name git.example.com;
28-
48+
...
2949
location / {
3050
client_max_body_size 512M;
3151
proxy_pass http://localhost:3000;
@@ -39,21 +59,13 @@ server {
3959
}
4060
```
4161

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-
4862
## Nginx with a sub-path
4963

5064
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`:
5165

5266
```
5367
server {
54-
listen 80;
55-
server_name git.example.com;
56-
68+
...
5769
# Note: Trailing slash
5870
location /gitea/ {
5971
client_max_body_size 512M;
@@ -69,7 +81,7 @@ server {
6981
}
7082
```
7183

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

7486
## Nginx and serve static resources directly
7587

@@ -93,7 +105,7 @@ or use a cdn for the static files.
93105

94106
Set `[server] STATIC_URL_PREFIX = /_/static` in your configuration.
95107

96-
```apacheconf
108+
```
97109
server {
98110
listen 80;
99111
server_name git.example.com;
@@ -112,7 +124,7 @@ server {
112124

113125
Set `[server] STATIC_URL_PREFIX = http://cdn.example.com/gitea` in your configuration.
114126

115-
```apacheconf
127+
```
116128
# application server running Gitea
117129
server {
118130
listen 80;
@@ -124,7 +136,7 @@ server {
124136
}
125137
```
126138

127-
```apacheconf
139+
```
128140
# static content delivery server
129141
server {
130142
listen 80;
@@ -151,6 +163,8 @@ If you want Apache HTTPD to serve your Gitea instance, you can add the following
151163
ProxyRequests off
152164
AllowEncodedSlashes NoDecode
153165
ProxyPass / http://localhost:3000/ nocanon
166+
ProxyPreserveHost On
167+
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
154168
</VirtualHost>
155169
```
156170

@@ -172,6 +186,8 @@ In case you already have a site, and you want Gitea to share the domain name, yo
172186
AllowEncodedSlashes NoDecode
173187
# Note: no trailing slash after either /git or port
174188
ProxyPass /git http://localhost:3000 nocanon
189+
ProxyPreserveHost On
190+
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
175191
</VirtualHost>
176192
```
177193

@@ -183,7 +199,7 @@ Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.
183199

184200
If you want Caddy to serve your Gitea instance, you can add the following server block to your Caddyfile:
185201

186-
```apacheconf
202+
```
187203
git.example.com {
188204
reverse_proxy localhost:3000
189205
}
@@ -193,7 +209,7 @@ git.example.com {
193209

194210
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:
195211

196-
```apacheconf
212+
```
197213
git.example.com {
198214
route /git/* {
199215
uri strip_prefix /git
@@ -371,19 +387,3 @@ gitea:
371387
This config assumes that you are handling HTTPS on the traefik side and using HTTP between Gitea and traefik.
372388
373389
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.

routers/api/packages/container/container.go

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ func apiErrorDefined(ctx *context.Context, err *namedError) {
116116
}
117117

118118
func apiUnauthorizedError(ctx *context.Context) {
119+
// TODO: it doesn't seem quite right but it doesn't really cause problem at the moment.
120+
// container registry requires that the "/v2" must be in the root, so the sub-path in AppURL should be removed, ideally.
119121
ctx.Resp.Header().Add("WWW-Authenticate", `Bearer realm="`+httplib.GuessCurrentAppURL(ctx)+`v2/token",service="container_registry",scope="*"`)
120122
apiErrorDefined(ctx, errUnauthorized)
121123
}

0 commit comments

Comments
 (0)