Skip to content

Commit 66eab09

Browse files
committed
翻译redir的指令
1 parent b317776 commit 66eab09

File tree

13 files changed

+223
-91
lines changed

13 files changed

+223
-91
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Caddy 是一款使用 Go 语言的简单易用的单文件网页服务器,原
5858
## 进度记录
5959

6060
- 2017-06-10, 启动项目
61-
- 2015-06-29, 项目基础翻译完成
62-
- 2015-07-, 校对审核
61+
- 2017-06-29, 项目基础翻译完成
62+
- 2017-07-, 校对审核
6363

6464
## 如何参与
6565

docs-cn/HTTP Directives/basicauth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ basicauth path username password
1515
* **username** 用户名
1616
* **password** 密码
1717

18-
这个语法对于使用默认的范围标志 Restricted(受限)来保护单个文件或基本路径/目录是非常方便的,如果要保护多个资源或指定范围,可以使用以下的写法:
18+
这个语法对于使用默认的范围标志 "Restricted(受限)"来保护单个文件或基本路径/目录是非常方便的,如果要保护多个资源或指定范围,可以使用以下的写法:
1919

2020
```
2121
basicauth username password {

docs-cn/HTTP Directives/bind.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# http.bind
2-
bind overrides the host to which the server should bind. Normally, the listener binds to the wildcard host. However, you may force the listener to bind to another hostname or IP instead. This directive accepts only a host, not a port.
3-
绑定将覆盖服务器应绑定到的主机,正常情况下,侦听器绑定到通配符主机。 但是,您可能会强制监听器绑定到另一个主机名或IP。 这个指令仅接受的是主机名而不是端口。
2+
bind 将覆盖服务器绑定到的主机,正常情况下,侦听器绑定到匹配的主机,但是,你可能会强制监听绑定到另一个主机名或IP。这个指令仅接受的是主机名而不是端口。
43

5-
Note that binding sites inconsistently may result in unintended consequences. For example, if two sites on the same port resolve to 127.0.0.1 and only one of those sites is configured with bind 127.0.0.1, then only one site will be accessible since the other will bind to the port without a specific host; the OS will choose the more specific matching socket. (Virtual hosts are not shared across different listeners.)
6-
注意,绑定站点不一致可能会导致意想不到的后果。 例如,如果同一端口上的两个站点解析为127.0.0.1,并且只有一个站点配置了bind 127.0.0.1,则只有一个站点将可访问,因为其他站点将绑定到没有特定主机的端口; 操作系统将选择更具体的匹配插座。 (虚拟主机不会在不同的监听器之间共享。)
4+
注意,绑定站点不一致可能会导致意想不到的后果。 例如,如果同一端口上的两个站点都解析到127.0.0.1,并且只有一个站点配置了bind 127.0.0.1,则只有一个站点将可访问,因为其他站点将绑定到没有特定主机的端口,操作系统将会选择最匹配的socket。(虚拟主机不会在不同的监听器之间共享)
75

86
## 语法
97
```
108
bind host
119
```
12-
1310
* **host** 要绑定到的主机名(或IP地址)
1411

1512
## 例子
16-
To make your socket accessible only to that machine, bind to IP 127.0.0.1 (localhost):
17-
要使你的socket只能访问该机器,请绑定到IP 127.0.0.1(localhost):
13+
要使你的socket只能访问该机器,请绑定IP地址到127.0.0.1(localhost):
1814

1915
```
2016
bind 127.0.0.1

docs-cn/HTTP Directives/fastcgi.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# http.fastcgi
2-
fastcgi proxies requests to a FastCGI server. Even though the most common use for this directive is to serve PHP sites, it is by default a generic FastCGI proxy. This directive may be used multiple times with different request paths.
3-
fastcgi代理请求到FastCGI服务器,尽管这个指令最常见的用法是为PHP站点提供服务,默认情况下是通用的FastCGI代理,该指令可以使用不同的请求路径多次使用。
2+
fastcgi代理请求到FastCGI服务器,尽管这个指令最常见的用法是为PHP站点提供服务,默认情况下是通用的FastCGI代理,该指令可以多次使用不同的请求路径。
43

