Gitea in a Subdirectory with Nginx

Gitea's Home Page
Gitea’s Home Page

Running web applications from the subdirectory of a URL has its benefits. There doesn’t seem to be much talk about this A series of posts about running my favorite open source applications from a URL subdirectory sounds like a good idea. It’s useful when you need to expose a web application quickly without provisioning a new subdomain and 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 We are connecting over a 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 Be sure that broad caching and deny directives are not applied to the reverse proxy location block or you might end up with strange 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.socket

In 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.socket

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

31 July 2019 — Written
2 March 2022 — Updated
Thedro Neely — Creator
gitea-in-a-sub-directory-with-nginx.md — Article

More Content

Openring

Web Ring

Comments

References

  1. https://thedroneely.com/git/
  2. https://thedroneely.com/
  3. https://thedroneely.com/posts/
  4. https://thedroneely.com/projects/
  5. https://thedroneely.com/about/
  6. https://thedroneely.com/contact/
  7. https://thedroneely.com/abstracts/
  8. https://ko-fi.com/thedroneely
  9. https://thedroneely.com/tags/git/
  10. https://thedroneely.com/tags/nginx/
  11. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx/#isso-thread
  12. https://thedroneely.com/posts/rss.xml
  13. https://thedroneely.com/images/gitea-in-a-sub-directory-with-nginx.png
  14. https://gitea.io/en-us/
  15. http://nginx.org/en/docs/
  16. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx/#code-block-608218e
  17. https://www.digitalocean.com/community/tools/nginx
  18. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx/#code-block-7f9b3d3
  19. https://github.com/go-gitea/gitea/commit/f49d160447899270fbca6370cb7ab2742dce85dc
  20. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx/#code-block-bd11a01
  21. https://www.thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx.md
  22. https://thedroneely.com/archives/projects/
  23. https://thedroneely.com/posts/kubernetes-in-a-linux-container/
  24. https://thedroneely.com/projects/voiceover-website/
  25. https://git.sr.ht/~sircmpwn/openring
  26. https://drewdevault.com/2022/11/12/In-praise-of-Plan-9.html
  27. https://drewdevault.com/
  28. https://mxb.dev/blog/the-indieweb-for-everyone/
  29. https://mxb.dev/
  30. https://www.taniarascia.com/simplifying-drag-and-drop/
  31. https://www.taniarascia.com/
  32. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx#isso-thread
  33. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx#code-block-608218e
  34. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx#code-block-7f9b3d3
  35. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx#code-block-bd11a01
  36. https://thedroneely.com/posts/good-evil-and-the-law/
  37. https://thedroneely.com/abstracts/golden-sun/
  38. https://thedroneely.com/posts/writing-with-vale/
  39. https://thedroneely.com/posts/making-web-pages/
  40. https://thedroneely.com/posts/keeping-up-with-open-source/
  41. https://drewdevault.com/2022/09/16/Open-source-matters.html
  42. https://mxb.dev/blog/make-free-stuff/
  43. https://thedroneely.com/sitemap.xml
  44. https://thedroneely.com/index.json
  45. https://thedroneely.com/resume/
  46. https://gitlab.com/tdro
  47. https://github.com/tdro
  48. https://codeberg.org/tdro
  49. https://thedroneely.com/analytics
  50. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx#
  51. https://creativecommons.org/licenses/by-sa/2.0/
  52. https://thedroneely.com/git/thedroneely/thedroneely.com
  53. https://opensource.org/licenses/GPL-3.0
  54. https://www.thedroneely.com/
  55. https://thedroneely.com/posts/gitea-in-a-sub-directory-with-nginx/#