2018-10-17 21:19:04 +03:00
|
|
|
|
---
|
|
|
|
|
date: "2018-05-22T11:00:00+00:00"
|
2023-05-23 13:14:57 +03:00
|
|
|
|
title: "反向代理"
|
2018-10-17 21:19:04 +03:00
|
|
|
|
slug: "reverse-proxies"
|
2023-04-04 16:47:31 +03:00
|
|
|
|
weight: 16
|
2020-12-09 09:47:06 +03:00
|
|
|
|
toc: false
|
2018-10-17 21:19:04 +03:00
|
|
|
|
draft: false
|
Refactor docs (#23752)
This was intended to be a small followup for
https://github.com/go-gitea/gitea/pull/23712, but...here we are.
1. Our docs currently use `slug` as the entire URL, which makes
refactoring tricky (see https://github.com/go-gitea/gitea/pull/23712).
Instead, this PR attempts to make future refactoring easier by using
slugs as an extension of the section. (Hugo terminology)
- What the above boils down to is this PR attempts to use directory
organization as URL management. e.g. `usage/comparison.en-us.md` ->
`en-us/usage/comparison/`, `usage/packages/overview.en-us.md` ->
`en-us/usage/packages/overview/`
- Technically we could even remove `slug`, as Hugo defaults to using
filename, however at least with this PR it means `slug` only needs to be
the name for the **current file** rather than an entire URL
2. This PR adds appropriate aliases (redirects) for pages, so anything
on the internet that links to our docs should hopefully not break.
3. A minor nit I've had for a while, renaming `seek-help` to `support`.
It's a minor thing, but `seek-help` has a strange connotation to it.
4. The commits are split such that you can review the first which is the
"actual" change, and the second is added redirects so that the first
doesn't break links elsewhere.
---------
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-04-28 06:33:41 +03:00
|
|
|
|
aliases:
|
|
|
|
|
- /zh-cn/reverse-proxies
|
2018-10-17 21:19:04 +03:00
|
|
|
|
menu:
|
|
|
|
|
sidebar:
|
2023-03-23 18:18:24 +03:00
|
|
|
|
parent: "administration"
|
2018-10-17 21:19:04 +03:00
|
|
|
|
name: "反向代理"
|
|
|
|
|
weight: 16
|
|
|
|
|
identifier: "reverse-proxies"
|
|
|
|
|
---
|
|
|
|
|
|
2022-10-18 00:30:30 +03:00
|
|
|
|
# 反向代理
|
|
|
|
|
|
|
|
|
|
**目录**
|
|
|
|
|
|
|
|
|
|
{{< toc >}}
|
|
|
|
|
|
2018-10-17 21:19:04 +03:00
|
|
|
|
## 使用 Nginx 作为反向代理服务
|
|
|
|
|
|
|
|
|
|
如果您想使用 Nginx 作为 Gitea 的反向代理服务,您可以参照以下 `nginx.conf` 配置中 `server` 的 `http` 部分:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name git.example.com;
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
proxy_pass http://localhost:3000;
|
2022-10-18 00:30:30 +03:00
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
2018-10-17 21:19:04 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 使用 Nginx 作为反向代理服务并将 Gitea 路由至一个子路径
|
|
|
|
|
|
|
|
|
|
如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下 `nginx.conf` 配置中 `server` 的 `http` 部分,为 Gitea 添加路由规则:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name git.example.com;
|
|
|
|
|
|
2021-10-16 06:34:07 +03:00
|
|
|
|
# 注意: /git/ 最后需要有一个路径符号
|
2023-03-23 18:18:24 +03:00
|
|
|
|
location /git/ {
|
2021-10-16 06:34:07 +03:00
|
|
|
|
# 注意: 反向代理后端 URL 的最后需要有一个路径符号
|
|
|
|
|
proxy_pass http://localhost:3000/;
|
2022-10-18 00:30:30 +03:00
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
2018-10-17 21:19:04 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-16 06:34:07 +03:00
|
|
|
|
然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项。
|
2018-10-17 21:19:04 +03:00
|
|
|
|
|
|
|
|
|
## 使用 Apache HTTPD 作为反向代理服务
|
|
|
|
|
|
|
|
|
|
如果您想使用 Apache HTTPD 作为 Gitea 的反向代理服务,您可以为您的 Apache HTTPD 作如下配置(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下):
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<VirtualHost *:80>
|
|
|
|
|
...
|
|
|
|
|
ProxyPreserveHost On
|
|
|
|
|
ProxyRequests off
|
2019-07-20 21:44:53 +03:00
|
|
|
|
AllowEncodedSlashes NoDecode
|
|
|
|
|
ProxyPass / http://localhost:3000/ nocanon
|
2018-10-17 21:19:04 +03:00
|
|
|
|
</VirtualHost>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`
|
|
|
|
|
|
|
|
|
|
## 使用 Apache HTTPD 作为反向代理服务并将 Gitea 路由至一个子路径
|
|
|
|
|
|
|
|
|
|
如果您已经有一个域名并且想与 Gitea 共享该域名,您可以增加以下配置为 Gitea 添加路由规则(在 Ubuntu 中,配置文件通常在 `/etc/apache2/httpd.conf` 目录下):
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<VirtualHost *:80>
|
|
|
|
|
...
|
|
|
|
|
<Proxy *>
|
|
|
|
|
Order allow,deny
|
|
|
|
|
Allow from all
|
|
|
|
|
</Proxy>
|
2019-07-27 01:09:12 +03:00
|
|
|
|
AllowEncodedSlashes NoDecode
|
2021-10-16 06:34:07 +03:00
|
|
|
|
# 注意: 路径和 URL 后面都不要写路径符号 '/'
|
2019-07-27 01:09:12 +03:00
|
|
|
|
ProxyPass /git http://localhost:3000 nocanon
|
2018-10-17 21:19:04 +03:00
|
|
|
|
</VirtualHost>
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-16 06:34:07 +03:00
|
|
|
|
然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项。
|
2018-10-17 21:19:04 +03:00
|
|
|
|
|
|
|
|
|
注:必须启用以下 Apache HTTPD 组件:`proxy`, `proxy_http`
|
|
|
|
|
|
|
|
|
|
## 使用 Caddy 作为反向代理服务
|
|
|
|
|
|
|
|
|
|
如果您想使用 Caddy 作为 Gitea 的反向代理服务,您可以在 `Caddyfile` 中添加如下配置:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
git.example.com {
|
|
|
|
|
proxy / http://localhost:3000
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 使用 Caddy 作为反向代理服务并将 Gitea 路由至一个子路径
|
|
|
|
|
|
|
|
|
|
如果您已经有一个域名并且想与 Gitea 共享该域名,您可以在您的 `Caddyfile` 文件中增加以下配置,为 Gitea 添加路由规则:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
git.example.com {
|
2021-10-16 06:34:07 +03:00
|
|
|
|
# 注意: 路径 /git/ 最后需要有路径符号
|
|
|
|
|
proxy /git/ http://localhost:3000
|
2018-10-17 21:19:04 +03:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-16 06:34:07 +03:00
|
|
|
|
然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项。
|
2022-04-20 17:08:23 +03:00
|
|
|
|
|
|
|
|
|
## 使用 Traefik 作为反向代理服务
|
|
|
|
|
|
|
|
|
|
如果您想使用 traefik 作为 Gitea 的反向代理服务,您可以在 `docker-compose.yaml` 中添加 label 部分(假设使用 docker 作为 traefik 的 provider):
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
gitea:
|
|
|
|
|
image: gitea/gitea
|
|
|
|
|
...
|
|
|
|
|
labels:
|
|
|
|
|
- "traefik.enable=true"
|
|
|
|
|
- "traefik.http.routers.gitea.rule=Host(`example.com`)"
|
|
|
|
|
- "traefik.http.services.gitea-websecure.loadbalancer.server.port=3000"
|
|
|
|
|
```
|
|
|
|
|
|
2022-07-28 04:22:47 +03:00
|
|
|
|
这份配置假设您使用 traefik 来处理 HTTPS 服务,并在其和 Gitea 之间使用 HTTP 进行通信。
|