54
## 语法
65
```
@@ -34,10 +33,11 @@ connect_timeout is the time allowed for connecting to the backend. Must be a dur
3433
read_timeout is the time allowed to read a response from the backend. Must be a duration value.
3534
send_timeout is the time allowed to send a request to the backend. Must be a duration value.
3635

37-
## Presets
36+
## 预设
3837
A preset is shorthand for a certain FastCGI configuration. These presets are available:
38+
预设是一个快速的FastCGI配置,这些预置可用如下:
3939

40-
php is shorthand for:
40+
PHP简写为:
4141

4242
```
4343
ext .php
@@ -46,14 +46,16 @@ index index.php
4646
```
4747

4848
You do not need to specify the individual configuration settings for a preset. However, you can overwrite its individual settings if needed by declaring them manually.
49+
你不需要为预置指定单独的配置设置,但是,如果需要,可以手动声明它的单独设置。
50+
您不需要为预设指定各个配置设置。 但是,如果需要,可以手动声明它们来覆盖其各个设置。
4951

5052
## 例子
5153
在127.0.0.1:9000处理FastCGI响应的所有请求:
5254
```
5355
fastcgi / 127.0.0.1:9000
5456
```
5557

56-
Forward all requests in /blog to a PHP site (like WordPress) being served with php-fpm:
58+
将/blog中的所有请求转发到php-fpm提供的PHP站点(如WordPress):
5759
```
5860
fastcgi /blog/ 127.0.0.1:9000 php
5961
```
@@ -65,6 +67,7 @@ fastcgi / 127.0.0.1:9001 {
6567
}
6668
```
6769
With PHP preset, but overriding the ext property:
70+
使用PHP预设,但覆盖ext属性:
6871

6972
```
7073
fastcgi / 127.0.0.1:9001 php {

docs-cn/HTTP Directives/header.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ header path name value
1212
* **name** 是字段的名称,前缀用连字符(-)删除头或加号(+)来追加而不是覆盖。
1313
* **value** 是字段的值, 也可以使用[placeholders(占位符)](../placeholders.md)插入动态值。
1414

15-
16-
This directive can be used multiple times, or you can group multiple custom header fields for the same path:
1715
这个指令可以多次使用,也可以在相同的路径分组多个自定义头字段:
1816

1917
```

docs-cn/HTTP Directives/pprof.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# http.pprof
2+
pprof publishes runtime profiling data at endpoints under /debug/pprof. You can visit /debug/pprof on your site for an index of the available endpoints.
3+
pprof在/ debug / pprof下的端点发布运行时分析数据。 您可以访问/ debug / pprof在您的站点上的可用端点的索引。
4+
5+
This is a debugging tool. Certain requests (such as collecting execution traces) can be slow. If you use pprof on a live site, consider restricting access or enabling it only temporarily.
6+
> 这是一个调试工具。 某些请求(如收集执行跟踪)可能很慢。 如果您在现场网站上使用pprof,请考虑限制访问或仅暂时启用它。
7+
8+
For more information, please see Go's pprof documentation and read Profiling Go Programs.
9+
有关更多信息,请参阅Go的pprof文档并阅读Profiling Go程序。
10+
11+
## 语法
12+
```
13+
pprof
14+
```
15+
16+
## 例子
17+
Enable pprof endpoints:
18+
启用pprof端点:
19+
20+
```
21+
pprof
22+
```

