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.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. ProxyPass / http://localhost:3000/
  46. ProxyPassReverse / http://localhost:3000/
  47. </VirtualHost>
  48. ```
  49. 注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`
  50. ## 使用 Apache HTTPD 作为反向代理服务并将 Gitea 路由至一个子路径
  51. 如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下配置为 Gitea 添加路由规则(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下):
  52. ```
  53. <VirtualHost *:80>
  54. ...
  55. <Proxy *>
  56. Order allow,deny
  57. Allow from all
  58. </Proxy>
  59. ProxyPass /git http://localhost:3000 # Note: no trailing slash after either /git or port
  60. ProxyPassReverse /git http://localhost:3000 # Note: no trailing slash after either /git or port
  61. </VirtualHost>
  62. ```
  63. 然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。
  64. 注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`
  65. ## 使用 Caddy 作为反向代理服务
  66. 如果您想使用 Caddy 作为 Gitea 的反向代理服务,您可以在 `Caddyfile` 中添加如下配置:
  67. ```
  68. git.example.com {
  69. proxy / http://localhost:3000
  70. }
  71. ```
  72. ## 使用 Caddy 作为反向代理服务并将 Gitea 路由至一个子路径
  73. 如果您已经有一个域名并且想与 Gitea 共享该域名,您可以在您的 `Caddyfile` 文件中增加以下配置,为 Gitea 添加路由规则:
  74. ```
  75. git.example.com {
  76. proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/
  77. }
  78. ```
  79. 然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。