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

reverse-proxies.zh-cn.md 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ---
  2. date: "2018-05-22T11:00:00+00:00"
  3. title: "使用:反向代理"
  4. slug: "reverse-proxies"
  5. weight: 17
  6. toc: true
  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. location /git/ { # Note: Trailing slash
  33. proxy_pass http://localhost:3000/; # Note: Trailing slash
  34. }
  35. }
  36. ```
  37. 然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。
  38. ## 使用 Apache HTTPD 作为反向代理服务
  39. 如果您想使用 Apache HTTPD 作为 Gitea 的反向代理服务,您可以为您的 Apache HTTPD 作如下配置(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下):
  40. ```
  41. <VirtualHost *:80>
  42. ...
  43. ProxyPreserveHost On
  44. ProxyRequests off
  45. AllowEncodedSlashes NoDecode
  46. ProxyPass / http://localhost:3000/ nocanon
  47. ProxyPassReverse / http://localhost:3000/
  48. </VirtualHost>
  49. ```
  50. 注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`
  51. ## 使用 Apache HTTPD 作为反向代理服务并将 Gitea 路由至一个子路径
  52. 如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下配置为 Gitea 添加路由规则(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下):
  53. ```
  54. <VirtualHost *:80>
  55. ...
  56. <Proxy *>
  57. Order allow,deny
  58. Allow from all
  59. </Proxy>
  60. AllowEncodedSlashes NoDecode
  61. # Note: no trailing slash after either /git or port
  62. ProxyPass /git http://localhost:3000 nocanon
  63. ProxyPassReverse /git http://localhost:3000
  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. proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/
  80. }
  81. ```
  82. 然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。