Skip to content

Commit

Permalink
improve nginx sample
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed May 18, 2024
1 parent 16cb5fc commit 3fd173b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions docs/content/administration/reverse-proxies.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,31 @@ server {

## Nginx with a sub-path

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`:
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
into the `http` section of `nginx.conf`:

```nginx
server {
...
# Note: Trailing slash
location /gitea/ {
location /gitea {
return 301 $scheme://$host/gitea/;
}
location ~ ^/(gitea|v2)/ {
client_max_body_size 512M;
# make nginx use unescaped URI, keep "%2F" as is
# make nginx use unescaped URI, keep "%2F" as-is, remove the "/gitea" sub-path prefix, pass "/v2" as-is.
rewrite ^ $request_uri;
rewrite ^/gitea(/.*) $1 break;
rewrite ^(/gitea)?(/.*) $2 break;
proxy_pass http://127.0.0.1:3000$uri;
# other common HTTP headers, see the "Nginx" config section above
proxy_set_header ...
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
Expand Down

0 comments on commit 3fd173b

Please sign in to comment.