Gitea in a Subdirectory with Nginx
Running web applications from the subdirectory of a URL has its benefits.
There doesn’t seem to be much talk about this
URL subdirectory sounds like a good
idea.
SSL certificate.
For example let’s run Gitea from the subdirectory of
a domain using nginx We will make Gitea
accessible from a URL of the form https://www.example.com/gitea or
https://www.example.com/git.
To accomplish this, reverse proxy using a separate location block in the nginx
unix socket to access the Gitea instance. The forward slashes at the end of
the proxy_pass are important and match the location block.
nginx
location /gitea/ {
proxy_pass http://unix:/opt/gitea/var/lib/gitea/gitea.socket:/;
}Then in Gitea’s app.ini configuration, adjust the server block to match the
location block specified 404s and exotic behavior.
ini
[server]
PROTOCOL = unix
SSH_DOMAIN = example.com
DOMAIN = http://www.example.com/gitea/
ROOT_URL = http://www.example.com/gitea/
HTTP_ADDR = /opt/gitea/var/lib/gitea/gitea.socketIn
future versions of Gitea,
the unix protocol value is deprecated in favour of http+unix.
ini
[server]
PROTOCOL = http+unix
SSH_DOMAIN = example.com
DOMAIN = http://www.example.com/gitea/
ROOT_URL = http://www.example.com/gitea/
HTTP_ADDR = /opt/gitea/var/lib/gitea/gitea.socketA user can access the full Gitea instance from the gitea/ subdirectory of the
URL.
All applications are not created equal and some blow up badly in a subdirectory. Gitea supports this natively from the configuration.
Some applications require elaborate tricks, workarounds, or source code changes that are probably not worth the effort.