@@ -817,6 +817,283 @@ proxy_pass http://unix:/tmp/backend.socket:/uri/;
817
817
818
818
允许将[已禁用](#proxy_hide_header)的头字段从代理服务器传递到客户端。
819
819
820
+ ### proxy_pass_request_body
821
+
822
+ |\-|说明|
823
+ |------:|------|
824
+ |**语法**|**proxy_pass_request_body** `on` | `off`;|
825
+ |**默认**|proxy_pass_request_body on;|
826
+ |**上下文**|http、server、location|
827
+
828
+ 指示是否将原始请求体传递给代理服务器。
829
+
830
+ ```nginx
831
+ location /x-accel-redirect-here/ {
832
+ proxy_method GET;
833
+ proxy_pass_request_body off;
834
+ proxy_set_header Content-Length "";
835
+
836
+ proxy_pass ...
837
+ }
838
+ ```
839
+
840
+ 另请参阅 [ proxy_set_header] ( #proxy_set_header ) 和 [ proxy_pass_request_headers] ( #proxy_pass_request_headers ) 指令。
841
+
842
+ ### proxy_pass_request_headers
843
+
844
+ | \- | 说明|
845
+ | ------:| ------|
846
+ | ** 语法** | ** proxy_pass_request_headers** ` on ` | ; ` off ` ;|
847
+ | ** 默认** | proxy_pass_request_headers on;|
848
+ | ** 上下文** | http、server、location|
849
+
850
+ 指示是否将原始请求的 header 字段传递给代理服务器。
851
+
852
+ ``` nginx
853
+ location /x-accel-redirect-here/ {
854
+ proxy_method GET;
855
+ proxy_pass_request_headers off;
856
+ proxy_pass_request_body off;
857
+
858
+ proxy_pass ...
859
+ }
860
+ ```
861
+
862
+ 另请参阅 [ proxy_set_header] ( #proxy_set_header ) 和 [ proxy_pass_request_body] ( #proxy_pass_request_body ) 指令。
863
+
864
+ ### proxy_read_timeout
865
+
866
+ | \- | 说明|
867
+ | ------:| ------|
868
+ | ** 语法** | ** proxy_read_timeout** ` time ` ;|
869
+ | ** 默认** | proxy_read_timeout 60s;|
870
+ | ** 上下文** | http、server、location|
871
+
872
+ 定义从代理服务器读取响应的超时时间。该超时时间仅针对两个连续的读操作之间设置,而不是整个响应的传输过程。如果代理服务器在该时间内未传输任何内容,则关闭连接。
873
+
874
+ ### proxy_redirect
875
+
876
+ | \- | 说明|
877
+ | ------:| ------|
878
+ | ** 语法** | ** proxy_redirect** ` default ` ;<br />** proxy_redirect** ` off ` ;<br />** proxy_redirect** ` redirect replacement ` ;|
879
+ | ** 默认** | proxy_redirect default;|
880
+ | ** 上下文** | http、server、location|
881
+
882
+ 设置代理服务器响应 header 中的 ** Location** 和 ** Refresh** 字段应要更改的文本。假设代理服务器返回header 字段为 ` Location: http://localhost:8000/two/some/uri/ ` 。指令
883
+
884
+ ``` nginx
885
+ proxy_redirect http://localhost:8000/two/ http://frontend/one/;
886
+ ```
887
+
888
+ 将此字符串重写为 ` Location: http://frontend/one/some/uri/ ` 。
889
+
890
+ ` replacement ` 中可能省略了服务器名称:
891
+
892
+ ``` nginx
893
+ proxy_redirect http://localhost:8000/two/ /;
894
+ ```
895
+
896
+ 然后如果不是来自 80 端口,则将插入主服务器的名称和端口。
897
+
898
+ ` default ` 参数指定的默认替换使用 [ location] ( ngx_http_core_module.md#location ) 和 [ proxy_pass] ( ngx_http_proxy_module.md#proxy_pass ) 指令的参数。因此,以下两种配置是等效的:
899
+
900
+ ``` nginx
901
+ location /one/ {
902
+ proxy_pass http://upstream:port/two/;
903
+ proxy_redirect default;
904
+ ```
905
+
906
+ ``` nginx
907
+ location /one/ {
908
+ proxy_pass http://upstream:port/two/;
909
+ proxy_redirect http://upstream:port/two/ /one/;
910
+ ```
911
+
912
+ 如果使用变量指定 [ proxy_pass] ( ngx_http_proxy_module.md#proxy_pass ) ,则不允许使用 ` default ` 参数。
913
+
914
+ ` replacement ` 字符串可以包换变量:
915
+
916
+ ``` nginx
917
+ proxy_redirect http://localhost:8000/ http://$host:$server_port/;
918
+ ```
919
+
920
+ ` redirect ` 也可以包含变量(1.1.11 版本):
921
+
922
+ ``` nginx
923
+ proxy_redirect http://$proxy_host:8000/ /;
924
+ ```
925
+
926
+ 可以使用正则表达式指定指令(1.1.11)。在这种情况下,` redirect ` 应该以 ` ~ ` 符号开头,以区分大小写匹配,或者使用 ` ~* ` 符号以区分大小写匹配。正则表达式可以包含命名和位置捕获,并且 ` replacement ` 可以引用它们:
927
+
928
+ ``` nginx
929
+ proxy_redirect ~^(http://[^:]+):\d+(/.+)$ $1$2;
930
+ proxy_redirect ~*/user/([^/]+)/(.+)$ http://$1.example.com/$2;
931
+ ```
932
+
933
+ ` off ` 参数取消所有 ` proxy_redirect ` 指令对当前级别的影响:
934
+
935
+ ``` nginx
936
+ proxy_redirect off;
937
+ proxy_redirect default;
938
+ proxy_redirect http://localhost:8000/ /;
939
+ proxy_redirect http://www.example.com/ /;
940
+ ```
941
+
942
+ 使用此指令,还可以将主机名添加到代理服务器发出的相对重定向:
943
+
944
+ ``` nginx
945
+ proxy_redirect / /;
946
+ ```
947
+
948
+ ### proxy_request_buffering
949
+
950
+ | \- | 说明|
951
+ | ------:| ------|
952
+ | ** 语法** | ** proxy_request_buffering** ` on ` | ; ` off ` ;|
953
+ | ** 默认** | proxy_request_buffering on;|
954
+ | ** 上下文** | http、server、location|
955
+ | ** 提示** | 该指令在 1.7.11 版本中出现|
956
+
957
+ 启用或禁用客户端请求体缓冲。
958
+
959
+ 启用缓冲后,在将请求发送到代理服务器之前,将从客户端[ 读取] ( ngx_http_core_module.md#client_body_buffer_size ) 整个请求体。
960
+
961
+ 禁用缓冲时,请求体在收到时立即发送到代理服务器。在这种情况下,如果 nginx 已经开始发送请求体,则无法将请求传递给[ 下一个服务器] ( #proxy_next_upstream ) 。
962
+
963
+ 当使用 HTTP/1.1 分块传输编码发送原始请求体时,无论指令值如何,都将缓冲请求体,除非为代理[ 启用] ( #proxy_http_version ) 了 HTTP/1.1。
964
+
965
+ ### proxy_send_lowat
966
+
967
+ | \- | 说明|
968
+ | ------:| ------|
969
+ | ** 语法** | ** proxy_send_lowat** ` size ` ;|
970
+ | ** 默认** | proxy_send_lowat 0;|
971
+ | ** 上下文** | http、server、location|
972
+
973
+ 如果指令设置为非零值,则 nginx 将尝试通过使用 [ kqueue] ( ../../介绍/连接处理方式.md#kqueue ) 方法的 ` NOTE_LOWAT ` 标志或有指定大小的 ` SO_SNDLOWAT ` 套接字选项来最小化到代理服务器的传出连接上的发送操作数。
974
+
975
+ 在 Linux、Solaris 和 Windows 上忽略此指令。
976
+
977
+ ### proxy_send_timeout
978
+
979
+ | \- | 说明|
980
+ | ------:| ------|
981
+ | ** 语法** | ** proxy_send_timeout** ` time ` ;|
982
+ | ** 默认** | proxy_send_timeout 60s;|
983
+ | ** 上下文** | http、server、location|
984
+
985
+ 设置将请求传输到代理服务器的超时时间。超时时间仅作用于两个连续的写操作之间,而不是整个请求的传输过程。如果代理服务器在该时间内未收到任何内容,则关闭连接。
986
+
987
+ ### proxy_set_body
988
+
989
+ | \- | 说明|
990
+ | ------:| ------|
991
+ | ** 语法** | ** proxy_set_body** ` value ` ;|
992
+ | ** 默认** | ——|
993
+ | ** 上下文** | http、server、location|
994
+
995
+ 允许重新定义传递给代理服务器的请求体。该值可以包含文本、变量及其组合。
996
+
997
+ ### proxy_set_header
998
+
999
+ | \- | 说明|
1000
+ | ------:| ------|
1001
+ | ** 语法** | ** proxy_set_header** ` filed value ` ;|
1002
+ | ** 默认** | ** proxy_set_header** ` Host $proxy_host ` ;<br />** proxy_set_header** ` Connection close ` ;|
1003
+ | ** 上下文** | http、server、location|
1004
+
1005
+ 允许将字段重新定义或附加到[ 传递] ( #proxy_pass_request_headers ) 给代理服务器的请求 header。该值可以包含文本、变量及其组合。当且仅当在当前级别上没有定义 ` proxy_set_header ` 指令时,这些指令才从上层级别继承。默认情况下,只重新定义了两个字段:
1006
+
1007
+ ``` nginx
1008
+ proxy_set_header Host $proxy_host;
1009
+ proxy_set_header Connection close;
1010
+ ```
1011
+
1012
+ 如果启用了缓存,则来自原始请求的 header 字段 ** If-Modified-Since** 、** If-Unmodified-Since** 、** If-None-Match** 、** If-Match** 、** Range** 和 ** If-Range** 不会传递给代理服务器。
1013
+
1014
+ 一个未经更改的请求头(header)字段 ** Host** 可以像这样传递:
1015
+
1016
+ ``` nginx
1017
+ proxy_set_header Host $http_host;
1018
+ ```
1019
+
1020
+ 但是,如果客户端请求 header 中不存在此字段,则不会传递任何内容。在这种情况下,最好使用 ` $host ` 变量 —— 它的值等于 ** Host** 请求头字段中的服务器名称,或者如果此字段不存在则等于主服务器名称:
1021
+
1022
+ ``` nginx
1023
+ proxy_set_header Host $host;
1024
+ ```
1025
+
1026
+ 此外,服务器名称可以与代理服务器的端口一起传递:
1027
+
1028
+ ``` nginx
1029
+ proxy_set_header Host $host:$proxy_port;
1030
+ ```
1031
+
1032
+ 如果头字段的值为空字符串,则此字段将不会传递给代理服务器:
1033
+
1034
+ ``` nginx
1035
+ proxy_set_header Accept-Encoding "";
1036
+ ```
1037
+
1038
+ ### proxy_socket_keepalive
1039
+
1040
+ | \- | 说明|
1041
+ | ------:| ------|
1042
+ | ** 语法** | ** proxy_socket_keepalive** ` on ` | ; ` off ` ;|
1043
+ | ** 默认** | proxy_socket_keepalive off;|
1044
+ | ** 上下文** | http、server、location|
1045
+ | ** 提示** | 该指令在 1.15.6 版本中出现|
1046
+
1047
+ 配置到代理服务器的传出连接的 ** TCP keepalive** 行为。默认情况下,操作系统的设置对 socket 有影响。如果指令设置为值 ` on ` ,则为 socket 打开 ` SO_KEEPALIVE ` socket 选项。
1048
+
1049
+ ### proxy_ssl_certificate
1050
+
1051
+ | \- | 说明|
1052
+ | ------:| ------|
1053
+ | ** 语法** | ** proxy_ssl_certificate** ` file ` ;|
1054
+ | ** 默认** | ——|
1055
+ | ** 上下文** | http、server、location|
1056
+ | ** 提示** | 该指令在 1.7.8 版本中出现|
1057
+
1058
+ 指定一个 PEM 格式的证书文件(` file ` ),该证书用于 HTTPS 代理服务器身份验证。
1059
+
1060
+ ### proxy_ssl_certificate_key
1061
+
1062
+ | \- | 说明|
1063
+ | ------:| ------|
1064
+ | ** 语法** | ** proxy_ssl_certificate_key** ` file ` ;|
1065
+ | ** 默认** | ——|
1066
+ | ** 上下文** | http、server、location|
1067
+ | ** 提示** | 该指令在 1.7.8 版本中出现|
1068
+
1069
+ 指定一个有密钥的 PEM 格式文件(` file ` ),用于 HTTPS 代理服务器身份验证。
1070
+
1071
+ 可以指定 ` engine:name:id ` 来代替 ` file ` (1.7.9),它将从名为 ` name ` 的 OpenSSL 引擎加载 id 为 ` id ` 的密钥。
1072
+
1073
+ ### proxy_ssl_ciphers
1074
+
1075
+ | \- | 说明|
1076
+ | ------:| ------|
1077
+ | ** 语法** | ** proxy_ssl_ciphers** ` ciphers ` ;|
1078
+ | ** 默认** | proxy_ssl_ciphers DEFAULT;|
1079
+ | ** 上下文** | http、server、location|
1080
+ | ** 提示** | 该指令在 1.5.6 版本中出现|
1081
+
1082
+ 指定对 HTTPS 代理服务器的请求已启用密码。密码应为 OpenSSL 库支持的格式。
1083
+
1084
+ 可以使用 ` openssl ciphers ` 命令查看完整的支持列表。
1085
+
1086
+ ### proxy_ssl_crl
1087
+
1088
+ | \- | 说明|
1089
+ | ------:| ------|
1090
+ | ** 语法** | ** proxy_ssl_crl** ` file ` ;|
1091
+ | ** 默认** | ——|
1092
+ | ** 上下文** | http、server、location|
1093
+ | ** 提示** | 该指令在 1.7.0 版本中出现|
1094
+
1095
+ 指定一个包含已撤销证书(CRL)的 PEM 格式的文件(` file ` ),用于[ 验证] ( #proxy_ssl_verify ) HTTPS 代理服务器的证书。
1096
+
820
1097
** 待续……**
821
1098
822
1099
## 原文档
0 commit comments