Nginx proxy基本指令整理2

原创文章,转载请指明出处并保留原文url地址

 

本文主要针对nginx的几个主要cache指令做一个简单的整理,另外部分指令做了实际测试,本文具体包括如下指令:

 

proxy_headers_hash_bucket_sizeproxy_headers_hash_max_size proxy_hide_header proxy_http_version proxy_ignore_client_abort proxy_hide_header proxy_ignore_headersproxy_intercept_errors

 

 

9. proxy_headers_hash_bucket_size 

 

syntax:

 

proxy_headers_hash_bucket_size    size;

 

default:

 

proxy_headers_hash_bucket_size 64;

 

context:

 

http, server, location

 

 

proxy_hide_headerproxy_set_header指令设置hash tablesbucket size尺寸大小。另外,提供了一个单独的文件详细介绍建立哈希表建立方法

 

 

Sets the bucket size for hash tables used by the proxy_hide_header and proxy_set_header directives. Details of setting up hash tables are provided in a separate document.

 

 

 

10. proxy_headers_hash_max_size 

 

syntax:

 

proxy_headers_hash_max_size     size;

 

default:

 

proxy_headers_hash_max_size 512;

 

context:

 

http, server, location

 

设置用于proxy_hide_headerproxy_set_header指令的hash table最大大小。另外,提供了一个单独的文件详细介绍建立哈希表建立方法

 

Sets the maximum size of hash tables used by the proxy_hide_header and proxy_set_header directives. Details of setting up hash tables are provided in a separate document.

 

 

11. proxy_hide_header 

 

syntax:

 

proxy_hide_header    field;

 

default:

 

 

context:

 

http, server, location

 

在默认情况下,nginx不把重方向代理服务器获取来的一些header头(包括:DateServer, X-Pad以及X-Accel-....等指令)传递给客户端。这个proxy_hide_header指令可以指定其他不传递的header到客户端。相反若是需要传递某些头到客户端可以通过proxy_pass_header指令进行

 

By default, nginx does not pass the header fields “Date”, “Server”, “X-Pad”, and “X-Accel-...” from the response of a proxied server to a client. The proxy_hide_header directive sets additional fields that will not be passed. If, on the contrary, the passing of fields needs to be permitted, the proxy_pass_header directive can be used.

 

 

12. proxy_http_version 

 

syntax:

 

proxy_http_version    1.0 | 1.1;

 

default:

 

proxy_http_version 1.0;

 

context:

 

http, server, location

 

该指令出现在版本1.1.4
设置nginx服务器的http版本,默认情况下是1.0版本。为了利用keepalive连接功能,推荐设置1.1版本

 

注:在http1.0版本中,规定每次http请求都需要重新开启一个tcp连接来进行数据的传输,但是由于tcp连接是个昂贵的网络连接,每次都需要重建立连接是非常不划算的功能。

 

http1.1中以及可以通过keepalive指令指示后续http请求可以复用前面已经建立的tcp连接来传递http的各种数据等,因此可以较好的提高效率。

 

 

This directive appeared in version 1.1.4.

 

Sets the HTTP protocol version for proxying. By default, version 1.0 is used. Version 1.1 is recommended for use with keepalive connections.

 

 

13. proxy_ignore_client_abort 

 

syntax:

 

proxy_ignore_client_abort    on | off;

 

default:

 

proxy_ignore_client_abort off;

 

context:

 

http, server, location

 

如果一个客户端不在等待响应而关闭了请求的连接,这个指令将决定是否关闭同一个被代理服务器的连接。

 

Determines should the connection with a proxied server be closed if a client closes a connection without waiting for a response.

 

 

 

14. proxy_hide_header 

 

syntax:

 

proxy_hide_header   field;

 

default:

 

 

context:

 

http, server, location

 

 

默认情况下,nginx不将被代理服务器的如下响应头(http head)传递给客户端,包括Date, Server, X-Pad, and X-Accel-...”。proxy_hide_header 这里可以设置额外的不传递给客户端的http head信息。相反可以使用proxy_pass_header 指令指定将哪些信息传递给客户端。

 

 

By default, nginx does not pass the header fields Date, Server, X-Pad, and X-Accel-...from the response of a proxied server to a client. The proxy_hide_header directive sets additional fields that will not be passed. If, on the contrary, the passing of fields needs to be permitted, the proxy_pass_header directive can be used.

 

 

 

 

15. proxy_ignore_headers

 

syntax:

 

proxy_ignore_headers    field...;

 

default:

 

 

context:

 

http, server, location

 

 

对从被代理服务器返回的响应数据中的一些header信息设置禁止处理。下面信息域能被忽略:X-Accel-Redirect, X-Accel-Expires, X-Accel-Limit-Rate(1.1.6), X-Accel-Buffering(1.1.6), X-Accel-Charset(1.1.6), Expires, Cache-Control, and Set-Cookie(0.8.44).

 

如果没有被禁用,处理这些header具有以下作用:

 

X-Accel-Expires, Expires, Cache-Control, and Set-Cookie”设置响应缓存的参数。

 

X-Accel-Redirect执行内部重定向到指定的URI;
    X-Accel-Limit-Rate设置传输到客户端的响应速率限制;

 

X-Accel-Buffering启用或禁用缓存的响应;
X-Accel-Charset” 设置响应所需的字符集。

 

Disables processing of certain response header fields from the proxied server. The following fields can be ignored: X-Accel-Redirect, X-Accel-Expires, X-Accel-Limit-Rate(1.1.6), X-Accel-Buffering(1.1.6), X-Accel-Charset(1.1.6), Expires, Cache-Control, and Set-Cookie(0.8.44).

 

If not disabled, processing of these header fields has the following effect:

 

X-Accel-Expires, Expires, Cache-Control, and Set-Cookieset parameters of response caching;

 

X-Accel-Redirectperforms an internal redirect to the specified URI;

 

X-Accel-Limit-Ratesets a rate limit for transmission of a response to a client;

 

X-Accel-Bufferingenables or disables buffering of a response;

 

X-Accel-Charsetsets the desired charset of a response.

 

 

16. proxy_intercept_errors 

 

syntax:

 

proxy_intercept_errors    on | off;

 

default:

 

proxy_intercept_errors off;

 

context:

 

http, server, location

 

确定当被代理服务器的响应返回码大于或者等400时,是否需要将请求传递给客户端或者重定向到nginx进行处理,通过error_page指令。

 

Determines whether proxied responses with codes greater than or equal to 400 should be passed to a client or be redirected to nginx for processing using the error_page directive.

 

发表评论