docs-cn/HTTP Directives/proxy.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ proxy /stream localhost:8080 {
131131
```
132132

133133
代理所有请求除了/static或/robots.txt之外的内容
134-
135134
```
136135
proxy / backend:1234 {
137136
except /static /robots.txt

docs-cn/HTTP Directives/redir.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
# http.redir
2-
redir sends the client an HTTP redirect status code if the URL matches the specified pattern. It is also possible to make a redirect conditional.
3-
如果URL匹配指定的模式,redir会向客户端发送HTTP重定向状态代码,也可以使重定向有条件。
2+
如果URL匹配指定的模式,redir会向客户端发送HTTP重定向状态码,也可以使重定向有条件。
43

54
## 语法
65
```
76
redir from to [code]
87
```
8+
* **from** 要匹配的请求路径(它必须完全匹配,除了/,这是一个全部)。
9+
* **to** 要重定向到的路径(可以使用请求占位符)。
10+
* **code** 用于响应HTTP的状态码,必须在[300-308]的之间(不包括306)。也可以是针对浏览器的meta标记重定向,默认状态码为301表示永久移动。
911

10-
from is the request path to match (it must match exactly, except for /, which is a catch-all).
11-
to is the path to redirect to (may use request placeholders).
12-
code is the HTTP status code to respond with; must be in the range [300-308] excluding 306. May also be meta to issue meta tag redirect for browsers. The default status code is 301 Moved Permanently.
13-
To create a permanent, "catch-all" redirect, omit the from value:
14-
12+
要创建永久的"catch-all"重定向,请忽略from值:
1513
```
1614
redir to
1715
```
1816

19-
If you have a lot of redirects, share a redirect code by making a table:
20-
17+
如果你有很多重定向,可以通过制表来共享重定向码:
2118
```
2219
redir [code] {
2320
from to [code]
2421
}
2522
```
2623

27-
Each line defines a redirect and may optionally overwrite the redirect code defined at the top of the table. If no redirect code is specified, the default is used.
24+
每行都可以定义一个重定向,并可以可选地覆盖在表顶部定义的重定向码,如果未指定重定向代码,则使用默认值。
2825

2926
一组重定向也可以有条件的:
3027
```
@@ -35,26 +32,24 @@ redir [code] {
3532
}
3633
```
3734

38-
if specifies a rewrite condition. Multiple ifs are AND-ed together by default. a and b are any string and may use request placeholders. cond is the condition, with possible values explained in rewrite (which also has an if statement).
39-
if_op specifies how the ifs are evaluated; the default is and.
40-
Preserving Path
41-
By default, redirects are from precisely matching paths to the precise location you've defined. You can preserve the path or other portions of the request URL by using replaceable values, such as {uri} or {path}, in any "to" argument. Only request placeholders are supported.
35+
* **if** 指定重写的条件,默认情况下,多个ifs都是和的关系。 a和b是任意字符串,可以使用请求占位符,cond是条件,可能的值在重写中说明(也有一个if语句)。
36+
* **if_op** 指定如何确定ifs的关系,默认是和。
4237

43-
## 例子
44-
When a request comes in for /resources/images/photo.jpg, redirect to /resources/images/drawing.jpg with HTTP 307 (Temporary Redirect) status code:
38+
## 保护路径
39+
默认情况下,重定向是从精确匹配的路径到你定义的精确位置,你可以在任意"to"的参数中使用可替换值(例如{uri}或{path})来保留请求URL的路径或其他部分,仅支持请求占位符。
4540

41+
## 例子
42+
当请求/resources/images/photo.jpg时,使用HTTP 307状态码(临时重定向)重定向到/resources/images/drawing.jpg:
4643
```
4744
redir /resources/images/photo.jpg /resources/images/drawing.jpg 307
4845
```
4946

50-
Redirect all requests to https://newsite.com while preserving the request URI:
51-
47+
将所有请求重定向到https://newsite.com,同时保留请求的URI:
5248
```
5349
redir https://newsite.com{uri}
5450
```
5551

56-
Defining multiple redirections that share a 307 status code, except the last one:
57-
52+
定义多个重定向的307状态码,除了最后一个:
5853
```
5954
redir 307 {
6055
/foo /info/foo
@@ -63,8 +58,7 @@ redir 307 {
6358
}
6459
```
6560

66-
Redirect only if the forwarded protocol is HTTP:
67-
61+
只有转发协议是HTTP时才重定向:
6862
```
6963
redir 301 {
7064
if {>X-Forwarded-Proto} is http

docs-cn/HTTP Directives/tls.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# tls
2+
tls configures HTTPS connections. Since HTTPS is enabled automatically, this directive should only be used to deliberately override default settings. Use with care, if at all.
3+
4+
Caddy supports SNI (Server Name Indication), so you can serve multiple HTTPS sites from the same port on your machine. In addition, Caddy implements OCSP stapling for all qualifying certificates. Caddy also automatically rotates all TLS session ticket keys periodically.
5+
6+
The tls directive will ignore sites that are explicitly defined to be http:// or are on port 80. This allows you to use the tls directive in a server block that is shared with both HTTP and HTTPS sites.
7+
8+
If not all the hostnames are not known when starting the server, you can use the On-Demand TLS feature, which issues certificates during the TLS handshake rather than at startup.
9+
10+
Caddy ships with sane defaults for cipher suites, curves, key types, and protocols. Their exact selection and ordering may change at any time with new releases. You probably do not need to change them yourself. Adjust the TLS configuration at your own risk.
11+
12+
## 语法
13+
tls off
14+
Disables TLS for the site. Not recommended unless you have a good reason. With TLS off, automatic HTTPS is also disabled, so the default port (2015) will not be changed.
15+
16+
tls email
17+
email is the email address to use with which to generate a certificate with a trusted CA. By providing an email here you will not be prompted when you run Caddy.
18+
Although the above syntax is not needed to enable TLS, it allows you to specify the email address used for your CA account, instead of prompting for one or using another one from a previous run.
19+
20+
To use Caddy with your own certificate and key:
21+
22+
tls cert key
23+
cert is the certificate file. If the certificate is signed by a CA, this certificate file should be a bundle: a concatenation of the server's certificate followed by the CA's certificate (root certificate usually not necessary).
24+
key is the server's private key file which matches the certificate file.
25+
You can use this directive multiple times to specify multiple certificate and key pairs.
26+
27+
Or to have Caddy generate and use an untrusted, self-signed certificate in memory:
28+
29+
tls self_signed
30+
The above syntaxes use Caddy's default TLS settings with your own certificate and key or a self-signed certificate, which should be sufficient in most cases.
31+
32+
Advanced users may open a settings block for more control, optionally specifying their own certificate and key:
33+
34+
tls [cert key] {
35+
protocols min max
36+
ciphers ciphers...
37+
curves curves...
38+
clients [request|require|verify_if_given] clientcas...
39+
load dir
40+
max_certs limit
41+
key_type type
42+
dns provider
43+
alpn protos...
44+
must_staple
45+
}
46+
cert and key are the same as above.
47+
protocols specifies the minimum and maximum protocol versions to support. See below for valid values. If min and max are the same, it need only be specified once.
48+
ciphers is a list of space-separated ciphers that will be supported, overriding the defaults. If you list any, only the ones you specify will be allowed and preferred in the order given. See below for valid values.
49+
curves is a list of space-separated curves that will be supported in the given order, overriding the defaults. Valid curves are listed below.
50+
clients is a list of space-separated client root CAs used for verification during TLS client authentication. If used, clients will be asked to present their certificate by their browser, which will be verified against this list of client certificate authorities. A client will not be allowed to connect if their certificate was not signed by one of these root CAs. Note that this setting applies to the entire listener, not just a single site. You may modify the strictness of client authentication using one of the keywords before the list of client CAs:
51+
request merely asks a client to provide a certificate, but will not fail if none is given or if an invalid one is presented.
52+
require requires a client certificate, but will not verify it.
53+
verify_if_given will not fail if none is presented, but reject all that do not pass verification.
54+
The default, if no flag is set but a CA file found, is to do both: to require client certificates and validate them.
55+
load is a directory from which to load certificates and keys. The entire directory and its subfolders will be walked in search of .pem files. Each .pem file must contain the PEM-encoded certificate (chain) and key blocks, concatenated together.
56+
max_certs enables On-Demand TLS, which obtains certificates during the first handshake requiring it rather than at startup. This is NOT recommended if the full hostname is given in the Caddyfile and known at startup! The limit value restricts the number of certificates allowed to be issued on demand (during TLS handshake) for this site. It must be a positive integer. This value gets reset after the process exits (but is preserved through reloads).
57+
key_type is the type of key to use when generating keys for certificates (only applies to managed or TLS or self-signed certificates). Valid values are rsa2048, rsa4096, rsa8192, p256, and p384. Default is currently rsa2048.
58+
dns is the name of a DNS provider; specifying it enables the DNS challenge. Note that you need to give cred
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http.websocket
2+
websocket facilitates a WebSocket server/proxy. A command is executed when a new WebSocket connection is made and Caddy relays the client's connection to the command.
3+
4+
Any command can be executed as long as it takes input from stdin and writes to stdout, as this is how it will communicate with the WebSocket client. The command does not need to know that it is talking to a Web Socket client; just use stdin and stdout.
5+
6+
Caddy will not make any effort to keep the backend process alive while a client is connected. It is the developer's responsibility to ensure the program does not terminate until the client is ready to close the connection or would be ready for it to terminate.
7+
8+
Note that HTTP/2 does not support protocol upgrade, so you may have to disable HTTP/2 in order to use this directive successfully on secure connections.
9+
10+
## 语法
11+
websocket [path] command
12+
13+
path is the base path to match with the request URL
14+
command is the command to execute
15+
If path is omitted, a default path of / is assumed (meaning all requests).
16+
17+
## 例子
18+
Simple WebSockets echo server:
19+
20+
websocket /echo cat

0 commit comments

Comments
 (0)