|
| 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 | + |
| 16 | +## 使用 Nginx 作为反向代理服务 |
| 17 | + |
| 18 | +如果您想使用 Nginx 作为 Gitea 的反向代理服务,您可以参照以下 `nginx.conf` 配置中 `server` 的 `http` 部分: |
| 19 | + |
| 20 | +``` |
| 21 | +server { |
| 22 | + listen 80; |
| 23 | + server_name git.example.com; |
| 24 | +
|
| 25 | + location / { |
| 26 | + proxy_pass http://localhost:3000; |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +## 使用 Nginx 作为反向代理服务并将 Gitea 路由至一个子路径 |
| 32 | + |
| 33 | +如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下 `nginx.conf` 配置中 `server` 的 `http` 部分,为 Gitea 添加路由规则: |
| 34 | + |
| 35 | +``` |
| 36 | +server { |
| 37 | + listen 80; |
| 38 | + server_name git.example.com; |
| 39 | +
|
| 40 | + location /git/ { # Note: Trailing slash |
| 41 | + proxy_pass http://localhost:3000/; # Note: Trailing slash |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。 |
| 47 | + |
| 48 | +## 使用 Apache HTTPD 作为反向代理服务 |
| 49 | + |
| 50 | +如果您想使用 Apache HTTPD 作为 Gitea 的反向代理服务,您可以为您的 Apache HTTPD 作如下配置(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下): |
| 51 | + |
| 52 | +``` |
| 53 | +<VirtualHost *:80> |
| 54 | + ... |
| 55 | + ProxyPreserveHost On |
| 56 | + ProxyRequests off |
| 57 | + ProxyPass / http://localhost:3000/ |
| 58 | + ProxyPassReverse / http://localhost:3000/ |
| 59 | +</VirtualHost> |
| 60 | +``` |
| 61 | + |
| 62 | +注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http` |
| 63 | + |
| 64 | +## 使用 Apache HTTPD 作为反向代理服务并将 Gitea 路由至一个子路径 |
| 65 | + |
| 66 | +如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下配置为 Gitea 添加路由规则(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下): |
| 67 | + |
| 68 | +``` |
| 69 | +<VirtualHost *:80> |
| 70 | + ... |
| 71 | + <Proxy *> |
| 72 | + Order allow,deny |
| 73 | + Allow from all |
| 74 | + </Proxy> |
| 75 | +
|
| 76 | + ProxyPass /git http://localhost:3000 # Note: no trailing slash after either /git or port |
| 77 | + ProxyPassReverse /git http://localhost:3000 # Note: no trailing slash after either /git or port |
| 78 | +</VirtualHost> |
| 79 | +``` |
| 80 | + |
| 81 | +然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。 |
| 82 | + |
| 83 | +注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http` |
| 84 | + |
| 85 | +## 使用 Caddy 作为反向代理服务 |
| 86 | + |
| 87 | +如果您想使用 Caddy 作为 Gitea 的反向代理服务,您可以在 `Caddyfile` 中添加如下配置: |
| 88 | + |
| 89 | +``` |
| 90 | +git.example.com { |
| 91 | + proxy / http://localhost:3000 |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## 使用 Caddy 作为反向代理服务并将 Gitea 路由至一个子路径 |
| 96 | + |
| 97 | +如果您已经有一个域名并且想与 Gitea 共享该域名,您可以在您的 `Caddyfile` 文件中增加以下配置,为 Gitea 添加路由规则: |
| 98 | + |
| 99 | +``` |
| 100 | +git.example.com { |
| 101 | + proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/ |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`。 |
0 commit comments