I have decided to set up a Gitea instance on my server to manage my personal repositories.

While installing and running it was straightforward, I ran into some problems setting up nginx to reverse proxy a subfolder to the Gitea instance. The problem was mostly due to Gitea not serving static resources, such as css stylesheets or javascript files.

After reading through various help documents and GitHub tickets, I found this comment on a now-closed issue that include a setup for nginx that works in my case:

location /git {
    return 301 $scheme://$host:$server_port/git/;
}

location ^~ /git/ {
    resolver 127.0.0.1 valid=30s;
    set $upstream_app 127.0.0.1;
    set $upstream_port 3000;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    rewrite /git(.*) $1 break;
}

For what I can understand of the code above, the first location statement just add a trailing backslash to the request and bumps it to the second location statement.

The second statement doesn’t apply to files in the root directory with the ^~ exclusion. The rest of the statement sets up the proxy server.

I think that the last rewrite is needed to serve other static assets.