添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Skip to main content
Version: 1.20.4

Reverse Proxies

Nginx

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

server {
listen 80;
server_name git.example.com;

location / {
client_max_body_size 512M;
proxy_pass http://localhost:3000;
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;
}
}

Resolving Error: 413 Request Entity Too Large

This error indicates nginx is configured to restrict the file upload size, it affects attachment uploading, form posting, package uploading and LFS pushing, etc. You can fine tune the client_max_body_size option according to nginx document .

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 :

server {
listen 80;
server_name git.example.com;

# Note: Trailing slash
location /gitea/ {
client_max_body_size 512M;

# make nginx use unescaped URI, keep "%2F" as is
rewrite ^ $request_uri;
rewrite ^/gitea(/.*) $1 break;
proxy_pass http://127.0.0.1:3000$uri;

# other common HTTP headers, see the "Nginx" config section above
proxy_set_header ...
}
}

Then you MUST set something like [server] ROOT_URL = http://git.example.com/git/ correctly in your configuration.

Nginx 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.

Nginx can serve static resources directly and proxy only the dynamic requests to Gitea. Nginx is optimized for serving static content, while the proxying of large responses might be the opposite of that (see https://serverfault.com/q/587386 ).

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.