Skip to content

Commit 3fd173b

Browse files
committed
improve nginx sample
1 parent 16cb5fc commit 3fd173b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,31 @@ server {
6161

6262
## Nginx with a sub-path
6363

64-
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`:
6567

6668
```nginx
6769
server {
6870
...
69-
# Note: Trailing slash
70-
location /gitea/ {
71+
location /gitea {
72+
return 301 $scheme://$host/gitea/;
73+
}
74+
location ~ ^/(gitea|v2)/ {
7175
client_max_body_size 512M;
7276
73-
# make nginx use unescaped URI, keep "%2F" as is
77+
# make nginx use unescaped URI, keep "%2F" as-is, remove the "/gitea" sub-path prefix, pass "/v2" as-is.
7478
rewrite ^ $request_uri;
75-
rewrite ^/gitea(/.*) $1 break;
79+
rewrite ^(/gitea)?(/.*) $2 break;
7680
proxy_pass http://127.0.0.1:3000$uri;
7781
7882
# other common HTTP headers, see the "Nginx" config section above
79-
proxy_set_header ...
83+
proxy_set_header Connection $http_connection;
84+
proxy_set_header Upgrade $http_upgrade;
85+
proxy_set_header Host $host;
86+
proxy_set_header X-Real-IP $remote_addr;
87+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
88+
proxy_set_header X-Forwarded-Proto $scheme;
8089
}
8190
}
8291
```

0 commit comments

Comments
 (0)