From c117cba701820b942a8ad0806eaac182b1af327a Mon Sep 17 00:00:00 2001 From: Vladimir Vitkov Date: Thu, 20 Nov 2025 21:43:40 +0000 Subject: [PATCH] add static resource config to the apache section (#81) Add a section showing how to avoid proxying of static resources by Apache HTTPD Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/docs/pulls/81 Reviewed-by: Lunny Xiao Co-authored-by: Vladimir Vitkov Co-committed-by: Vladimir Vitkov --- docs/administration/reverse-proxies.md | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/docs/administration/reverse-proxies.md b/docs/administration/reverse-proxies.md index 353c0056..72739017 100644 --- a/docs/administration/reverse-proxies.md +++ b/docs/administration/reverse-proxies.md @@ -210,6 +210,50 @@ Then you **MUST** set something like `[server] ROOT_URL = http://git.example.com The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`. ::: +## Apache HTTPD and serve static resources directly + +We can tune the performance in splitting requests into categories static and dynamic. + +CSS files, JavaScript files, images and web fonts are static content. +The front page, a repository view or issue list is dynamic content. + +Apache HTTPD can serve static resources directly and proxy only the dynamic requests to Gitea. + +Download a snapshot of the Gitea source repository to `/path/to/gitea/`. +After this, run `make frontend` in the repository directory to generate the static resources. We are only interested in the `public/` directory for this task, so you can delete the rest. +(You will need to have [Node with npm](https://nodejs.org/en/download/) and `make` installed to generate the static resources) + +Depending on the scale of your user base, you might want to split the traffic to two distinct servers, +or use a cdn for the static files. + +### Single node and single domain + +Set `[server] STATIC_URL_PREFIX = /_/static` in your configuration. + +```apacheconf + + ... + + Order allow,deny + Allow from all + + + ProxyPass /_/static/ ! + Alias /_/static/ /path/to/gitea/public/ + + Options FollowSymlinks + AllowOverride None + Require all granted + + + AllowEncodedSlashes NoDecode + # Note: no trailing slash after either /git or port + ProxyPass / http://localhost:3000/ nocanon + ProxyPreserveHost On + RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME} + +``` + ## Caddy If you want Caddy to serve your Gitea instance, you can add the following server block to your Caddyfile: