|
| 1 | +# ngx_http_scgi_module |
| 2 | + |
| 3 | +- [配置示例](#example_configuration) |
| 4 | +- [指令](#directives) |
| 5 | + - [scgi_bind](#scgi_bind) |
| 6 | + - [scgi_buffer_size](#scgi_buffer_size) |
| 7 | + - [scgi_buffering](#scgi_buffering) |
| 8 | + - [scgi_buffers](#scgi_buffers) |
| 9 | + - [scgi_busy_buffers_size](#scgi_busy_buffers_size) |
| 10 | + - [scgi_cache](#scgi_cache) |
| 11 | + - [scgi_cache_background_update](#scgi_cache_background_update) |
| 12 | + - [scgi_cache_bypass](#scgi_cache_bypass) |
| 13 | + - [scgi_cache_key](#scgi_cache_key) |
| 14 | + - [scgi_cache_lock](#scgi_cache_lock) |
| 15 | + - [scgi_cache_lock_age](#scgi_cache_lock_age) |
| 16 | + - [scgi_cache_lock_timeout](#scgi_cache_lock_timeout) |
| 17 | + - [scgi_cache_max_range_offset](#scgi_cache_max_range_offset) |
| 18 | + - [scgi_cache_methods](#scgi_cache_methods) |
| 19 | + - [scgi_cache_min_uses](#scgi_cache_min_uses) |
| 20 | + - [scgi_cache_path](#scgi_cache_path) |
| 21 | + - [scgi_cache_purge](#scgi_cache_purge) |
| 22 | + - [scgi_cache_revalidate](#scgi_cache_revalidate) |
| 23 | + - [scgi_cache_use_stale](#scgi_cache_use_stale) |
| 24 | + - [scgi_cache_valid](#scgi_cache_valid) |
| 25 | + - [scgi_connect_timeout](#scgi_connect_timeout) |
| 26 | + - [scgi_force_ranges](#scgi_force_ranges) |
| 27 | + - [scgi_hide_header](#scgi_hide_header) |
| 28 | + - [scgi_ignore_client_abort](#scgi_ignore_client_abort) |
| 29 | + - [scgi_ignore_headers](#scgi_ignore_headers) |
| 30 | + - [scgi_intercept_errors](#scgi_intercept_errors) |
| 31 | + - [scgi_limit_rate](#scgi_limit_rate) |
| 32 | + - [scgi_max_temp_file_size](#scgi_max_temp_file_size) |
| 33 | + - [scgi_next_upstream](#scgi_next_upstream) |
| 34 | + - [scgi_next_upstream_timeout](#scgi_next_upstream_timeout) |
| 35 | + - [scgi_next_upstream_tries](#scgi_next_upstream_tries) |
| 36 | + - [scgi_no_cache](#scgi_no_cache) |
| 37 | + - [scgi_param](#scgi_param) |
| 38 | + - [scgi_pass](#scgi_pass) |
| 39 | + - [scgi_pass_header](#scgi_pass_header) |
| 40 | + - [scgi_pass_request_body](#scgi_pass_request_body) |
| 41 | + - [scgi_pass_request_headers](#scgi_pass_request_headers) |
| 42 | + - [scgi_read_timeout](#scgi_read_timeout) |
| 43 | + - [scgi_request_buffering](#scgi_request_buffering) |
| 44 | + - [scgi_send_timeout](#scgi_send_timeout) |
| 45 | + - [scgi_socket_keepalive](#scgi_socket_keepalive) |
| 46 | + - [scgi_store](#scgi_store) |
| 47 | + - [scgi_store_access](#scgi_store_access) |
| 48 | + - [scgi_temp_file_write_size](#scgi_temp_file_write_size) |
| 49 | + - [scgi_temp_path](#scgi_temp_path) |
| 50 | + |
| 51 | +`ngx_http_scgi_module` 模块允许将请求传递给 SCGI 服务器。 |
| 52 | + |
| 53 | +<a id="example_configuration"></a> |
| 54 | + |
| 55 | +## 配置示例 |
| 56 | + |
| 57 | +```nginx |
| 58 | +location / { |
| 59 | + include scgi_params; |
| 60 | + scgi_pass localhost:9000; |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +<a id="directives"></a> |
| 65 | + |
| 66 | +## 指令 |
| 67 | + |
| 68 | +### scgi_bind |
| 69 | + |
| 70 | +|\-|说明| |
| 71 | +|:------|:------| |
| 72 | +|**语法**|**scgi_bind** `address [transparent] | off`;| |
| 73 | +|**默认**|——| |
| 74 | +|**上下文**|http、server、location| |
| 75 | + |
| 76 | +使用可选端口(1.11.2)从指定的本地 IP 地址发出到 SCGI 服务器的传出连接。参数值可以包含变量(1.3.12)。特殊值 `off`(1.3.12)取消从先前配置级别继承的 `scgi_bind` 指令的作用,该指令允许系统自动分配本地 IP 地址和端口。 |
| 77 | + |
| 78 | +`transparent` 参数(1.11.0)允许到 SCGI 服务器的传出连接源自非本地 IP 地址,例如,来自一个客户端的真实 IP 地址: |
| 79 | + |
| 80 | +```nginx |
| 81 | +scgi_bind $remote_addr transparent; |
| 82 | +``` |
| 83 | + |
| 84 | +为了使此参数起作用,通常需要使用[超级用户](../核心功能.md#user)权限运行 nginx worker 进程。在 Linux 上,不需要(1.13.8)像指定 `transparent` 参数一样,worker 进程从 master 进程继承 `CAP_NET_RAW` 功能。还需要配置内核路由表以拦截来自 SCGI 服务器的网络流量。 |
| 85 | + |
| 86 | +### scgi_buffer_size |
| 87 | + |
| 88 | +|\-|说明| |
| 89 | +|:------|:------| |
| 90 | +|**语法**|**scgi_buffer_size** `size`;| |
| 91 | +|**默认**|scgi_buffer_size 4k|8k;| |
| 92 | +|**上下文**|http、server、location| |
| 93 | + |
| 94 | +设置用于读取从 SCGI 服务器接收的响应的第一部分的缓冲区的大小(`size`)。这部分通常包含一个小的响应头。默认情况下,缓冲区大小等于一个内存页,即 4K 或 8K,具体取决于平台。然而,它可以做得更小。 |
| 95 | + |
| 96 | +### scgi_buffering |
| 97 | + |
| 98 | +|\-|说明| |
| 99 | +|:------|:------| |
| 100 | +|**语法**|**scgi_buffering** `on` | `off`;| |
| 101 | +|**默认**|scgi_buffering on;| |
| 102 | +|**上下文**|http、server、location| |
| 103 | + |
| 104 | +启用或禁用缓冲来自 SCGI 服务器的响应。 |
| 105 | + |
| 106 | +启用缓冲后,nginx 会尽快从 SCGI 服务器接收响应,并将其保存到 [scgi_buffer_size](#scgi_buffer_size) 和 [scgi_buffers](#scgi_buffers) 指令设置的缓冲区中。如果整个响应不适合放入内存,则可以将其中的一部分保存到磁盘上的临时文件中。写入临时文件由 [scgi_max_temp_file_size](#scgi_max_temp_file_size) 和 [scgi_temp_file_write_size](#scgi_temp_file_write_size) 指令控制。 |
| 107 | + |
| 108 | +禁用缓冲时,会在收到响应时立即同步传递给客户端。nginx 不会尝试从 SCGI 服务器读取整个响应。nginx 一次可以从服务器接收的数据的最大大小由 [scgi_buffer_size](#scgi_buffer_size) 指令设置。 |
| 109 | + |
| 110 | +也可以通过在 **X-Accel-Buffering** 响应头字段中传递 `yes` 或 `no` 来启用或禁用缓冲。可以使用 [scgi_ignore_headers](#scgi_ignore_headers) 指令禁用此功能。 |
| 111 | + |
| 112 | +### scgi_buffers |
| 113 | + |
| 114 | +|\-|说明| |
| 115 | +|:------|:------| |
| 116 | +|**语法**|**scgi_buffers** `number size`;| |
| 117 | +|**默认**|scgi_buffers 8 4k|8k;| |
| 118 | +|**上下文**|http、server、location| |
| 119 | + |
| 120 | +设置用于从 SCGI 服务器读取响应的缓冲区的数量(`number`)和大小(`size`),适用于单个连接。默认情况下,缓冲区大小等于一个内存页,即 4K 或 8K,具体取决于平台。 |
| 121 | + |
| 122 | +### scgi_busy_buffers_size |
| 123 | + |
| 124 | +|\-|说明| |
| 125 | +|:------|:------| |
| 126 | +|**语法**|**scgi_busy_buffers_size** `size`;| |
| 127 | +|**默认**|scgi_busy_buffers_size 8k|16k;| |
| 128 | +|**上下文**|http、server、location| |
| 129 | + |
| 130 | +当启用[缓冲](#scgi_buffering)来自 SCGI 服务器的响应时,限制在响应尚未完全读取时可能忙于向客户端发送响应的缓冲区的总大小(`size`)。同时,其余缓冲区可用于读取响应,如果需要,还可以缓冲部分响应临时文件。默认情况下,`size` 由 [scgi_buffer_size](#scgi_buffer_size) 和 [scgi_buffers](#scgi_buffers) 指令设置的两个缓冲区的大小限制。 |
| 131 | + |
| 132 | +### scgi_cache |
| 133 | + |
| 134 | +|\-|说明| |
| 135 | +|:------|:------| |
| 136 | +|**语法**|**scgi_cache** `zone` | `off`;| |
| 137 | +|**默认**|scgi_cache off;| |
| 138 | +|**上下文**|http、server、location| |
| 139 | + |
| 140 | +定义一个用于缓存的共享内存区域。可以在多个地方使用相同的区域。参数值可以包含变量(1.7.9)。`off` 参数禁用从先前配置级别继承的缓存。 |
| 141 | + |
| 142 | +### scgi_cache_background_update |
| 143 | + |
| 144 | +|\-|说明| |
| 145 | +|:------|:------| |
| 146 | +|**语法**|**scgi_cache_background_update** `on` | `off`;| |
| 147 | +|**默认**|scgi_cache_background_update off;| |
| 148 | +|**上下文**|http、server、location| |
| 149 | +|**提示**|该指令在 1.11.10 版本中出现| |
| 150 | + |
| 151 | +允许启动一个后台子请求以更新过期的缓存项,同时将过时的缓存响应返回给客户端。请注意,在更新时必须[允许](#scgi_cache_use_stale_updating)使用陈旧的缓存响应。 |
| 152 | + |
| 153 | +### scgi_cache_bypass |
| 154 | + |
| 155 | +|\-|说明| |
| 156 | +|:------|:------| |
| 157 | +|**语法**|**scgi_cache_bypass** `string ...`;| |
| 158 | +|**默认**|——| |
| 159 | +|**上下文**|http、server、location| |
| 160 | + |
| 161 | +定义不从缓存中获取响应的条件。如果字符串参数中有一个值不为空且不等于 `0`,则不会从缓存中获取响应: |
| 162 | + |
| 163 | +```nginx |
| 164 | +scgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment; |
| 165 | +scgi_cache_bypass $http_pragma $http_authorization; |
| 166 | +``` |
| 167 | + |
| 168 | +可以与 [scgi_no_cache](#scgi_no_cache) 指令一起使用。 |
| 169 | + |
| 170 | +### scgi_cache_key |
| 171 | + |
| 172 | +|\-|说明| |
| 173 | +|:------|:------| |
| 174 | +|**语法**|**scgi_cache_key** `string`;| |
| 175 | +|**默认**|——| |
| 176 | +|**上下文**|http、server、location| |
| 177 | + |
| 178 | +定义一个用于缓存的 key: |
| 179 | + |
| 180 | +```nginx |
| 181 | +scgi_cache_key localhost:9000$request_uri; |
| 182 | +``` |
| 183 | + |
| 184 | +### scgi_cache_lock |
| 185 | + |
| 186 | +|\-|说明| |
| 187 | +|:------|:------| |
| 188 | +|**语法**|**scgi_cache_lock** `on` | `off`;| |
| 189 | +|**默认**|scgi_cache_lock off;| |
| 190 | +|**上下文**|http、server、location| |
| 191 | +|**提示**|该指令在 1.1.12 版本中出现| |
| 192 | + |
| 193 | +启用后,在将请求传递给 SCGI 服务器,一次只允许一个请求填充根据 [scgi_cache_key](#scgi_cache_key) 指令标识的新缓存元素。同一缓存元素的其他请求将等待响应出现在缓存中或直到 [scgi_cache_lock_timeout](scgi_cache_lock_timeout) 指令设置的时间,缓存此元素的缓存锁释放。 |
| 194 | + |
| 195 | +### scgi_cache_lock_age |
| 196 | + |
| 197 | +|\-|说明| |
| 198 | +|:------|:------| |
| 199 | +|**语法**|**scgi_cache_lock_age** `time`;| |
| 200 | +|**默认**|scgi_cache_lock_age 5s;| |
| 201 | +|**上下文**|http、server、location| |
| 202 | +|**提示**|该指令在 1.7.8 版本中出现| |
| 203 | + |
| 204 | +如果传递给 SCGI 服务器以填充新缓存元素的最后一个请求在指定时间(`time`)内没有完成,则可以将另一个请求传递给 SCGI 服务器。 |
| 205 | + |
| 206 | +### scgi_cache_lock_timeout |
| 207 | + |
| 208 | +|\-|说明| |
| 209 | +|:------|:------| |
| 210 | +|**语法**|**scgi_cache_lock_timeout** `time`;| |
| 211 | +|**默认**|scgi_cache_lock_timeout 5s;| |
| 212 | +|**上下文**|http、server、location| |
| 213 | +|**提示**|该指令在 1.1.12 版本中出现| |
| 214 | + |
| 215 | +设置 [scgi_cache_lock](#scgi_cache_lock) 的超时时间。当时间到期时,请求将被传递给 SCGI 服务器,但响应将不会被缓存。 |
| 216 | + |
| 217 | +> 1.7.8 版本之前响应可以被缓存。 |
| 218 | +
|
| 219 | +### scgi_cache_max_range_offset |
| 220 | + |
| 221 | +|\-|说明| |
| 222 | +|:------|:------| |
| 223 | +|**语法**|**scgi_cache_max_range_offset** `number`;| |
| 224 | +|**默认**|——| |
| 225 | +|**上下文**|http、server、location| |
| 226 | +|**提示**|该指令在 1.11.6 版本中出现| |
| 227 | + |
| 228 | +设置一个字节范围(byte-range)请求的偏移量(以字节为单位)。如果范围超出偏移量,则范围请求将传递给 SCGI 服务器,并且不会缓存响应。 |
| 229 | + |
| 230 | +### scgi_cache_methods |
| 231 | + |
| 232 | +|\-|说明| |
| 233 | +|:------|:------| |
| 234 | +|**语法**|**scgi_cache_methods** `GET \| HEAD \| POST ...`;| |
| 235 | +|**默认**|scgi_cache_methods GET HEAD;| |
| 236 | +|**上下文**|http、server、location| |
| 237 | + |
| 238 | +如果此指令中列出了客户端请求方法,则将缓存响应。`GET` 和 `HEAD` 方法总是添加到列表中,但建议明确指定它们。另请参见 [scgi_no_cache](#scgi_no_cache) 指令。 |
| 239 | + |
| 240 | +### scgi_cache_min_uses |
| 241 | + |
| 242 | +|\-|说明| |
| 243 | +|:------|:------| |
| 244 | +|**语法**|**scgi_cache_min_uses** `number`;| |
| 245 | +|**默认**|scgi_cache_min_uses 1;| |
| 246 | +|**上下文**|http、server、location| |
| 247 | + |
| 248 | +设置缓存响应之前的请求数(`number`)。 |
| 249 | + |
| 250 | +### scgi_cache_path |
| 251 | + |
| 252 | +|\-|说明| |
| 253 | +|:------|:------| |
| 254 | +|**语法**|**scgi_cache_path** `path [levels=levels] [use_temp_path=on\|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on\|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time]`;| |
| 255 | +|**默认**|——| |
| 256 | +|**上下文**|http| |
| 257 | + |
| 258 | +**待续……** |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | +## 原文档 |
| 263 | + |
| 264 | +- [http://nginx.org/en/docs/http/ngx_http_scgi_module.html](http://nginx.org/en/docs/http/ngx_http_scgi_module.html) |
0 commit comments