Skip to content

Commit cf1a7b0

Browse files
authored
Improve reverse-proxy document and fix nginx config bug (#24616)
Close #23711, thanks to @ghnp5 ! Close #24612, thanks to @DanielGibson ! Major changes: * the default value of nginx's client_max_body_size is too small, so put a 512M here * move `Resolving Error: 413 Request Entity Too Large` to a sub-section of `Nginx` section * make nginx use unescaped the URI and keep "%2F" as is when using sub-path * add details for General sub-path configuration
1 parent c355728 commit cf1a7b0

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

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

+29-17
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ menu:
2525

2626
If you want Nginx to serve your Gitea instance, add the following `server` section to the `http` section of `nginx.conf`:
2727

28-
```apacheconf
28+
```
2929
server {
3030
listen 80;
3131
server_name git.example.com;
3232
3333
location / {
34+
client_max_body_size 512M;
3435
proxy_pass http://localhost:3000;
3536
proxy_set_header Host $host;
3637
proxy_set_header X-Real-IP $remote_addr;
@@ -40,23 +41,32 @@ server {
4041
}
4142
```
4243

44+
### Resolving Error: 413 Request Entity Too Large
45+
46+
This error indicates nginx is configured to restrict the file upload size,
47+
it affects attachment uploading, form posting, package uploading and LFS pushing, etc.
48+
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).
49+
4350
## Nginx with a sub-path
4451

4552
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`:
4653

47-
```apacheconf
54+
```
4855
server {
4956
listen 80;
5057
server_name git.example.com;
5158
5259
# Note: Trailing slash
53-
location /git/ {
54-
# Note: Trailing slash
55-
proxy_pass http://localhost:3000/;
56-
proxy_set_header Host $host;
57-
proxy_set_header X-Real-IP $remote_addr;
58-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
59-
proxy_set_header X-Forwarded-Proto $scheme;
60+
location /gitea/ {
61+
client_max_body_size 512M;
62+
63+
# make nginx use unescaped URI, keep "%2F" as is
64+
rewrite ^ $request_uri;
65+
rewrite ^/gitea(/.*) $1 break;
66+
proxy_pass http://127.0.0.1:3000$uri;
67+
68+
# other common HTTP headers, see the "Nginx" config section above
69+
proxy_set_header ...
6070
}
6171
}
6272
```
@@ -132,14 +142,6 @@ server {
132142
}
133143
```
134144

135-
## Resolving Error: 413 Request Entity Too Large
136-
137-
This error indicates nginx is configured to restrict the file upload size.
138-
139-
In your nginx config file containing your Gitea proxy directive, find the `location { ... }` block for Gitea and add the line
140-
`client_max_body_size 16M;` to set this limit to 16 megabytes or any other number of choice.
141-
If you use Git LFS, this will also limit the size of the largest file you will be able to push.
142-
143145
## Apache HTTPD
144146

145147
If you want Apache HTTPD to serve your Gitea instance, you can add the following to your Apache HTTPD configuration (usually located at `/etc/apache2/httpd.conf` in Ubuntu):
@@ -387,3 +389,13 @@ gitea:
387389
This config assumes that you are handling HTTPS on the traefik side and using HTTP between Gitea and traefik.
388390
389391
Then you **MUST** set something like `[server] ROOT_URL = http://example.com/gitea/` correctly in your configuration.
392+
393+
## General sub-path configuration
394+
395+
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.
396+
397+
If you really need to do so, to make Gitea works with sub-path (eg: `http://example.com/gitea/`), here are the requirements:
398+
399+
1. Set `[server] ROOT_URL = http://example.com/gitea/` in your `app.ini` file.
400+
2. Make the reverse-proxy pass `http://example.com/gitea/foo` to `http://gitea-server:3000/foo`.
401+
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`.

0 commit comments

Comments
 (0)