Nginx中文文档-ngx_http_core_module(T-V)

本文档包含以下指令:tcp_nodelay、tcp_nopush、try_files、types、types_hash_bucket_size、types_hash_max_size、underscores_in_headers、variables_hash_bucket_size、variables_hash_max_size

tcp_nodelay

语法:tcp_nodelay on | off
默认:tcp_nodelay on
上下文: http, server, location

启用或禁用TCP_NODELAY选项。该功能仅在连接已过渡到keep-alive状态下有效。

tcp_nopush

语法:tcp_nopush on | off
默认:tcp_nopush off
上下文:http, server, location

启用或禁用tcp_nopush功能,在FreeBSD系统上通过TCP_NOPUSH socket选项实现,在Linux通过TCP_CORK socket选项实现。只有在sendfile生效状态下才能启用。启用该选项将允许:

  • Linux和FreeBSD 4.*系统下在一个包中发送响应头和文件开头
  • 在满包中发送一个文件

try_files

语法:try_files fileuri;
try_files file … =code;
默认:—
上下文:server, location

按指定顺序检测文件是否存在,并返回第一个找到的文件,该过程在当前上下文中执行。文件的路径是由root和alias指令以及file参数构成。有可能会通过在名字后面添加“/”检测目录是否存在,例如“$uri/”。如果没有找到任何的文件,则会产生一个内部重定向到最后一个参数uri指定的文件:

location /images/ {
    try_files $uri /images/default.gif;
}

location = /images/default.gif {
    expires 30s;
}

最后一个参数可以指向一个location,如下面的例子所示。从0.7.51版本开始,最后一个参数也可以是一个code

location / {
    try_files $uri $uri/index.html $uri.html =404;
}

代理Mongrel的例子:

location / {
    try_files /system/maintenance.html
              $uri $uri/index.html $uri.html
              @mongrel;
}

location @mongrel {
    proxy_pass http://mongrel;
}

Drupal/FastCGI举例:

location / {
    try_files $uri $uri/ @drupal;
}

location ~ \.php$ {
    try_files $uri @drupal;

    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
    fastcgi_param QUERY_STRING    $args;

    ... other fastcgi_param's
}

location @drupal {
    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to/index.php;
    fastcgi_param SCRIPT_NAME     /index.php;
    fastcgi_param QUERY_STRING    q=$uri&$args;

    ... other fastcgi_param's
}

下面的例子中,

location / {
    try_files $uri $uri/ @drupal;
}

try_files指令等价于:

location / {
    error_page 404 = @drupal;
    log_not_found off;
}

下面的例子,

location ~ \.php$ {
    try_files $uri @drupal;

    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;

    ...
}

try_files指令在将请求发送到FastCGI服务器之前检测文件是否存在。
Wordpress 和 Joomla的例子:

location / {
    try_files $uri $uri/ @wordpress;
}

location ~ \.php$ {
    try_files $uri @wordpress;

    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
    ... other fastcgi_param's
}

location @wordpress {
    fastcgi_pass ...;

    fastcgi_param SCRIPT_FILENAME /path/to/index.php;
    ... other fastcgi_param's
}

types

语法:types { … }
默认:types {
text/html html;
image/gif gif;
image/jpeg jpg;
}
上下文:http, server, location

响应的MIME与文件扩展的对照表,大小写不敏感。多个扩展名可以映射为同一个类型:

types {
    application/octet-stream bin exe dll;
    application/octet-stream deb;
    application/octet-stream dmg;
}

在conf/mime.types文件中定义了一个比较完整的映射表。
要定义一个特殊的location,所有的MIME类型都是application/octet-stream,可以用下面的配置:

location /download/ {
    types        { }
    default_type application/octet-stream;
}

types_hash_bucket_size

语法:types_hash_bucket_size size
默认:types_hash_bucket_size 64
上下文:http, server, location

设置一个类型哈希表的大小。1.5.13版本之前,默认值的大小取决于CPU缓存行。

types_hash_max_size

语法:types_hash_max_size size
默认:types_hash_max_size 1024
上下文:http, server, location

设置类型哈希表最大的大小。

underscores_in_headers

语法:underscores_in_headers on | off
默认:underscores_in_headers off
上下文:http, server

启用或禁用客户端请求头域中的下划线。如果禁用了此功能,客户端请求头域中的下划线会被认为是无效的。
如果该指令定义在sever块中,只对默认的服务器有效。该值同样作用于监听了同一端口和IP的虚拟主机。

variables_hash_bucket_size

语法:variables_hash_bucket_size size
默认:variables_hash_bucket_size 64
上下文:http

设置一个变量哈希表的大小。

variables_hash_max_size

语法:variables_hash_max_size size
默认:variables_hash_max_size 1024
上下文:http

设置最大的变量哈希表大小。1.5.13版本以前,默认值是512.

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

请开启浏览器JavaScript