You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reverse-proxies.en-us.md 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ---
  2. date: "2018-05-22T11:00:00+00:00"
  3. title: "Usage: Reverse Proxies"
  4. slug: "reverse-proxies"
  5. weight: 17
  6. toc: true
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "usage"
  11. name: "Reverse Proxies"
  12. weight: 16
  13. identifier: "reverse-proxies"
  14. ---
  15. ## Using Nginx as a reverse proxy
  16. If you want Nginx to serve your Gitea instance, you can the following `server` section inside the `http` section of `nginx.conf`:
  17. ```
  18. server {
  19. listen 80;
  20. server_name git.example.com;
  21. location / {
  22. proxy_pass http://localhost:3000;
  23. }
  24. }
  25. ```
  26. ## Using Nginx with a sub-path as a reverse proxy
  27. 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`:
  28. ```
  29. server {
  30. listen 80;
  31. server_name git.example.com;
  32. location /git/ { # Note: Trailing slash
  33. proxy_pass http://localhost:3000/; # Note: Trailing slash
  34. }
  35. }
  36. ```
  37. Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
  38. ## Using Nginx as a reverse proxy and serve static resources directly
  39. We can tune the performance in splitting requests into categories static and dynamic.
  40. CSS files, JavaScript files, images and web fonts are static content.
  41. The front page, a repository view or issue list is dynamic content.
  42. Nginx can serve static resources directly and proxy only the dynamic requests to gitea.
  43. Nginx is optimized for serving static content, while the proxying of large responses might be the opposite of that
  44. (see https://serverfault.com/q/587386).
  45. Download a snap shot of the gitea source repository to `/path/to/gitea/`.
  46. We are only interested in the `public/` directory and you can delete the rest.
  47. Depending on the scale of your user base, you might want to split the traffic to two distinct servers,
  48. or use a cdn for the static files.
  49. ### using a single node and a single domain
  50. Set `[server] STATIC_URL_PREFIX = /_/static` in your configuration.
  51. ```
  52. server {
  53. listen 80;
  54. server_name git.example.com;
  55. location /_/static {
  56. alias /path/to/gitea/public;
  57. }
  58. location / {
  59. proxy_pass http://localhost:3000;
  60. }
  61. }
  62. ```
  63. ### using two nodes and two domains
  64. Set `[server] STATIC_URL_PREFIX = http://cdn.example.com/gitea` in your configuration.
  65. ```
  66. # application server running gitea
  67. server {
  68. listen 80;
  69. server_name git.example.com;
  70. location / {
  71. proxy_pass http://localhost:3000;
  72. }
  73. }
  74. ```
  75. ```
  76. # static content delivery server
  77. server {
  78. listen 80;
  79. server_name cdn.example.com;
  80. location /gitea {
  81. alias /path/to/gitea/public;
  82. }
  83. location / {
  84. return 404;
  85. }
  86. }
  87. ```
  88. ## Using Apache HTTPD as a reverse proxy
  89. If you want Apache HTTPD to serve your Gitea instance, you can add the following to your Apache HTTPD configuration (usually located at `/etc/apache2/httpd.conf` in Ubuntu):
  90. ```
  91. <VirtualHost *:80>
  92. ...
  93. ProxyPreserveHost On
  94. ProxyRequests off
  95. AllowEncodedSlashes NoDecode
  96. ProxyPass / http://localhost:3000/ nocanon
  97. ProxyPassReverse / http://localhost:3000/
  98. </VirtualHost>
  99. ```
  100. Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
  101. ## Using Apache HTTPD with a sub-path as a reverse proxy
  102. In case you already have a site, and you want Gitea to share the domain name, you can setup Apache HTTPD to serve Gitea under a sub-path by adding the following to you Apache HTTPD configuration (usually located at `/etc/apache2/httpd.conf` in Ubuntu):
  103. ```
  104. <VirtualHost *:80>
  105. ...
  106. <Proxy *>
  107. Order allow,deny
  108. Allow from all
  109. </Proxy>
  110. AllowEncodedSlashes NoDecode
  111. # Note: no trailing slash after either /git or port
  112. ProxyPass /git http://localhost:3000 nocanon
  113. ProxyPassReverse /git http://localhost:3000
  114. </VirtualHost>
  115. ```
  116. Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
  117. Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
  118. ## Using Caddy as a reverse proxy
  119. If you want Caddy to serve your Gitea instance, you can add the following server block to your Caddyfile:
  120. ```
  121. git.example.com {
  122. proxy / http://localhost:3000
  123. }
  124. ```
  125. ## Using Caddy with a sub-path as a reverse proxy
  126. In case you already have a site, and you want Gitea to share the domain name, you can setup Caddy to serve Gitea under a sub-path by adding the following to your server block in your Caddyfile:
  127. ```
  128. git.example.com {
  129. proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/
  130. }
  131. ```
  132. Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.