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.zh-cn.md 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---
  2. date: "2018-05-22T11:00:00+00:00"
  3. title: "使用:反向代理"
  4. slug: "reverse-proxies"
  5. weight: 17
  6. toc: false
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "usage"
  11. name: "反向代理"
  12. weight: 16
  13. identifier: "reverse-proxies"
  14. ---
  15. ## 使用 Nginx 作为反向代理服务
  16. 如果您想使用 Nginx 作为 Gitea 的反向代理服务,您可以参照以下 `nginx.conf` 配置中 `server` 的 `http` 部分:
  17. ```
  18. server {
  19. listen 80;
  20. server_name git.example.com;
  21. location / {
  22. proxy_pass http://localhost:3000;
  23. }
  24. }
  25. ```
  26. ## 使用 Nginx 作为反向代理服务并将 Gitea 路由至一个子路径
  27. 如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下 `nginx.conf` 配置中 `server` 的 `http` 部分,为 Gitea 添加路由规则:
  28. ```
  29. server {
  30. listen 80;
  31. server_name git.example.com;
  32. # 注意: /git/ 最后需要有一个路径符号
  33. location /git/ {
  34. # 注意: 反向代理后端 URL 的最后需要有一个路径符号
  35. proxy_pass http://localhost:3000/;
  36. }
  37. }
  38. ```
  39. 然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项。
  40. ## 使用 Apache HTTPD 作为反向代理服务
  41. 如果您想使用 Apache HTTPD 作为 Gitea 的反向代理服务,您可以为您的 Apache HTTPD 作如下配置(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下):
  42. ```
  43. <VirtualHost *:80>
  44. ...
  45. ProxyPreserveHost On
  46. ProxyRequests off
  47. AllowEncodedSlashes NoDecode
  48. ProxyPass / http://localhost:3000/ nocanon
  49. </VirtualHost>
  50. ```
  51. 注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`
  52. ## 使用 Apache HTTPD 作为反向代理服务并将 Gitea 路由至一个子路径
  53. 如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下配置为 Gitea 添加路由规则(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下):
  54. ```
  55. <VirtualHost *:80>
  56. ...
  57. <Proxy *>
  58. Order allow,deny
  59. Allow from all
  60. </Proxy>
  61. AllowEncodedSlashes NoDecode
  62. # 注意: 路径和 URL 后面都不要写路径符号 '/'
  63. ProxyPass /git http://localhost:3000 nocanon
  64. </VirtualHost>
  65. ```
  66. 然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项。
  67. 注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`
  68. ## 使用 Caddy 作为反向代理服务
  69. 如果您想使用 Caddy 作为 Gitea 的反向代理服务,您可以在 `Caddyfile` 中添加如下配置:
  70. ```
  71. git.example.com {
  72. proxy / http://localhost:3000
  73. }
  74. ```
  75. ## 使用 Caddy 作为反向代理服务并将 Gitea 路由至一个子路径
  76. 如果您已经有一个域名并且想与 Gitea 共享该域名,您可以在您的 `Caddyfile` 文件中增加以下配置,为 Gitea 添加路由规则:
  77. ```
  78. git.example.com {
  79. # 注意: 路径 /git/ 最后需要有路径符号
  80. proxy /git/ http://localhost:3000
  81. }
  82. ```
  83. 然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项。
  84. ## 使用 Traefik 作为反向代理服务
  85. 如果您想使用 traefik 作为 Gitea 的反向代理服务,您可以在 `docker-compose.yaml` 中添加 label 部分(假设使用 docker 作为 traefik 的 provider):
  86. ```yaml
  87. gitea:
  88. image: gitea/gitea
  89. ...
  90. labels:
  91. - "traefik.enable=true"
  92. - "traefik.http.routers.gitea.rule=Host(`example.com`)"
  93. - "traefik.http.services.gitea-websecure.loadbalancer.server.port=3000"
  94. ```
  95. 这份配置假设您使用 traefik 来处理 HTTPS 服务,并在其和 Gitea 之间使用 HTTP 进行通信。