Skip to content

Commit

Permalink
update tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
ginuerzh committed Nov 22, 2024
1 parent a9b904a commit ad43ced
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 68 deletions.
2 changes: 2 additions & 0 deletions docs/tutorials/api/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ GOST可以通过开启Web API服务使用RESTful API和GOST进程进行交互。
type: tcp
api:
addr: :18080
# unix domain socket
# addr: unix:///var/run/gost.sock
pathPrefix: /api
accesslog: true
auth:
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorials/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ GOST内部通过[Prometheus](https://prometheus.io/)的指标(Metrics)来提供

metrics:
addr: :9000
# unix domain socket
# addr: unix:///var/run/gost.sock
path: /metrics
auth:
username: user
Expand Down
92 changes: 59 additions & 33 deletions docs/tutorials/reverse-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,18 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: example.com
# filter:
# host: example.com
matcher:
rule: Host(`example.com`)
http:
host: test.example.com
- name: example-org
addr: example.org:80
filter:
host: example.org
# filter:
# host: example.org
matcher:
rule: Host(`example.org`)
http:
host: test.example.org:80
```
Expand All @@ -408,7 +412,7 @@ curl --resolve example.com:80:127.0.0.1 http://example.com

### 自定义请求头

通过设置`http.header`选项可以自定义请求头部信息,如果所设置的头部字段已存在则会被覆盖。
通过设置`http.requestHeader`选项可以自定义请求头部信息,如果所设置的头部字段已存在则会被覆盖。

```yaml hl_lines="16-20"
services:
Expand All @@ -424,20 +428,24 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: example.com
# filter:
# host: example.com
matcher:
rule: Host(`example.com`)
http:
header:
requestHeader:
User-Agent: gost/3.0.0
foo: bar
bar: 123
# host: test.example.com
- name: example-org
addr: example.org:80
filter:
host: example.org
# filter:
# host: example.org
matcher:
rule: Host(`example.org`)
http:
header:
requestHeader:
User-Agent: curl/7.81.0
foo: bar
bar: baz
Expand All @@ -464,8 +472,10 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: example.com
# filter:
# host: example.com
matcher:
rule: Host(`example.com`)
http:
responseHeader:
foo: bar
Expand All @@ -492,8 +502,10 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: example.com
# filter:
# host: example.com
matcher:
rule: Host(`example.com`)
http:
auth:
username: user
Expand All @@ -504,7 +516,7 @@ services:
### URL路径重写
通过设置`http.rewrite`选项定义URL路径重写规则。
通过设置`http.rewriteURL`选项定义URL路径重写规则。

```yaml hl_lines="16-21"
services:
Expand All @@ -520,20 +532,22 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: example.com
# filter:
# host: example.com
matcher:
rule: Host(`example.com`)
http:
rewrite:
rewriteURL:
- match: /api/login
replacement: /user/login
- match: /api/(.*)
replacement: /$1
```
`rewrite.match` (string)
`rewriteURL.match` (string)
: 指定路径匹配模式(支持正则表达式)。

`rewrite.replacement` (string)
`rewriteURL.replacement` (string)
: 设置路径替换内容。

`http://example.com/api/login`会被重写为`http://example.com/user/login`。
Expand All @@ -558,8 +572,10 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: example.com
# filter:
# host: example.com
matcher:
rule: Host(`example.com`)
http:
rewriteBody:
- match: foo
Expand Down Expand Up @@ -594,8 +610,10 @@ services:
nodes:
- name: example-com
addr: example.com:443
filter:
host: example.com
# filter:
# host: example.com
matcher:
rule: Host(`example.com`)
tls:
secure: true
serverName: example.com
Expand Down Expand Up @@ -646,12 +664,16 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: .example.com
# filter:
# host: .example.com
matcher:
rule: Host(`.example.com`)
- name: example-org
addr: example.org:80
filter:
host: .example.org
# filter:
# host: .example.org
matcher:
rule: Host(`.example.org`)
```
```bash
Expand All @@ -676,12 +698,16 @@ services:
nodes:
- name: example-com
addr: example.com:80
filter:
host: .example.com
# filter:
# host: .example.com
matcher:
rule: Host(`.example.com`)
- name: example-org
addr: example.org:80
filter:
host: .example.org
# filter:
# host: .example.org
matcher:
rule: Host(`.example.org`)
```
```bash
Expand Down
6 changes: 4 additions & 2 deletions en/docs/tutorials/api/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ GOST can use the RESTful API to interact with the GOST process by starting the W

=== "CLI"

```sh
```bash
gost -L http://:8080 -api :18080
```

or

```sh
```bash
gost -L http://:8080 -api "user:pass@:18080?pathPrefix=/api&accesslog=true"
```

Expand All @@ -30,6 +30,8 @@ GOST can use the RESTful API to interact with the GOST process by starting the W
type: tcp
api:
addr: :18080
# also support unix domain socket
# addr: unix:///var/run/gost.sock
pathPrefix: /api
accesslog: true
auth:
Expand Down
2 changes: 2 additions & 0 deletions en/docs/tutorials/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Use the `metrics` option to enable metrics, which is disabled by default.

metrics:
addr: :9000
# also support unix domain socket
# addr: unix:///var/run/gost.sock
path: /metrics
auth:
username: user
Expand Down
Loading

0 comments on commit ad43ced

Please sign in to comment.