blob: 4350ab157fde4868ac9a1033c63f82f3d438a3e5 [file] [log] [blame]
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001
Igor Sysoevd90282d2004-09-28 08:34:51 +00002/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev4e9393a2003-01-09 05:36:00 +00007#include <ngx_config.h>
Igor Sysoev4e9393a2003-01-09 05:36:00 +00008#include <ngx_core.h>
Igor Sysoev6253ca12003-05-27 12:18:54 +00009#include <ngx_http.h>
Igor Sysoev4e9393a2003-01-09 05:36:00 +000010
Igor Sysoev1b735832004-11-11 14:07:14 +000011
Igor Sysoev94e32ce2006-04-07 14:08:04 +000012typedef struct {
Igor Sysoev722231f2007-02-14 18:51:19 +000013 u_char *name;
Igor Sysoev94e32ce2006-04-07 14:08:04 +000014 uint32_t method;
15} ngx_http_method_name_t;
16
17
Igor Sysoev64304df2007-01-24 09:14:08 +000018#define NGX_HTTP_REQUEST_BODY_FILE_OFF 0
19#define NGX_HTTP_REQUEST_BODY_FILE_ON 1
Igor Sysoevcd5b99a2007-01-25 08:45:04 +000020#define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
Igor Sysoev64304df2007-01-24 09:14:08 +000021
22
Igor Sysoeve55988c2008-05-24 14:14:13 +000023static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r);
24static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r,
25 ngx_http_location_tree_node_t *node);
Igor Sysoev4e9393a2003-01-09 05:36:00 +000026
Igor Sysoev899b44e2005-05-12 14:58:06 +000027static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
Igor Sysoev890fc962003-07-20 21:15:59 +000028static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
29static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
30static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
31static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
Igor Sysoevaa828612005-02-09 14:31:07 +000032 void *parent, void *child);
Igor Sysoev890fc962003-07-20 21:15:59 +000033static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
34static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
Igor Sysoevaa828612005-02-09 14:31:07 +000035 void *parent, void *child);
Igor Sysoevdc479b42003-03-20 16:09:44 +000036
Igor Sysoev805d9db2005-02-03 19:33:37 +000037static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000038 void *dummy);
Igor Sysoev805d9db2005-02-03 19:33:37 +000039static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000040 void *dummy);
Igor Sysoev22f6d862008-12-11 10:21:08 +000041static ngx_int_t ngx_http_core_regex_location(ngx_conf_t *cf,
42 ngx_http_core_loc_conf_t *clcf, ngx_str_t *regex, ngx_uint_t caseless);
Igor Sysoev805d9db2005-02-03 19:33:37 +000043
44static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000045 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000046static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
Igor Sysoevaa828612005-02-09 14:31:07 +000047 void *conf);
Igor Sysoev4e9393a2003-01-09 05:36:00 +000048
Igor Sysoev805d9db2005-02-03 19:33:37 +000049static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000050 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000051static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000052 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000053static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev94e32ce2006-04-07 14:08:04 +000054static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
55 void *conf);
Igor Sysoev385af282008-07-30 12:34:04 +000056static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd,
57 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000058static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000059 void *conf);
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +000060static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
61 void *conf);
Igor Sysoev140c7552007-09-01 12:12:48 +000062static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
63 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000064static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000065 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000066static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000067 void *conf);
Igor Sysoev899b44e2005-05-12 14:58:06 +000068static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
69 void *conf);
Igor Sysoev14c84222007-11-30 22:08:29 +000070static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoev13f5ff92007-11-27 11:33:52 +000071 void *conf);
Igor Sysoevc16b0052007-12-27 14:21:59 +000072#if (NGX_HTTP_GZIP)
73static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
74 void *conf);
75#endif
Igor Sysoevb5faed22003-10-29 08:30:44 +000076
Igor Sysoev805d9db2005-02-03 19:33:37 +000077static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
Igor Sysoev08d068f2007-05-07 09:20:42 +000078static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
Igor Sysoev805d9db2005-02-03 19:33:37 +000079
80static ngx_conf_post_t ngx_http_core_lowat_post =
Igor Sysoev5a8bc362007-05-07 08:49:15 +000081 { ngx_http_core_lowat_check };
Igor Sysoevb5faed22003-10-29 08:30:44 +000082
Igor Sysoev08d068f2007-05-07 09:20:42 +000083static ngx_conf_post_handler_pt ngx_http_core_pool_size_p =
84 ngx_http_core_pool_size;
85
Igor Sysoev5cdb2ce2008-05-24 15:43:48 +000086static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_server_names = {
87 ngx_conf_deprecated, "optimize_server_names", "server_name_in_redirect"
Igor Sysoev8290d282006-02-03 12:58:48 +000088};
89
Igor Sysoev9b9616e2007-12-21 16:19:48 +000090static ngx_conf_deprecated_t ngx_conf_deprecated_open_file_cache_retest = {
91 ngx_conf_deprecated, "open_file_cache_retest", "open_file_cache_valid"
92};
93
Igor Sysoev2d028f82007-12-29 16:38:23 +000094static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any = {
95 ngx_conf_deprecated, "satisfy_any", "satisfy"
96};
97
Igor Sysoev4e9393a2003-01-09 05:36:00 +000098
Igor Sysoev64304df2007-01-24 09:14:08 +000099static ngx_conf_enum_t ngx_http_core_request_body_in_file[] = {
100 { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF },
101 { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON },
Igor Sysoevcd5b99a2007-01-25 08:45:04 +0000102 { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN },
Igor Sysoev64304df2007-01-24 09:14:08 +0000103 { ngx_null_string, 0 }
104};
105
106
Igor Sysoev2d028f82007-12-29 16:38:23 +0000107static ngx_conf_enum_t ngx_http_core_satisfy[] = {
108 { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
109 { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
110 { ngx_null_string, 0 }
111};
112
113
Igor Sysoev863325f2008-12-01 14:22:51 +0000114static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
Igor Sysoev2c336482009-02-10 15:05:05 +0000115 { ngx_string("off"), NGX_HTTP_IMS_OFF },
116 { ngx_string("exact"), NGX_HTTP_IMS_EXACT },
117 { ngx_string("before"), NGX_HTTP_IMS_BEFORE },
Igor Sysoev863325f2008-12-01 14:22:51 +0000118 { ngx_null_string, 0 }
119};
120
121
Igor Sysoevc16b0052007-12-27 14:21:59 +0000122#if (NGX_HTTP_GZIP)
123
124static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
125 { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
126 { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
127 { ngx_null_string, 0 }
128};
129
130
131static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
132 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
133 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
134 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
135 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
136 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
137 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
138 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
139 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
140 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
141 { ngx_null_string, 0 }
142};
143
144
145static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
146static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store");
147static ngx_str_t ngx_http_gzip_private = ngx_string("private");
148
149#endif
150
151
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000152static ngx_command_t ngx_http_core_commands[] = {
153
Igor Sysoevffe71442006-02-08 15:33:12 +0000154 { ngx_string("variables_hash_max_size"),
155 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
156 ngx_conf_set_num_slot,
157 NGX_HTTP_MAIN_CONF_OFFSET,
158 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
159 NULL },
160
161 { ngx_string("variables_hash_bucket_size"),
162 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
163 ngx_conf_set_num_slot,
164 NGX_HTTP_MAIN_CONF_OFFSET,
165 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
166 NULL },
167
Igor Sysoev305a9d82005-12-26 17:07:48 +0000168 { ngx_string("server_names_hash_max_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000169 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
170 ngx_conf_set_num_slot,
171 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +0000172 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000173 NULL },
174
Igor Sysoev305a9d82005-12-26 17:07:48 +0000175 { ngx_string("server_names_hash_bucket_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000176 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
177 ngx_conf_set_num_slot,
178 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +0000179 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000180 NULL },
181
Igor Sysoev865c1502003-11-30 20:03:18 +0000182 { ngx_string("server"),
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000183 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000184 ngx_http_core_server,
Igor Sysoev865c1502003-11-30 20:03:18 +0000185 0,
186 0,
187 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000188
Igor Sysoev865c1502003-11-30 20:03:18 +0000189 { ngx_string("connection_pool_size"),
190 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
191 ngx_conf_set_size_slot,
192 NGX_HTTP_SRV_CONF_OFFSET,
193 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
Igor Sysoev08d068f2007-05-07 09:20:42 +0000194 &ngx_http_core_pool_size_p },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000195
Igor Sysoev865c1502003-11-30 20:03:18 +0000196 { ngx_string("request_pool_size"),
197 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
198 ngx_conf_set_size_slot,
199 NGX_HTTP_SRV_CONF_OFFSET,
200 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
Igor Sysoev08d068f2007-05-07 09:20:42 +0000201 &ngx_http_core_pool_size_p },
Igor Sysoev187fcd82003-05-23 11:53:01 +0000202
Igor Sysoev865c1502003-11-30 20:03:18 +0000203 { ngx_string("client_header_timeout"),
204 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
205 ngx_conf_set_msec_slot,
206 NGX_HTTP_SRV_CONF_OFFSET,
207 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
208 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000209
Igor Sysoev865c1502003-11-30 20:03:18 +0000210 { ngx_string("client_header_buffer_size"),
211 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
212 ngx_conf_set_size_slot,
213 NGX_HTTP_SRV_CONF_OFFSET,
214 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
215 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000216
Igor Sysoevf7abd722004-09-23 06:32:00 +0000217 { ngx_string("large_client_header_buffers"),
Igor Sysoev85080d02004-09-22 16:18:21 +0000218 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
219 ngx_conf_set_bufs_slot,
220 NGX_HTTP_SRV_CONF_OFFSET,
Igor Sysoevf7abd722004-09-23 06:32:00 +0000221 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
Igor Sysoev865c1502003-11-30 20:03:18 +0000222 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000223
Igor Sysoev8290d282006-02-03 12:58:48 +0000224 { ngx_string("optimize_server_names"),
225 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
226 ngx_conf_set_flag_slot,
Igor Sysoev5cdb2ce2008-05-24 15:43:48 +0000227 NGX_HTTP_LOC_CONF_OFFSET,
228 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
229 &ngx_conf_deprecated_optimize_server_names },
Igor Sysoev34303462006-01-24 16:08:27 +0000230
Igor Sysoev3362b8d2005-05-14 18:42:03 +0000231 { ngx_string("ignore_invalid_headers"),
232 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
233 ngx_conf_set_flag_slot,
234 NGX_HTTP_SRV_CONF_OFFSET,
235 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
236 NULL },
237
Igor Sysoev8decab32007-10-18 11:36:58 +0000238 { ngx_string("merge_slashes"),
239 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
240 ngx_conf_set_flag_slot,
241 NGX_HTTP_SRV_CONF_OFFSET,
242 offsetof(ngx_http_core_srv_conf_t, merge_slashes),
243 NULL },
244
Igor Sysoev753792e2008-09-24 14:02:50 +0000245 { ngx_string("underscores_in_headers"),
246 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
247 ngx_conf_set_flag_slot,
248 NGX_HTTP_SRV_CONF_OFFSET,
249 offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
250 NULL },
251
Igor Sysoev865c1502003-11-30 20:03:18 +0000252 { ngx_string("location"),
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000253 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000254 ngx_http_core_location,
Igor Sysoev865c1502003-11-30 20:03:18 +0000255 NGX_HTTP_SRV_CONF_OFFSET,
256 0,
257 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000258
Igor Sysoev865c1502003-11-30 20:03:18 +0000259 { ngx_string("listen"),
Igor Sysoevb145b062005-06-15 18:33:41 +0000260 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000261 ngx_http_core_listen,
Igor Sysoev865c1502003-11-30 20:03:18 +0000262 NGX_HTTP_SRV_CONF_OFFSET,
263 0,
264 NULL },
Igor Sysoeva19a85e2003-01-28 15:56:37 +0000265
Igor Sysoev865c1502003-11-30 20:03:18 +0000266 { ngx_string("server_name"),
267 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000268 ngx_http_core_server_name,
Igor Sysoev865c1502003-11-30 20:03:18 +0000269 NGX_HTTP_SRV_CONF_OFFSET,
270 0,
271 NULL },
Igor Sysoev13933252003-05-29 13:02:09 +0000272
Igor Sysoev24025022005-12-16 15:07:08 +0000273 { ngx_string("types_hash_max_size"),
274 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
275 ngx_conf_set_num_slot,
276 NGX_HTTP_LOC_CONF_OFFSET,
277 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
278 NULL },
279
280 { ngx_string("types_hash_bucket_size"),
281 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
282 ngx_conf_set_num_slot,
283 NGX_HTTP_LOC_CONF_OFFSET,
284 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
285 NULL },
286
Igor Sysoev865c1502003-11-30 20:03:18 +0000287 { ngx_string("types"),
288 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
289 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000290 ngx_http_core_types,
Igor Sysoev865c1502003-11-30 20:03:18 +0000291 NGX_HTTP_LOC_CONF_OFFSET,
292 0,
293 NULL },
Igor Sysoev79a80482003-05-14 17:13:13 +0000294
Igor Sysoev865c1502003-11-30 20:03:18 +0000295 { ngx_string("default_type"),
296 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
297 ngx_conf_set_str_slot,
298 NGX_HTTP_LOC_CONF_OFFSET,
299 offsetof(ngx_http_core_loc_conf_t, default_type),
300 NULL },
Igor Sysoev6253ca12003-05-27 12:18:54 +0000301
Igor Sysoev865c1502003-11-30 20:03:18 +0000302 { ngx_string("root"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000303 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
304 |NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000305 ngx_http_core_root,
Igor Sysoev865c1502003-11-30 20:03:18 +0000306 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000307 0,
308 NULL },
309
310 { ngx_string("alias"),
311 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000312 ngx_http_core_root,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000313 NGX_HTTP_LOC_CONF_OFFSET,
314 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000315 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000316
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000317 { ngx_string("limit_except"),
318 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
319 ngx_http_core_limit_except,
320 NGX_HTTP_LOC_CONF_OFFSET,
321 0,
322 NULL },
323
Igor Sysoevae02c192004-03-19 05:25:53 +0000324 { ngx_string("client_max_body_size"),
325 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev1765f472006-07-07 16:33:19 +0000326 ngx_conf_set_off_slot,
Igor Sysoevae02c192004-03-19 05:25:53 +0000327 NGX_HTTP_LOC_CONF_OFFSET,
328 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
329 NULL },
330
Igor Sysoevdbb27762004-04-01 16:20:53 +0000331 { ngx_string("client_body_buffer_size"),
332 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
333 ngx_conf_set_size_slot,
334 NGX_HTTP_LOC_CONF_OFFSET,
335 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
336 NULL },
337
Igor Sysoev865c1502003-11-30 20:03:18 +0000338 { ngx_string("client_body_timeout"),
339 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
340 ngx_conf_set_msec_slot,
341 NGX_HTTP_LOC_CONF_OFFSET,
342 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
343 NULL },
Igor Sysoev2b0c76c2003-10-27 21:01:00 +0000344
Igor Sysoev02025fd2005-01-18 13:03:58 +0000345 { ngx_string("client_body_temp_path"),
346 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
347 ngx_conf_set_path_slot,
348 NGX_HTTP_LOC_CONF_OFFSET,
349 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
350 (void *) ngx_garbage_collector_temp_handler },
351
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000352 { ngx_string("client_body_in_file_only"),
353 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
Igor Sysoev64304df2007-01-24 09:14:08 +0000354 ngx_conf_set_enum_slot,
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000355 NGX_HTTP_LOC_CONF_OFFSET,
356 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
Igor Sysoev64304df2007-01-24 09:14:08 +0000357 &ngx_http_core_request_body_in_file },
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000358
Igor Sysoev865c1502003-11-30 20:03:18 +0000359 { ngx_string("sendfile"),
Igor Sysoev300de4f2007-01-21 17:42:28 +0000360 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
361 |NGX_CONF_TAKE1,
Igor Sysoev865c1502003-11-30 20:03:18 +0000362 ngx_conf_set_flag_slot,
363 NGX_HTTP_LOC_CONF_OFFSET,
364 offsetof(ngx_http_core_loc_conf_t, sendfile),
365 NULL },
Igor Sysoev5bf3d252003-10-22 07:05:29 +0000366
Igor Sysoevc9b57dc2007-05-07 06:33:39 +0000367 { ngx_string("sendfile_max_chunk"),
368 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
369 ngx_conf_set_size_slot,
370 NGX_HTTP_LOC_CONF_OFFSET,
371 offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
372 NULL },
373
Igor Sysoev385af282008-07-30 12:34:04 +0000374 { ngx_string("directio"),
375 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
376 ngx_http_core_directio,
377 NGX_HTTP_LOC_CONF_OFFSET,
378 0,
379 NULL },
380
Igor Sysoev3c3ca172004-01-05 20:55:48 +0000381 { ngx_string("tcp_nopush"),
382 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
383 ngx_conf_set_flag_slot,
384 NGX_HTTP_LOC_CONF_OFFSET,
385 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
386 NULL },
387
Igor Sysoev924bd792004-10-11 15:07:03 +0000388 { ngx_string("tcp_nodelay"),
389 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
390 ngx_conf_set_flag_slot,
391 NGX_HTTP_LOC_CONF_OFFSET,
392 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
393 NULL },
394
Igor Sysoev865c1502003-11-30 20:03:18 +0000395 { ngx_string("send_timeout"),
396 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
397 ngx_conf_set_msec_slot,
398 NGX_HTTP_LOC_CONF_OFFSET,
399 offsetof(ngx_http_core_loc_conf_t, send_timeout),
400 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000401
Igor Sysoev865c1502003-11-30 20:03:18 +0000402 { ngx_string("send_lowat"),
403 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
404 ngx_conf_set_size_slot,
405 NGX_HTTP_LOC_CONF_OFFSET,
406 offsetof(ngx_http_core_loc_conf_t, send_lowat),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000407 &ngx_http_core_lowat_post },
Igor Sysoevb5faed22003-10-29 08:30:44 +0000408
Igor Sysoev7823cc32004-07-14 16:01:42 +0000409 { ngx_string("postpone_output"),
410 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
411 ngx_conf_set_size_slot,
412 NGX_HTTP_LOC_CONF_OFFSET,
413 offsetof(ngx_http_core_loc_conf_t, postpone_output),
414 NULL },
415
416 { ngx_string("limit_rate"),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000417 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
418 |NGX_CONF_TAKE1,
Igor Sysoev7823cc32004-07-14 16:01:42 +0000419 ngx_conf_set_size_slot,
420 NGX_HTTP_LOC_CONF_OFFSET,
421 offsetof(ngx_http_core_loc_conf_t, limit_rate),
422 NULL },
423
Igor Sysoev865c1502003-11-30 20:03:18 +0000424 { ngx_string("keepalive_timeout"),
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000425 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000426 ngx_http_core_keepalive,
Igor Sysoev865c1502003-11-30 20:03:18 +0000427 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000428 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000429 NULL },
Igor Sysoevfa73aac2003-05-21 13:28:21 +0000430
Igor Sysoev2d028f82007-12-29 16:38:23 +0000431 { ngx_string("satisfy"),
432 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
433 ngx_conf_set_enum_slot,
434 NGX_HTTP_LOC_CONF_OFFSET,
435 offsetof(ngx_http_core_loc_conf_t, satisfy),
436 &ngx_http_core_satisfy },
437
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000438 { ngx_string("satisfy_any"),
439 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
440 ngx_conf_set_flag_slot,
441 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev2d028f82007-12-29 16:38:23 +0000442 offsetof(ngx_http_core_loc_conf_t, satisfy),
443 &ngx_conf_deprecated_satisfy_any },
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000444
Igor Sysoev899b44e2005-05-12 14:58:06 +0000445 { ngx_string("internal"),
446 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
447 ngx_http_core_internal,
448 NGX_HTTP_LOC_CONF_OFFSET,
449 0,
450 NULL },
451
Igor Sysoev865c1502003-11-30 20:03:18 +0000452 { ngx_string("lingering_time"),
453 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
454 ngx_conf_set_msec_slot,
455 NGX_HTTP_LOC_CONF_OFFSET,
456 offsetof(ngx_http_core_loc_conf_t, lingering_time),
457 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000458
Igor Sysoev865c1502003-11-30 20:03:18 +0000459 { ngx_string("lingering_timeout"),
460 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
461 ngx_conf_set_msec_slot,
462 NGX_HTTP_LOC_CONF_OFFSET,
463 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
464 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000465
Igor Sysoev0ab91b92004-06-06 19:49:18 +0000466 { ngx_string("reset_timedout_connection"),
467 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
468 ngx_conf_set_flag_slot,
469 NGX_HTTP_LOC_CONF_OFFSET,
470 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
471 NULL },
472
Igor Sysoev3f24ae22007-12-29 15:30:39 +0000473 { ngx_string("server_name_in_redirect"),
474 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
475 ngx_conf_set_flag_slot,
476 NGX_HTTP_LOC_CONF_OFFSET,
477 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
478 NULL },
479
Igor Sysoev7b190b42005-06-07 15:56:31 +0000480 { ngx_string("port_in_redirect"),
481 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
482 ngx_conf_set_flag_slot,
483 NGX_HTTP_LOC_CONF_OFFSET,
484 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
485 NULL },
486
Igor Sysoev865c1502003-11-30 20:03:18 +0000487 { ngx_string("msie_padding"),
488 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
489 ngx_conf_set_flag_slot,
490 NGX_HTTP_LOC_CONF_OFFSET,
491 offsetof(ngx_http_core_loc_conf_t, msie_padding),
492 NULL },
Igor Sysoev12b4b002003-10-24 06:53:41 +0000493
Igor Sysoev3f8dc592006-08-28 16:57:48 +0000494 { ngx_string("msie_refresh"),
495 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
496 ngx_conf_set_flag_slot,
497 NGX_HTTP_LOC_CONF_OFFSET,
498 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
499 NULL },
500
Igor Sysoev5192b362005-07-08 14:34:20 +0000501 { ngx_string("log_not_found"),
502 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
503 ngx_conf_set_flag_slot,
504 NGX_HTTP_LOC_CONF_OFFSET,
505 offsetof(ngx_http_core_loc_conf_t, log_not_found),
506 NULL },
507
Igor Sysoev2eec1e12008-09-27 15:08:02 +0000508 { ngx_string("log_subrequest"),
509 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
510 ngx_conf_set_flag_slot,
511 NGX_HTTP_LOC_CONF_OFFSET,
512 offsetof(ngx_http_core_loc_conf_t, log_subrequest),
513 NULL },
514
Igor Sysoev3f8dc592006-08-28 16:57:48 +0000515 { ngx_string("recursive_error_pages"),
516 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
517 ngx_conf_set_flag_slot,
518 NGX_HTTP_LOC_CONF_OFFSET,
519 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
520 NULL },
521
Igor Sysoev070cf222007-10-22 10:17:34 +0000522 { ngx_string("server_tokens"),
523 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
524 ngx_conf_set_flag_slot,
525 NGX_HTTP_LOC_CONF_OFFSET,
526 offsetof(ngx_http_core_loc_conf_t, server_tokens),
527 NULL },
528
Igor Sysoev863325f2008-12-01 14:22:51 +0000529 { ngx_string("if_modified_since"),
530 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
531 ngx_conf_set_enum_slot,
532 NGX_HTTP_LOC_CONF_OFFSET,
533 offsetof(ngx_http_core_loc_conf_t, if_modified_since),
534 &ngx_http_core_if_modified_since },
535
Igor Sysoev865c1502003-11-30 20:03:18 +0000536 { ngx_string("error_page"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000537 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
538 |NGX_CONF_2MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000539 ngx_http_core_error_page,
Igor Sysoev865c1502003-11-30 20:03:18 +0000540 NGX_HTTP_LOC_CONF_OFFSET,
541 0,
542 NULL },
Igor Sysoev74e95c22003-11-09 20:03:38 +0000543
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +0000544 { ngx_string("try_files"),
545 NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
546 ngx_http_core_try_files,
547 NGX_HTTP_LOC_CONF_OFFSET,
548 0,
549 NULL },
550
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000551 { ngx_string("post_action"),
552 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
553 |NGX_CONF_TAKE1,
554 ngx_conf_set_str_slot,
555 NGX_HTTP_LOC_CONF_OFFSET,
556 offsetof(ngx_http_core_loc_conf_t, post_action),
557 NULL },
558
Igor Sysoev865c1502003-11-30 20:03:18 +0000559 { ngx_string("error_log"),
Igor Sysoev03420a62004-01-20 20:40:08 +0000560 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000561 ngx_http_core_error_log,
Igor Sysoev865c1502003-11-30 20:03:18 +0000562 NGX_HTTP_LOC_CONF_OFFSET,
563 0,
564 NULL },
Igor Sysoev890fc962003-07-20 21:15:59 +0000565
Igor Sysoev865c1502003-11-30 20:03:18 +0000566 { ngx_string("open_file_cache"),
Igor Sysoev140c7552007-09-01 12:12:48 +0000567 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
568 ngx_http_core_open_file_cache,
Igor Sysoev865c1502003-11-30 20:03:18 +0000569 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev140c7552007-09-01 12:12:48 +0000570 offsetof(ngx_http_core_loc_conf_t, open_file_cache),
Igor Sysoev865c1502003-11-30 20:03:18 +0000571 NULL },
572
Igor Sysoev9b9616e2007-12-21 16:19:48 +0000573 { ngx_string("open_file_cache_valid"),
574 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
575 ngx_conf_set_sec_slot,
576 NGX_HTTP_LOC_CONF_OFFSET,
577 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
578 NULL },
579
Igor Sysoev140c7552007-09-01 12:12:48 +0000580 { ngx_string("open_file_cache_retest"),
581 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
582 ngx_conf_set_sec_slot,
583 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev9b9616e2007-12-21 16:19:48 +0000584 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
585 &ngx_conf_deprecated_open_file_cache_retest },
Igor Sysoev140c7552007-09-01 12:12:48 +0000586
Igor Sysoevf3b0e492007-12-22 13:19:39 +0000587 { ngx_string("open_file_cache_min_uses"),
588 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
589 ngx_conf_set_num_slot,
590 NGX_HTTP_LOC_CONF_OFFSET,
591 offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
592 NULL },
593
Igor Sysoev140c7552007-09-01 12:12:48 +0000594 { ngx_string("open_file_cache_errors"),
595 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
596 ngx_conf_set_flag_slot,
597 NGX_HTTP_LOC_CONF_OFFSET,
598 offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
599 NULL },
Igor Sysoev67f88e92004-03-12 16:57:08 +0000600
Igor Sysoev9afd58f2007-09-03 08:41:42 +0000601 { ngx_string("open_file_cache_events"),
602 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
603 ngx_conf_set_flag_slot,
604 NGX_HTTP_LOC_CONF_OFFSET,
605 offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
606 NULL },
607
Igor Sysoev13f5ff92007-11-27 11:33:52 +0000608 { ngx_string("resolver"),
609 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
610 ngx_http_core_resolver,
611 NGX_HTTP_LOC_CONF_OFFSET,
612 0,
613 NULL },
614
615 { ngx_string("resolver_timeout"),
616 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
617 ngx_conf_set_msec_slot,
618 NGX_HTTP_LOC_CONF_OFFSET,
619 offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
620 NULL },
621
Igor Sysoevc16b0052007-12-27 14:21:59 +0000622#if (NGX_HTTP_GZIP)
623
624 { ngx_string("gzip_vary"),
625 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
626 ngx_conf_set_flag_slot,
627 NGX_HTTP_LOC_CONF_OFFSET,
628 offsetof(ngx_http_core_loc_conf_t, gzip_vary),
629 NULL },
630
631 { ngx_string("gzip_http_version"),
632 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
633 ngx_conf_set_enum_slot,
634 NGX_HTTP_LOC_CONF_OFFSET,
635 offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
636 &ngx_http_gzip_http_version },
637
638 { ngx_string("gzip_proxied"),
639 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
640 ngx_conf_set_bitmask_slot,
641 NGX_HTTP_LOC_CONF_OFFSET,
642 offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
643 &ngx_http_gzip_proxied_mask },
644
645 { ngx_string("gzip_disable"),
646 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
647 ngx_http_gzip_disable,
648 NGX_HTTP_LOC_CONF_OFFSET,
649 0,
650 NULL },
651
652#endif
653
Igor Sysoev865c1502003-11-30 20:03:18 +0000654 ngx_null_command
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000655};
656
657
Igor Sysoev8f125582006-07-28 15:16:17 +0000658static ngx_http_module_t ngx_http_core_module_ctx = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000659 ngx_http_core_preconfiguration, /* preconfiguration */
Igor Sysoev09c684b2005-11-09 17:25:55 +0000660 NULL, /* postconfiguration */
Igor Sysoev78329332003-11-10 17:17:31 +0000661
Igor Sysoeva9830112003-05-19 16:39:14 +0000662 ngx_http_core_create_main_conf, /* create main configuration */
663 ngx_http_core_init_main_conf, /* init main configuration */
Igor Sysoevdc479b42003-03-20 16:09:44 +0000664
Igor Sysoeva9830112003-05-19 16:39:14 +0000665 ngx_http_core_create_srv_conf, /* create server configuration */
666 ngx_http_core_merge_srv_conf, /* merge server configuration */
667
668 ngx_http_core_create_loc_conf, /* create location configuration */
669 ngx_http_core_merge_loc_conf /* merge location configuration */
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000670};
671
672
673ngx_module_t ngx_http_core_module = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000674 NGX_MODULE_V1,
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000675 &ngx_http_core_module_ctx, /* module context */
676 ngx_http_core_commands, /* module directives */
Igor Sysoev6253ca12003-05-27 12:18:54 +0000677 NGX_HTTP_MODULE, /* module type */
Igor Sysoeve5733802005-09-08 14:36:09 +0000678 NULL, /* init master */
Igor Sysoev899b44e2005-05-12 14:58:06 +0000679 NULL, /* init module */
Igor Sysoeve5733802005-09-08 14:36:09 +0000680 NULL, /* init process */
681 NULL, /* init thread */
682 NULL, /* exit thread */
683 NULL, /* exit process */
684 NULL, /* exit master */
685 NGX_MODULE_V1_PADDING
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000686};
687
688
Igor Sysoev88b24062008-02-07 10:38:13 +0000689static ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " };
690
691
Igor Sysoevaa828612005-02-09 14:31:07 +0000692void
693ngx_http_handler(ngx_http_request_t *r)
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000694{
Igor Sysoevda173ab2006-08-30 10:39:17 +0000695 ngx_http_core_main_conf_t *cmcf;
696
Igor Sysoeve5a222c2005-01-25 12:27:35 +0000697 r->connection->log->action = NULL;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000698
699 r->connection->unexpected_eof = 0;
700
Igor Sysoevef316432006-08-16 13:09:33 +0000701 if (!r->internal) {
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000702 switch (r->headers_in.connection_type) {
703 case 0:
704 if (r->http_version > NGX_HTTP_VERSION_10) {
705 r->keepalive = 1;
706 } else {
707 r->keepalive = 0;
708 }
709 break;
710
711 case NGX_HTTP_CONNECTION_CLOSE:
712 r->keepalive = 0;
713 break;
714
715 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000716 r->keepalive = 1;
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000717 break;
718 }
719
720 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
721
722 /*
Igor Sysoevda173ab2006-08-30 10:39:17 +0000723 * MSIE may wait for some time if an response for
724 * a POST request was sent over a keepalive connection
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000725 */
726
Igor Sysoev9760a132003-10-21 07:47:21 +0000727 r->keepalive = 0;
728 }
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000729
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000730 if (r->headers_in.content_length_n > 0) {
731 r->lingering_close = 1;
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000732
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000733 } else {
734 r->lingering_close = 0;
735 }
Igor Sysoev9760a132003-10-21 07:47:21 +0000736
Igor Sysoevda173ab2006-08-30 10:39:17 +0000737 r->phase_handler = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000738
Igor Sysoevda173ab2006-08-30 10:39:17 +0000739 } else {
740 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
741 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
742 }
743
Igor Sysoev8a3cdc02006-09-25 17:49:49 +0000744 if (r->unparsed_uri.len) {
745 r->valid_unparsed_uri = 1;
746 }
747
748 r->valid_location = 1;
Igor Sysoevc16b0052007-12-27 14:21:59 +0000749 r->gzip = 0;
Igor Sysoev8a3cdc02006-09-25 17:49:49 +0000750
Igor Sysoevda173ab2006-08-30 10:39:17 +0000751 r->write_event_handler = ngx_http_core_run_phases;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000752 ngx_http_core_run_phases(r);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000753}
Igor Sysoeve2a31542003-04-08 15:40:10 +0000754
755
Igor Sysoevda173ab2006-08-30 10:39:17 +0000756void
Igor Sysoevaa828612005-02-09 14:31:07 +0000757ngx_http_core_run_phases(ngx_http_request_t *r)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000758{
Igor Sysoev865c1502003-11-30 20:03:18 +0000759 ngx_int_t rc;
Igor Sysoevda173ab2006-08-30 10:39:17 +0000760 ngx_http_phase_handler_t *ph;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000761 ngx_http_core_main_conf_t *cmcf;
762
763 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
764
Igor Sysoevda173ab2006-08-30 10:39:17 +0000765 ph = cmcf->phase_engine.handlers;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000766
Igor Sysoevda173ab2006-08-30 10:39:17 +0000767 while (ph[r->phase_handler].checker) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000768
Igor Sysoevda173ab2006-08-30 10:39:17 +0000769 rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
Igor Sysoev805d9db2005-02-03 19:33:37 +0000770
Igor Sysoevda173ab2006-08-30 10:39:17 +0000771 if (rc == NGX_OK) {
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000772 return;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000773 }
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000774 }
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000775}
776
777
Igor Sysoevaa828612005-02-09 14:31:07 +0000778ngx_int_t
Igor Sysoevda173ab2006-08-30 10:39:17 +0000779ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
780{
781 ngx_int_t rc;
782
783 /*
784 * generic phase checker,
785 * used by the post read, server rewrite, rewrite, and pre-access phases
786 */
787
788 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
789 "generic phase: %ui", r->phase_handler);
790
791 rc = ph->handler(r);
792
793 if (rc == NGX_OK) {
794 r->phase_handler = ph->next;
795 return NGX_AGAIN;
796 }
797
798 if (rc == NGX_DECLINED) {
799 r->phase_handler++;
800 return NGX_AGAIN;
801 }
802
803 if (rc == NGX_AGAIN || rc == NGX_DONE) {
804 return NGX_OK;
805 }
806
807 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
808
809 ngx_http_finalize_request(r, rc);
810
811 return NGX_OK;
812}
813
814
815ngx_int_t
816ngx_http_core_find_config_phase(ngx_http_request_t *r,
817 ngx_http_phase_handler_t *ph)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000818{
Igor Sysoev966e2a52007-08-15 15:57:26 +0000819 u_char *p;
820 size_t len;
Igor Sysoev303df472008-12-26 13:43:42 +0000821 ngx_int_t rc;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000822 ngx_http_core_loc_conf_t *clcf;
Igor Sysoeve2a31542003-04-08 15:40:10 +0000823
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000824 r->content_handler = NULL;
825 r->uri_changed = 0;
826
Igor Sysoeve55988c2008-05-24 14:14:13 +0000827 rc = ngx_http_core_find_location(r);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000828
Igor Sysoevdc911282008-08-17 18:02:55 +0000829 if (rc == NGX_ERROR) {
Igor Sysoevda173ab2006-08-30 10:39:17 +0000830 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
831 return NGX_OK;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000832 }
833
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000834 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
835
Igor Sysoev899b44e2005-05-12 14:58:06 +0000836 if (!r->internal && clcf->internal) {
Igor Sysoevda173ab2006-08-30 10:39:17 +0000837 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
838 return NGX_OK;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000839 }
840
Igor Sysoeva2573672005-10-05 14:46:21 +0000841 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
842 "using configuration \"%s%V\"",
843 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
844 &clcf->name);
845
Igor Sysoevb85fd592005-08-23 15:36:54 +0000846 ngx_http_update_location_config(r);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000847
848 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1765f472006-07-07 16:33:19 +0000849 "http cl:%O max:%O",
Igor Sysoev1b735832004-11-11 14:07:14 +0000850 r->headers_in.content_length_n, clcf->client_max_body_size);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000851
852 if (r->headers_in.content_length_n != -1
Igor Sysoev08e63d42006-08-14 15:09:38 +0000853 && !r->discard_body
Igor Sysoev89690bf2004-03-23 06:01:52 +0000854 && clcf->client_max_body_size
Igor Sysoev1765f472006-07-07 16:33:19 +0000855 && clcf->client_max_body_size < r->headers_in.content_length_n)
Igor Sysoev89690bf2004-03-23 06:01:52 +0000856 {
857 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoeve345d262007-10-18 15:53:38 +0000858 "client intended to send too large body: %O bytes",
Igor Sysoev89690bf2004-03-23 06:01:52 +0000859 r->headers_in.content_length_n);
860
Igor Sysoevda173ab2006-08-30 10:39:17 +0000861 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
862 return NGX_OK;
Igor Sysoev89690bf2004-03-23 06:01:52 +0000863 }
864
Igor Sysoeve55988c2008-05-24 14:14:13 +0000865 if (rc == NGX_DONE) {
Igor Sysoevaab4d8c2004-09-06 18:45:00 +0000866 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
867 if (r->headers_out.location == NULL) {
Igor Sysoevda173ab2006-08-30 10:39:17 +0000868 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
869 return NGX_OK;
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000870 }
871
Igor Sysoev899b44e2005-05-12 14:58:06 +0000872 /*
873 * we do not need to set the r->headers_out.location->hash and
874 * r->headers_out.location->key fields
875 */
876
Igor Sysoev966e2a52007-08-15 15:57:26 +0000877 if (r->args.len == 0) {
878 r->headers_out.location->value = clcf->name;
879
880 } else {
881 len = clcf->name.len + 1 + r->args.len;
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +0000882 p = ngx_pnalloc(r->pool, len);
Igor Sysoev966e2a52007-08-15 15:57:26 +0000883
884 if (p == NULL) {
885 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
886 return NGX_OK;
887 }
888
889 r->headers_out.location->value.len = len;
890 r->headers_out.location->value.data = p;
891
892 p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
893 *p++ = '?';
894 ngx_memcpy(p, r->args.data, r->args.len);
895 }
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000896
Igor Sysoevda173ab2006-08-30 10:39:17 +0000897 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
898 return NGX_OK;
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000899 }
900
Igor Sysoevda173ab2006-08-30 10:39:17 +0000901 r->phase_handler++;
902 return NGX_AGAIN;
903}
904
905
906ngx_int_t
907ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
908 ngx_http_phase_handler_t *ph)
909{
Igor Sysoevb0780752008-06-15 19:07:35 +0000910 ngx_http_core_srv_conf_t *cscf;
911
Igor Sysoevda173ab2006-08-30 10:39:17 +0000912 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
913 "post rewrite phase: %ui", r->phase_handler);
914
915 if (!r->uri_changed) {
916 r->phase_handler++;
917 return NGX_AGAIN;
918 }
919
920 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
921 "uri changes: %d", r->uri_changes);
922
923 /*
924 * gcc before 3.3 compiles the broken code for
925 * if (r->uri_changes-- == 0)
926 * if the r->uri_changes is defined as
927 * unsigned uri_changes:4
928 */
929
930 r->uri_changes--;
931
932 if (r->uri_changes == 0) {
933 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
934 "rewrite or internal redirection cycle "
935 "while processing \"%V\"", &r->uri);
936
937 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
938 return NGX_OK;
939 }
940
941 r->phase_handler = ph->next;
942
Igor Sysoevb0780752008-06-15 19:07:35 +0000943 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
944 r->loc_conf = cscf->ctx->loc_conf;
945
Igor Sysoevda173ab2006-08-30 10:39:17 +0000946 return NGX_AGAIN;
947}
948
949
950ngx_int_t
951ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
952{
953 ngx_int_t rc;
954 ngx_http_core_loc_conf_t *clcf;
955
956 if (r != r->main) {
957 r->phase_handler = ph->next;
958 return NGX_AGAIN;
959 }
960
961 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
962 "access phase: %ui", r->phase_handler);
963
964 rc = ph->handler(r);
965
966 if (rc == NGX_DECLINED) {
967 r->phase_handler++;
968 return NGX_AGAIN;
969 }
970
971 if (rc == NGX_AGAIN || rc == NGX_DONE) {
972 return NGX_OK;
973 }
974
975 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
976
Igor Sysoev2d028f82007-12-29 16:38:23 +0000977 if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
Igor Sysoevda173ab2006-08-30 10:39:17 +0000978
979 if (rc == NGX_OK) {
980 r->phase_handler++;
981 return NGX_AGAIN;
982 }
983
984 } else {
985 if (rc == NGX_OK) {
986 r->access_code = 0;
987
988 if (r->headers_out.www_authenticate) {
989 r->headers_out.www_authenticate->hash = 0;
990 }
991
992 r->phase_handler = ph->next;
993 return NGX_AGAIN;
994 }
995
996 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
997 r->access_code = rc;
998
999 r->phase_handler++;
1000 return NGX_AGAIN;
1001 }
1002 }
1003
1004 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
1005
1006 ngx_http_finalize_request(r, rc);
1007 return NGX_OK;
1008}
1009
1010
1011ngx_int_t
1012ngx_http_core_post_access_phase(ngx_http_request_t *r,
1013 ngx_http_phase_handler_t *ph)
1014{
1015 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1016 "post access phase: %ui", r->phase_handler);
1017
1018 if (r->access_code) {
1019
1020 if (r->access_code == NGX_HTTP_FORBIDDEN) {
1021 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1022 "access forbidden by rule");
1023 }
1024
1025 ngx_http_finalize_request(r, r->access_code);
1026 return NGX_OK;
1027 }
1028
1029 r->phase_handler++;
1030 return NGX_AGAIN;
1031}
1032
1033
1034ngx_int_t
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001035ngx_http_core_try_files_phase(ngx_http_request_t *r,
1036 ngx_http_phase_handler_t *ph)
1037{
Igor Sysoev67392e82009-01-27 16:22:02 +00001038 size_t len, root, alias, reserve, allocated;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001039 u_char *p, *name;
Igor Sysoevb03aa7f2009-03-19 13:42:27 +00001040 ngx_str_t path, args;
Igor Sysoev319dc272009-01-21 12:11:22 +00001041 ngx_uint_t test_dir;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001042 ngx_http_try_file_t *tf;
1043 ngx_open_file_info_t of;
1044 ngx_http_script_code_pt code;
1045 ngx_http_script_engine_t e;
1046 ngx_http_core_loc_conf_t *clcf;
1047 ngx_http_script_len_code_pt lcode;
1048
1049 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1050 "try files phase: %ui", r->phase_handler);
1051
1052 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1053
1054 if (clcf->try_files == NULL) {
1055 r->phase_handler++;
1056 return NGX_AGAIN;
1057 }
1058
1059 allocated = 0;
1060 root = 0;
1061 name = NULL;
Igor Sysoev67392e82009-01-27 16:22:02 +00001062 /* suppress MSVC warning */
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001063 path.data = NULL;
1064
1065 tf = clcf->try_files;
1066
1067 alias = clcf->alias ? clcf->name.len : 0;
1068
1069 for ( ;; ) {
1070
1071 if (tf->lengths) {
1072 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
1073
1074 e.ip = tf->lengths->elts;
1075 e.request = r;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001076
1077 /* 1 is for terminating '\0' as in static names */
1078 len = 1;
1079
1080 while (*(uintptr_t *) e.ip) {
1081 lcode = *(ngx_http_script_len_code_pt *) e.ip;
1082 len += lcode(&e);
1083 }
1084
1085 } else {
1086 len = tf->name.len;
1087 }
1088
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001089 /* 16 bytes are preallocation */
Igor Sysoev42c67dd2009-03-01 19:10:36 +00001090 reserve = ngx_abs((ssize_t) (len - r->uri.len)) + alias + 16;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001091
1092 if (reserve > allocated) {
1093
1094 /* we just need to allocate path and to copy a root */
1095
1096 if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) {
1097 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1098 return NGX_OK;
1099 }
1100
1101 name = path.data + root;
1102 allocated = path.len - root - (r->uri.len - alias);
1103 }
1104
1105 if (tf->values == NULL) {
1106
1107 /* tf->name.len includes the terminating '\0' */
1108
1109 ngx_memcpy(name, tf->name.data, tf->name.len);
1110
1111 path.len = (name + tf->name.len - 1) - path.data;
1112
1113 } else {
1114 e.ip = tf->values->elts;
1115 e.pos = name;
Igor Sysoev195860b2008-12-24 07:14:01 +00001116 e.flushed = 1;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001117
1118 while (*(uintptr_t *) e.ip) {
1119 code = *(ngx_http_script_code_pt *) e.ip;
1120 code((ngx_http_script_engine_t *) &e);
1121 }
1122
1123 path.len = e.pos - path.data;
1124
Igor Sysoev51ed97f2009-03-14 17:10:25 +00001125 *e.pos = '\0';
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001126
1127 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
1128 ngx_memcpy(name, name + alias, len - alias);
1129 path.len -= alias;
1130 }
1131 }
1132
Igor Sysoev319dc272009-01-21 12:11:22 +00001133 test_dir = tf->test_dir;
1134
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001135 tf++;
1136
1137 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1138 "try to use file: \"%s\"", name);
1139
1140 if (tf->lengths == NULL && tf->name.len == 0) {
1141
1142 path.len -= root;
1143 path.data += root;
1144
1145 if (path.data[0] == '@') {
1146 (void) ngx_http_named_location(r, &path);
1147
1148 } else {
Igor Sysoevb03aa7f2009-03-19 13:42:27 +00001149 ngx_http_split_args(r, &path, &args);
1150
1151 (void) ngx_http_internal_redirect(r, &path, &args);
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001152 }
1153
1154 return NGX_OK;
1155 }
1156
1157 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
1158
1159 of.directio = clcf->directio;
1160 of.valid = clcf->open_file_cache_valid;
1161 of.min_uses = clcf->open_file_cache_min_uses;
1162 of.errors = clcf->open_file_cache_errors;
1163 of.events = clcf->open_file_cache_events;
1164
1165 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
1166 != NGX_OK)
1167 {
1168 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
1169 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
1170 ngx_open_file_n " \"%s\" failed", path.data);
1171 }
1172
1173 continue;
1174 }
1175
Igor Sysoev319dc272009-01-21 12:11:22 +00001176 if (of.is_dir && !test_dir) {
Igor Sysoev977fd902009-01-19 11:24:25 +00001177 continue;
1178 }
1179
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001180 path.len -= root;
1181 path.data += root;
1182
1183 if (!alias) {
1184 r->uri = path;
1185
1186 } else {
1187 r->uri.len = alias + path.len;
1188 r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
1189 if (r->uri.data == NULL) {
1190 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1191 return NGX_OK;
1192 }
1193
1194 p = ngx_copy(r->uri.data, clcf->name.data, alias);
1195 ngx_memcpy(p, name, path.len);
1196 }
1197
Igor Sysoevb17bf522009-02-14 17:26:26 +00001198 if (ngx_http_set_exten(r) != NGX_OK) {
1199 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1200 return NGX_OK;
1201 }
1202
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001203 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1204 "try file uri: \"%V\"", &r->uri);
1205
1206 r->phase_handler++;
1207 return NGX_AGAIN;
1208 }
1209
1210 /* not reached */
1211}
1212
1213
1214ngx_int_t
Igor Sysoevda173ab2006-08-30 10:39:17 +00001215ngx_http_core_content_phase(ngx_http_request_t *r,
1216 ngx_http_phase_handler_t *ph)
1217{
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001218 size_t root;
Igor Sysoevda173ab2006-08-30 10:39:17 +00001219 ngx_int_t rc;
1220 ngx_str_t path;
1221
1222 if (r->content_handler) {
1223 r->write_event_handler = ngx_http_request_empty_handler;
1224 ngx_http_finalize_request(r, r->content_handler(r));
1225 return NGX_OK;
1226 }
1227
1228 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1229 "content phase: %ui", r->phase_handler);
1230
1231 rc = ph->handler(r);
1232
1233 if (rc == NGX_DONE) {
1234 return NGX_OK;
1235 }
1236
1237 if (rc != NGX_DECLINED) {
1238 ngx_http_finalize_request(r, rc);
1239 return NGX_OK;
1240 }
1241
1242 /* rc == NGX_DECLINED */
1243
1244 ph++;
1245
1246 if (ph->checker) {
1247 r->phase_handler++;
1248 return NGX_AGAIN;
1249 }
1250
1251 /* no content handler was found */
1252
1253 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
1254
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001255 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
Igor Sysoevda173ab2006-08-30 10:39:17 +00001256 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev9d2811b2007-09-27 09:39:29 +00001257 "directory index of \"%s\" is forbidden", path.data);
Igor Sysoevda173ab2006-08-30 10:39:17 +00001258 }
1259
1260 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
1261 return NGX_OK;
1262 }
1263
1264 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
1265
1266 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
Igor Sysoevb85fd592005-08-23 15:36:54 +00001267 return NGX_OK;
1268}
1269
1270
1271void
1272ngx_http_update_location_config(ngx_http_request_t *r)
1273{
1274 ngx_http_core_loc_conf_t *clcf;
1275
1276 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1277
Igor Sysoev94e32ce2006-04-07 14:08:04 +00001278 if (r->method & clcf->limit_except) {
1279 r->loc_conf = clcf->limit_except_loc_conf;
1280 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1281 }
1282
Igor Sysoevb0518172006-04-26 15:21:08 +00001283 if (r == r->main) {
Igor Sysoev4ca98f62007-03-28 14:38:33 +00001284 r->connection->log->file = clcf->err_log->file;
1285
Igor Sysoevb0518172006-04-26 15:21:08 +00001286 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
1287 r->connection->log->log_level = clcf->err_log->log_level;
1288 }
Igor Sysoevb85fd592005-08-23 15:36:54 +00001289 }
1290
1291 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
1292 r->connection->sendfile = 1;
1293
1294 } else {
1295 r->connection->sendfile = 0;
1296 }
1297
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00001298 if (clcf->client_body_in_file_only) {
1299 r->request_body_in_file_only = 1;
1300 r->request_body_in_persistent_file = 1;
Igor Sysoevcd5b99a2007-01-25 08:45:04 +00001301 r->request_body_in_clean_file =
1302 clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
Igor Sysoev7bdb7202006-04-19 15:30:56 +00001303 r->request_body_file_log_level = NGX_LOG_NOTICE;
1304
1305 } else {
1306 r->request_body_file_log_level = NGX_LOG_WARN;
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00001307 }
1308
Igor Sysoevb85fd592005-08-23 15:36:54 +00001309 if (r->keepalive && clcf->keepalive_timeout == 0) {
1310 r->keepalive = 0;
1311 }
1312
1313 if (!clcf->tcp_nopush) {
1314 /* disable TCP_NOPUSH/TCP_CORK use */
1315 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
1316 }
1317
Igor Sysoevc2807ec2006-02-16 15:26:46 +00001318 if (r->limit_rate == 0) {
1319 r->limit_rate = clcf->limit_rate;
1320 }
Igor Sysoev5192b362005-07-08 14:34:20 +00001321
Igor Sysoev6253ca12003-05-27 12:18:54 +00001322 if (clcf->handler) {
Igor Sysoevb3e73d82003-10-10 15:10:50 +00001323 r->content_handler = clcf->handler;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001324 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001325}
1326
1327
Igor Sysoevdc911282008-08-17 18:02:55 +00001328/*
1329 * NGX_OK - exact or regex match
1330 * NGX_DONE - auto redirect
1331 * NGX_AGAIN - inclusive match
1332 * NGX_ERROR - regex error
1333 * NGX_DECLINED - no match
1334 */
1335
Igor Sysoevaa828612005-02-09 14:31:07 +00001336static ngx_int_t
Igor Sysoeve55988c2008-05-24 14:14:13 +00001337ngx_http_core_find_location(ngx_http_request_t *r)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001338{
Igor Sysoeve55988c2008-05-24 14:14:13 +00001339 ngx_int_t rc;
1340 ngx_http_core_loc_conf_t *pclcf;
Igor Sysoev9a702422008-08-17 17:58:16 +00001341#if (NGX_PCRE)
Igor Sysoev925baa02009-03-06 12:49:22 +00001342 ngx_int_t n, len;
Igor Sysoev9a702422008-08-17 17:58:16 +00001343 ngx_uint_t noregex;
1344 ngx_http_core_loc_conf_t *clcf, **clcfp;
1345
1346 noregex = 0;
1347#endif
Igor Sysoeve55988c2008-05-24 14:14:13 +00001348
1349 pclcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1350
1351 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
1352
1353 if (rc == NGX_AGAIN) {
Igor Sysoev9a702422008-08-17 17:58:16 +00001354
1355#if (NGX_PCRE)
1356 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1357
1358 noregex = clcf->noregex;
1359#endif
1360
Igor Sysoeve55988c2008-05-24 14:14:13 +00001361 /* look up nested locations */
Igor Sysoev9a702422008-08-17 17:58:16 +00001362
Igor Sysoeve55988c2008-05-24 14:14:13 +00001363 rc = ngx_http_core_find_location(r);
1364 }
1365
1366 if (rc == NGX_OK || rc == NGX_DONE) {
1367 return rc;
1368 }
1369
1370 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1371
1372#if (NGX_PCRE)
Igor Sysoeve55988c2008-05-24 14:14:13 +00001373
Igor Sysoev9a702422008-08-17 17:58:16 +00001374 if (noregex == 0 && pclcf->regex_locations) {
Igor Sysoeve55988c2008-05-24 14:14:13 +00001375
Igor Sysoev925baa02009-03-06 12:49:22 +00001376 len = 0;
1377
Igor Sysoeve55988c2008-05-24 14:14:13 +00001378 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
1379
1380 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1381 "test location: ~ \"%V\"", &(*clcfp)->name);
1382
Igor Sysoevc7e87af2009-03-14 19:24:17 +00001383 if ((*clcfp)->captures) {
Igor Sysoev925baa02009-03-06 12:49:22 +00001384
Igor Sysoev000609a2009-03-11 13:04:02 +00001385 len = (NGX_HTTP_MAX_CAPTURES + 1) * 3;
Igor Sysoev925baa02009-03-06 12:49:22 +00001386
Igor Sysoev925baa02009-03-06 12:49:22 +00001387 if (r->captures == NULL) {
Igor Sysoevc7e87af2009-03-14 19:24:17 +00001388 r->captures = ngx_palloc(r->pool, len * sizeof(int));
1389 if (r->captures == NULL) {
1390 return NGX_ERROR;
1391 }
Igor Sysoev925baa02009-03-06 12:49:22 +00001392 }
1393 }
1394
1395 n = ngx_regex_exec((*clcfp)->regex, &r->uri, r->captures, len);
Igor Sysoeve55988c2008-05-24 14:14:13 +00001396
1397 if (n == NGX_REGEX_NO_MATCHED) {
1398 continue;
1399 }
1400
1401 if (n < 0) {
1402 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1403 ngx_regex_exec_n
1404 " failed: %d on \"%V\" using \"%V\"",
1405 n, &r->uri, &(*clcfp)->name);
Igor Sysoevdc911282008-08-17 18:02:55 +00001406 return NGX_ERROR;
Igor Sysoeve55988c2008-05-24 14:14:13 +00001407 }
1408
1409 /* match */
1410
1411 r->loc_conf = (*clcfp)->loc_conf;
1412
Igor Sysoev925baa02009-03-06 12:49:22 +00001413 r->ncaptures = len;
1414 r->captures_data = r->uri.data;
1415
Igor Sysoeve55988c2008-05-24 14:14:13 +00001416 /* look up nested locations */
1417
Igor Sysoevdc911282008-08-17 18:02:55 +00001418 rc = ngx_http_core_find_location(r);
1419
1420 return (rc == NGX_ERROR) ? rc : NGX_OK;
Igor Sysoeve55988c2008-05-24 14:14:13 +00001421 }
1422 }
Igor Sysoev307ab0d2007-08-12 15:25:09 +00001423#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001424
Igor Sysoeve55988c2008-05-24 14:14:13 +00001425 return rc;
1426}
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001427
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001428
Igor Sysoeve55988c2008-05-24 14:14:13 +00001429/*
1430 * NGX_OK - exact match
1431 * NGX_DONE - auto redirect
1432 * NGX_AGAIN - inclusive match
1433 * NGX_DECLINED - no match
1434 */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001435
Igor Sysoeve55988c2008-05-24 14:14:13 +00001436static ngx_int_t
1437ngx_http_core_find_static_location(ngx_http_request_t *r,
1438 ngx_http_location_tree_node_t *node)
1439{
1440 u_char *uri;
1441 size_t len, n;
1442 ngx_int_t rc, rv;
1443
1444 len = r->uri.len;
1445 uri = r->uri.data;
1446
1447 rv = NGX_DECLINED;
1448
1449 for ( ;; ) {
1450
1451 if (node == NULL) {
1452 return rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001453 }
1454
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001455 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoeve55988c2008-05-24 14:14:13 +00001456 "test location: \"%*s\"", node->len, node->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001457
Igor Sysoeve55988c2008-05-24 14:14:13 +00001458 n = (len <= (size_t) node->len) ? len : node->len;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001459
Igor Sysoev0f17f6c2008-07-29 16:55:11 +00001460 rc = ngx_filename_cmp(uri, node->name, n);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001461
Igor Sysoeve55988c2008-05-24 14:14:13 +00001462 if (rc != 0) {
1463 node = (rc < 0) ? node->left : node->right;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001464
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001465 continue;
1466 }
1467
Igor Sysoeve55988c2008-05-24 14:14:13 +00001468 if (len > (size_t) node->len) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001469
Igor Sysoeve55988c2008-05-24 14:14:13 +00001470 if (node->inclusive) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001471
Igor Sysoeve55988c2008-05-24 14:14:13 +00001472 r->loc_conf = node->inclusive->loc_conf;
1473 rv = NGX_AGAIN;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001474
Igor Sysoeve55988c2008-05-24 14:14:13 +00001475 node = node->tree;
1476 uri += n;
1477 len -= n;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001478
1479 continue;
Igor Sysoevea521232004-07-26 16:21:18 +00001480 }
1481
Igor Sysoeve55988c2008-05-24 14:14:13 +00001482 /* exact only */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001483
Igor Sysoeve55988c2008-05-24 14:14:13 +00001484 node = node->right;
Igor Sysoev307ab0d2007-08-12 15:25:09 +00001485
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001486 continue;
1487 }
1488
Igor Sysoeve55988c2008-05-24 14:14:13 +00001489 if (len == (size_t) node->len) {
1490
1491 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1492 node->inclusive->loc_conf;
1493 return NGX_OK;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001494 }
1495
Igor Sysoeve55988c2008-05-24 14:14:13 +00001496 /* len < node->len */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001497
Igor Sysoeve55988c2008-05-24 14:14:13 +00001498 if (len + 1 == (size_t) node->len && node->auto_redirect) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001499
Igor Sysoeve55988c2008-05-24 14:14:13 +00001500 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1501 node->inclusive->loc_conf;
1502 rv = NGX_DONE;
1503 }
1504
1505 node = node->left;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001506 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001507}
1508
1509
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001510void *
1511ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1512{
1513 u_char c, *p;
1514 ngx_uint_t i, hash;
1515
1516 if (r->headers_out.content_type.len == 0) {
1517 return NULL;
1518 }
1519
1520 if (r->headers_out.content_type_lowcase == NULL) {
1521
1522 p = ngx_pnalloc(r->pool, r->headers_out.content_type_len);
1523
1524 if (p == NULL) {
1525 return NULL;
1526 }
1527
1528 r->headers_out.content_type_lowcase = p;
1529
1530 hash = 0;
1531
1532 for (i = 0; i < r->headers_out.content_type_len; i++) {
1533 c = ngx_tolower(r->headers_out.content_type.data[i]);
1534 hash = ngx_hash(hash, c);
1535 *p++ = c;
1536 }
1537
1538 r->headers_out.content_type_hash = hash;
1539 }
1540
1541 return ngx_hash_find(types_hash,
1542 r->headers_out.content_type_hash,
1543 r->headers_out.content_type_lowcase,
1544 r->headers_out.content_type_len);
1545}
1546
1547
Igor Sysoevaa828612005-02-09 14:31:07 +00001548ngx_int_t
1549ngx_http_set_content_type(ngx_http_request_t *r)
Igor Sysoev865c1502003-11-30 20:03:18 +00001550{
Igor Sysoev6a078332008-08-04 10:18:36 +00001551 u_char c, *exten;
Igor Sysoev24025022005-12-16 15:07:08 +00001552 ngx_str_t *type;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001553 ngx_uint_t i, hash;
Igor Sysoev865c1502003-11-30 20:03:18 +00001554 ngx_http_core_loc_conf_t *clcf;
1555
Igor Sysoev08e63d42006-08-14 15:09:38 +00001556 if (r->headers_out.content_type.len) {
1557 return NGX_OK;
1558 }
1559
Igor Sysoev865c1502003-11-30 20:03:18 +00001560 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1561
1562 if (r->exten.len) {
Igor Sysoev805d9db2005-02-03 19:33:37 +00001563
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001564 hash = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001565
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001566 for (i = 0; i < r->exten.len; i++) {
1567 c = r->exten.data[i];
1568
1569 if (c >= 'A' && c <= 'Z') {
1570
Igor Sysoev6a078332008-08-04 10:18:36 +00001571 exten = ngx_pnalloc(r->pool, r->exten.len);
1572 if (exten == NULL) {
Igor Sysoev1f4220e2009-02-24 10:42:23 +00001573 return NGX_ERROR;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001574 }
1575
Igor Sysoev6a078332008-08-04 10:18:36 +00001576 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001577
1578 r->exten.data = exten;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001579
1580 break;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001581 }
1582
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001583 hash = ngx_hash(hash, c);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001584 }
1585
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001586 type = ngx_hash_find(&clcf->types_hash, hash,
Igor Sysoev24025022005-12-16 15:07:08 +00001587 r->exten.data, r->exten.len);
Igor Sysoev865c1502003-11-30 20:03:18 +00001588
Igor Sysoev24025022005-12-16 15:07:08 +00001589 if (type) {
Igor Sysoevef809b82006-06-28 16:00:26 +00001590 r->headers_out.content_type_len = type->len;
Igor Sysoev24025022005-12-16 15:07:08 +00001591 r->headers_out.content_type = *type;
Igor Sysoevef809b82006-06-28 16:00:26 +00001592
Igor Sysoev24025022005-12-16 15:07:08 +00001593 return NGX_OK;
Igor Sysoev865c1502003-11-30 20:03:18 +00001594 }
1595 }
1596
Igor Sysoevef809b82006-06-28 16:00:26 +00001597 r->headers_out.content_type_len = clcf->default_type.len;
Igor Sysoev24025022005-12-16 15:07:08 +00001598 r->headers_out.content_type = clcf->default_type;
Igor Sysoev865c1502003-11-30 20:03:18 +00001599
1600 return NGX_OK;
1601}
1602
1603
Igor Sysoevaa828612005-02-09 14:31:07 +00001604ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +00001605ngx_http_set_exten(ngx_http_request_t *r)
Igor Sysoev3b30a902003-12-25 20:26:58 +00001606{
1607 ngx_int_t i;
1608
1609 r->exten.len = 0;
1610 r->exten.data = NULL;
1611
1612 for (i = r->uri.len - 1; i > 1; i--) {
1613 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001614
Igor Sysoev3b30a902003-12-25 20:26:58 +00001615 r->exten.len = r->uri.len - i - 1;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001616 r->exten.data = &r->uri.data[i + 1];
Igor Sysoev3b30a902003-12-25 20:26:58 +00001617
1618 break;
1619
1620 } else if (r->uri.data[i] == '/') {
1621 break;
1622 }
1623 }
1624
1625 return NGX_OK;
1626}
1627
1628
Igor Sysoevaa828612005-02-09 14:31:07 +00001629ngx_int_t
Igor Sysoev208eed22005-10-07 13:30:52 +00001630ngx_http_send_header(ngx_http_request_t *r)
1631{
1632 if (r->err_status) {
1633 r->headers_out.status = r->err_status;
1634 r->headers_out.status_line.len = 0;
1635 }
1636
1637 return ngx_http_top_header_filter(r);
1638}
1639
1640
1641ngx_int_t
1642ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1643{
1644 ngx_int_t rc;
1645
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001646 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1647 "http output filter \"%V?%V\"", &r->uri, &r->args);
Igor Sysoev208eed22005-10-07 13:30:52 +00001648
1649 rc = ngx_http_top_body_filter(r, in);
1650
1651 if (rc == NGX_ERROR) {
1652 /* NGX_ERROR may be returned by any filter */
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001653 r->connection->error = 1;
Igor Sysoev208eed22005-10-07 13:30:52 +00001654 }
1655
1656 return rc;
1657}
1658
1659
1660u_char *
1661ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001662 size_t *root_length, size_t reserved)
Igor Sysoev208eed22005-10-07 13:30:52 +00001663{
Igor Sysoev8fea8852006-03-15 09:53:04 +00001664 u_char *last;
1665 size_t alias;
1666 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev208eed22005-10-07 13:30:52 +00001667
1668 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1669
1670 alias = clcf->alias ? clcf->name.len : 0;
1671
Igor Sysoev34303462006-01-24 16:08:27 +00001672 if (alias && !r->valid_location) {
1673 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1674 "\"alias\" could not be used in location \"%V\" "
1675 "where URI was rewritten", &clcf->name);
1676 return NULL;
1677 }
1678
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001679 if (clcf->root_lengths == NULL) {
Igor Sysoev208eed22005-10-07 13:30:52 +00001680
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001681 *root_length = clcf->root.len;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001682
Igor Sysoevbb7d6152009-03-14 19:20:34 +00001683 path->len = clcf->root.len + reserved + r->uri.len - alias + 1;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001684
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +00001685 path->data = ngx_pnalloc(r->pool, path->len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001686 if (path->data == NULL) {
1687 return NULL;
1688 }
1689
1690 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001691
Igor Sysoev8fea8852006-03-15 09:53:04 +00001692 } else {
Igor Sysoevf76a6c22009-03-18 12:21:19 +00001693 reserved += alias ? 1 : r->uri.len + 1;
1694
1695 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
Igor Sysoevc55a1042006-08-09 19:59:45 +00001696 clcf->root_values->elts)
Igor Sysoev8f125582006-07-28 15:16:17 +00001697 == NULL)
1698 {
1699 return NULL;
1700 }
1701
Igor Sysoev1f4220e2009-02-24 10:42:23 +00001702 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) {
Igor Sysoev8fea8852006-03-15 09:53:04 +00001703 return NULL;
1704 }
1705
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001706 *root_length = path->len - reserved;
1707 last = path->data + *root_length;
Igor Sysoev925baa02009-03-06 12:49:22 +00001708
1709 if (alias) {
1710 *last = '\0';
1711 return last;
1712 }
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001713 }
1714
Igor Sysoev8fea8852006-03-15 09:53:04 +00001715 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
Igor Sysoev208eed22005-10-07 13:30:52 +00001716
1717 return last;
1718}
1719
1720
1721ngx_int_t
Igor Sysoevceb99292005-09-06 16:09:32 +00001722ngx_http_auth_basic_user(ngx_http_request_t *r)
1723{
1724 ngx_str_t auth, encoded;
1725 ngx_uint_t len;
1726
1727 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1728 return NGX_DECLINED;
1729 }
1730
1731 if (r->headers_in.authorization == NULL) {
1732 r->headers_in.user.data = (u_char *) "";
1733 return NGX_DECLINED;
1734 }
1735
1736 encoded = r->headers_in.authorization->value;
1737
1738 if (encoded.len < sizeof("Basic ") - 1
Igor Sysoev722231f2007-02-14 18:51:19 +00001739 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
1740 sizeof("Basic ") - 1)
1741 != 0)
Igor Sysoevceb99292005-09-06 16:09:32 +00001742 {
1743 r->headers_in.user.data = (u_char *) "";
1744 return NGX_DECLINED;
1745 }
1746
1747 encoded.len -= sizeof("Basic ") - 1;
1748 encoded.data += sizeof("Basic ") - 1;
1749
1750 while (encoded.len && encoded.data[0] == ' ') {
1751 encoded.len--;
1752 encoded.data++;
1753 }
1754
1755 if (encoded.len == 0) {
1756 r->headers_in.user.data = (u_char *) "";
1757 return NGX_DECLINED;
1758 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001759
Igor Sysoevceb99292005-09-06 16:09:32 +00001760 auth.len = ngx_base64_decoded_length(encoded.len);
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +00001761 auth.data = ngx_pnalloc(r->pool, auth.len + 1);
Igor Sysoevceb99292005-09-06 16:09:32 +00001762 if (auth.data == NULL) {
1763 return NGX_ERROR;
1764 }
1765
1766 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
1767 r->headers_in.user.data = (u_char *) "";
1768 return NGX_DECLINED;
1769 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001770
Igor Sysoevceb99292005-09-06 16:09:32 +00001771 auth.data[auth.len] = '\0';
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001772
1773 for (len = 0; len < auth.len; len++) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001774 if (auth.data[len] == ':') {
1775 break;
1776 }
1777 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001778
Igor Sysoev09c684b2005-11-09 17:25:55 +00001779 if (len == 0 || len == auth.len) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001780 r->headers_in.user.data = (u_char *) "";
1781 return NGX_DECLINED;
1782 }
1783
1784 r->headers_in.user.len = len;
1785 r->headers_in.user.data = auth.data;
1786 r->headers_in.passwd.len = auth.len - len - 1;
1787 r->headers_in.passwd.data = &auth.data[len + 1];
1788
1789 return NGX_OK;
1790}
1791
1792
Igor Sysoev3f24ae22007-12-29 15:30:39 +00001793ngx_int_t
1794ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s)
1795{
Igor Sysoev3658a5b2009-03-18 12:23:57 +00001796 socklen_t len;
1797 ngx_uint_t addr;
1798 ngx_connection_t *c;
1799 u_char sa[NGX_SOCKADDRLEN];
1800 struct sockaddr_in *sin;
1801#if (NGX_HAVE_INET6)
1802 ngx_uint_t i;
1803 struct sockaddr_in6 *sin6;
1804#endif
Igor Sysoev3f24ae22007-12-29 15:30:39 +00001805
1806 c = r->connection;
1807
Igor Sysoev3658a5b2009-03-18 12:23:57 +00001808 switch (c->local_sockaddr->sa_family) {
1809
1810#if (NGX_HAVE_INET6)
1811 case AF_INET6:
1812 sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
1813
1814 for (addr = 0, i = 0; addr == 0 && i < 16; i++) {
1815 addr |= sin6->sin6_addr.s6_addr[i];
1816 }
1817
1818 break;
1819#endif
1820
1821 default: /* AF_INET */
1822 sin = (struct sockaddr_in *) c->local_sockaddr;
1823 addr = sin->sin_addr.s_addr;
1824 break;
1825 }
1826
1827 if (addr == 0) {
Igor Sysoeva35eacc2009-02-21 07:02:02 +00001828
1829 len = NGX_SOCKADDRLEN;
1830
1831 if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) {
Igor Sysoev3f24ae22007-12-29 15:30:39 +00001832 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
1833 return NGX_ERROR;
1834 }
1835
Igor Sysoeva35eacc2009-02-21 07:02:02 +00001836 c->local_sockaddr = ngx_palloc(r->connection->pool, len);
1837 if (c->local_sockaddr == NULL) {
1838 return NGX_ERROR;
1839 }
Igor Sysoev6645e762008-10-17 12:36:48 +00001840
Igor Sysoeva35eacc2009-02-21 07:02:02 +00001841 c->local_socklen = len;
1842 ngx_memcpy(c->local_sockaddr, &sa, len);
Igor Sysoev3f24ae22007-12-29 15:30:39 +00001843 }
1844
1845 if (s == NULL) {
1846 return NGX_OK;
1847 }
1848
Igor Sysoeva35eacc2009-02-21 07:02:02 +00001849 s->len = ngx_sock_ntop(c->local_sockaddr, s->data, s->len, 0);
Igor Sysoev3f24ae22007-12-29 15:30:39 +00001850
1851 return NGX_OK;
1852}
1853
1854
Igor Sysoevc16b0052007-12-27 14:21:59 +00001855#if (NGX_HTTP_GZIP)
1856
1857ngx_int_t
1858ngx_http_gzip_ok(ngx_http_request_t *r)
1859{
1860 time_t date, expires;
1861 ngx_uint_t p;
1862 ngx_array_t *cc;
1863 ngx_table_elt_t *e, *d;
1864 ngx_http_core_loc_conf_t *clcf;
1865
1866 if (r->gzip == 1) {
1867 return NGX_OK;
1868 }
1869
1870 if (r->gzip == 2) {
1871 return NGX_DECLINED;
1872 }
1873
1874 r->gzip = 2;
1875
1876 if (r != r->main
1877 || r->headers_in.accept_encoding == NULL
1878 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
1879 "gzip", 4 - 1)
1880 == NULL
1881
1882 /*
1883 * if the URL (without the "http://" prefix) is longer than 253 bytes,
1884 * then MSIE 4.x can not handle the compressed stream - it waits
1885 * too long, hangs up or crashes
1886 */
1887
1888 || (r->headers_in.msie4 && r->unparsed_uri.len > 200))
1889 {
1890 return NGX_DECLINED;
1891 }
1892
1893 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1894
Igor Sysoev54477e42008-08-26 15:09:28 +00001895 if (r->headers_in.msie6 && clcf->gzip_disable_msie6) {
1896 return NGX_DECLINED;
1897 }
1898
Igor Sysoevc16b0052007-12-27 14:21:59 +00001899 if (r->http_version < clcf->gzip_http_version) {
1900 return NGX_DECLINED;
1901 }
1902
1903 if (r->headers_in.via == NULL) {
1904 goto ok;
1905 }
1906
1907 p = clcf->gzip_proxied;
1908
1909 if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
1910 return NGX_DECLINED;
1911 }
1912
1913 if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
1914 goto ok;
1915 }
1916
1917 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
1918 goto ok;
1919 }
1920
1921 e = r->headers_out.expires;
1922
1923 if (e) {
1924
1925 if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
1926 return NGX_DECLINED;
1927 }
1928
1929 expires = ngx_http_parse_time(e->value.data, e->value.len);
1930 if (expires == NGX_ERROR) {
1931 return NGX_DECLINED;
1932 }
1933
1934 d = r->headers_out.date;
1935
1936 if (d) {
1937 date = ngx_http_parse_time(d->value.data, d->value.len);
1938 if (date == NGX_ERROR) {
1939 return NGX_DECLINED;
1940 }
1941
1942 } else {
1943 date = ngx_time();
1944 }
1945
1946 if (expires < date) {
1947 goto ok;
1948 }
1949
1950 return NGX_DECLINED;
1951 }
1952
1953 cc = &r->headers_out.cache_control;
1954
1955 if (cc->elts) {
1956
1957 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
1958 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
1959 NULL)
1960 >= 0)
1961 {
1962 goto ok;
1963 }
1964
1965 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
1966 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
1967 NULL)
1968 >= 0)
1969 {
1970 goto ok;
1971 }
1972
1973 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
1974 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
1975 NULL)
1976 >= 0)
1977 {
1978 goto ok;
1979 }
1980
1981 return NGX_DECLINED;
1982 }
1983
1984 if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
1985 return NGX_DECLINED;
1986 }
1987
1988 if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
1989 return NGX_DECLINED;
1990 }
1991
1992ok:
1993
1994#if (NGX_PCRE)
1995
1996 if (clcf->gzip_disable && r->headers_in.user_agent) {
1997
Igor Sysoevd5fe8182007-12-28 13:15:36 +00001998 if (ngx_regex_exec_array(clcf->gzip_disable,
Igor Sysoevc16b0052007-12-27 14:21:59 +00001999 &r->headers_in.user_agent->value,
2000 r->connection->log)
2001 != NGX_DECLINED)
2002 {
2003 return NGX_DECLINED;
2004 }
2005 }
2006
2007#endif
2008
2009 r->gzip = 1;
2010
2011 return NGX_OK;
2012}
2013
2014#endif
2015
2016
Igor Sysoevceb99292005-09-06 16:09:32 +00002017ngx_int_t
Igor Sysoev899b44e2005-05-12 14:58:06 +00002018ngx_http_subrequest(ngx_http_request_t *r,
Igor Sysoev9fcccaf2006-10-10 14:30:39 +00002019 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
Igor Sysoev960100e2006-10-13 15:20:10 +00002020 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
Igor Sysoev899b44e2005-05-12 14:58:06 +00002021{
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002022 ngx_connection_t *c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002023 ngx_http_request_t *sr;
2024 ngx_http_core_srv_conf_t *cscf;
2025 ngx_http_postponed_request_t *pr, *p;
2026
Igor Sysoevef809b82006-06-28 16:00:26 +00002027 r->main->subrequests--;
2028
2029 if (r->main->subrequests == 0) {
2030 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002031 "subrequests cycle while processing \"%V\"", uri);
Igor Sysoev5fd6d342006-11-02 13:48:28 +00002032 r->main->subrequests = 1;
Igor Sysoevef809b82006-06-28 16:00:26 +00002033 return NGX_ERROR;
2034 }
2035
Igor Sysoev899b44e2005-05-12 14:58:06 +00002036 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
2037 if (sr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002038 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002039 }
2040
2041 sr->signature = NGX_HTTP_MODULE;
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002042
2043 c = r->connection;
2044 sr->connection = c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002045
2046 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
2047 if (sr->ctx == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002048 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002049 }
2050
2051 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
Igor Sysoevc31a9bb2005-11-26 10:11:11 +00002052 sizeof(ngx_table_elt_t))
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002053 != NGX_OK)
Igor Sysoev899b44e2005-05-12 14:58:06 +00002054 {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002055 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002056 }
2057
2058 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2059 sr->main_conf = cscf->ctx->main_conf;
2060 sr->srv_conf = cscf->ctx->srv_conf;
2061 sr->loc_conf = cscf->ctx->loc_conf;
2062
2063 sr->pool = r->pool;
2064
2065 sr->headers_in = r->headers_in;
2066
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002067 ngx_http_clear_content_length(sr);
2068 ngx_http_clear_accept_ranges(sr);
2069 ngx_http_clear_last_modified(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002070
2071 sr->request_body = r->request_body;
2072
2073 sr->method = NGX_HTTP_GET;
2074 sr->http_version = r->http_version;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002075
2076 sr->request_line = r->request_line;
2077 sr->uri = *uri;
Igor Sysoev09c684b2005-11-09 17:25:55 +00002078
Igor Sysoev899b44e2005-05-12 14:58:06 +00002079 if (args) {
2080 sr->args = *args;
2081 }
Igor Sysoev09c684b2005-11-09 17:25:55 +00002082
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002083 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
2084 "http subrequest \"%V?%V\"", uri, &sr->args);
2085
Igor Sysoev960100e2006-10-13 15:20:10 +00002086 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;
2087 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
Igor Sysoev851cd732008-12-08 14:23:20 +00002088 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
Igor Sysoev09c684b2005-11-09 17:25:55 +00002089
Igor Sysoev899b44e2005-05-12 14:58:06 +00002090 sr->unparsed_uri = r->unparsed_uri;
Igor Sysoev5a45c682008-01-08 21:06:38 +00002091 sr->method_name = ngx_http_core_get_method;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002092 sr->http_protocol = r->http_protocol;
2093
2094 if (ngx_http_set_exten(sr) != NGX_OK) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002095 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002096 }
2097
Igor Sysoevf6e1fe32005-10-04 10:38:53 +00002098 sr->main = r->main;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002099 sr->parent = r;
Igor Sysoev960100e2006-10-13 15:20:10 +00002100 sr->post_subrequest = ps;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002101 sr->read_event_handler = ngx_http_request_empty_handler;
Igor Sysoev851cd732008-12-08 14:23:20 +00002102 sr->write_event_handler = ngx_http_handler;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002103
Igor Sysoevd8e54ad2008-12-24 06:11:04 +00002104 if (c->data == r && r->postponed == NULL) {
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002105 c->data = sr;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002106 }
2107
Igor Sysoev899b44e2005-05-12 14:58:06 +00002108 sr->variables = r->variables;
2109
2110 sr->log_handler = r->log_handler;
2111
2112 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
2113 if (pr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002114 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002115 }
2116
2117 pr->request = sr;
2118 pr->out = NULL;
2119 pr->next = NULL;
2120
2121 if (r->postponed) {
2122 for (p = r->postponed; p->next; p = p->next) { /* void */ }
2123 p->next = pr;
2124
2125 } else {
2126 r->postponed = pr;
2127 }
2128
2129 sr->internal = 1;
2130
Igor Sysoev31eb8c02005-09-23 11:02:22 +00002131 sr->discard_body = r->discard_body;
Igor Sysoev303df472008-12-26 13:43:42 +00002132 sr->expect_tested = 1;
Igor Sysoevd52477f2005-05-16 13:53:20 +00002133 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
2134
Igor Sysoev6f134cc2006-05-23 14:54:58 +00002135 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
2136
Igor Sysoev851cd732008-12-08 14:23:20 +00002137 r->main->subrequests++;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002138
Igor Sysoev851cd732008-12-08 14:23:20 +00002139 *psr = sr;
Igor Sysoevac72bd12006-05-04 15:32:46 +00002140
Igor Sysoev851cd732008-12-08 14:23:20 +00002141 return ngx_http_post_request(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002142}
2143
2144
2145ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +00002146ngx_http_internal_redirect(ngx_http_request_t *r,
2147 ngx_str_t *uri, ngx_str_t *args)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002148{
Igor Sysoevaa828612005-02-09 14:31:07 +00002149 ngx_http_core_srv_conf_t *cscf;
2150
Igor Sysoev5fede1e2006-08-18 14:17:54 +00002151 r->uri_changes--;
2152
2153 if (r->uri_changes == 0) {
2154 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002155 "rewrite or internal redirection cycle "
2156 "while internal redirect to \"%V\"", uri);
2157
Igor Sysoev5fede1e2006-08-18 14:17:54 +00002158 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2159 return NGX_DONE;
2160 }
2161
Igor Sysoev1b735832004-11-11 14:07:14 +00002162 r->uri = *uri;
Igor Sysoev13933252003-05-29 13:02:09 +00002163
2164 if (args) {
Igor Sysoev1b735832004-11-11 14:07:14 +00002165 r->args = *args;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002166
2167 } else {
2168 r->args.len = 0;
2169 r->args.data = NULL;
Igor Sysoev13933252003-05-29 13:02:09 +00002170 }
2171
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002172 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2173 "internal redirect: \"%V?%V\"", uri, &r->args);
2174
Igor Sysoev3b30a902003-12-25 20:26:58 +00002175 if (ngx_http_set_exten(r) != NGX_OK) {
Igor Sysoev5fede1e2006-08-18 14:17:54 +00002176 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2177 return NGX_DONE;
Igor Sysoev13933252003-05-29 13:02:09 +00002178 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002179
Igor Sysoevef316432006-08-16 13:09:33 +00002180 /* clear the modules contexts */
2181 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
Igor Sysoev0a280a32003-10-12 16:49:16 +00002182
Igor Sysoevaa828612005-02-09 14:31:07 +00002183 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2184 r->loc_conf = cscf->ctx->loc_conf;
2185
Igor Sysoevb85fd592005-08-23 15:36:54 +00002186 ngx_http_update_location_config(r);
2187
Igor Sysoev899b44e2005-05-12 14:58:06 +00002188 r->internal = 1;
2189
Igor Sysoev79a80482003-05-14 17:13:13 +00002190 ngx_http_handler(r);
Igor Sysoev13933252003-05-29 13:02:09 +00002191
Igor Sysoev9760a132003-10-21 07:47:21 +00002192 return NGX_DONE;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002193}
2194
2195
Igor Sysoev8889b652007-07-29 18:11:39 +00002196ngx_int_t
2197ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
2198{
Igor Sysoev8889b652007-07-29 18:11:39 +00002199 ngx_http_core_srv_conf_t *cscf;
2200 ngx_http_core_loc_conf_t **clcfp;
2201 ngx_http_core_main_conf_t *cmcf;
2202
2203 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2204
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002205 if (cscf->named_locations) {
Igor Sysoev8889b652007-07-29 18:11:39 +00002206
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002207 for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
Igor Sysoev8889b652007-07-29 18:11:39 +00002208
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002209 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2210 "test location: \"%V\"", &(*clcfp)->name);
2211
2212 if (name->len != (*clcfp)->name.len
2213 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
2214 {
2215 continue;
2216 }
2217
2218 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2219 "using location: %V \"%V?%V\"",
2220 name, &r->uri, &r->args);
2221
2222 r->internal = 1;
2223 r->content_handler = NULL;
2224 r->loc_conf = (*clcfp)->loc_conf;
2225
2226 ngx_http_update_location_config(r);
2227
2228 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2229
2230 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
2231
2232 ngx_http_core_run_phases(r);
2233
2234 return NGX_DONE;
Igor Sysoev8889b652007-07-29 18:11:39 +00002235 }
Igor Sysoev8889b652007-07-29 18:11:39 +00002236 }
2237
2238 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev9e039cf2007-10-22 10:15:48 +00002239 "could not find named location \"%V\"", name);
Igor Sysoev8889b652007-07-29 18:11:39 +00002240
2241 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
Igor Sysoeve55988c2008-05-24 14:14:13 +00002242
Igor Sysoev8889b652007-07-29 18:11:39 +00002243 return NGX_DONE;
2244}
2245
2246
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002247ngx_http_cleanup_t *
2248ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
Igor Sysoev0a280a32003-10-12 16:49:16 +00002249{
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002250 ngx_http_cleanup_t *cln;
Igor Sysoev0a280a32003-10-12 16:49:16 +00002251
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002252 r = r->main;
2253
2254 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
2255 if (cln == NULL) {
2256 return NULL;
Igor Sysoev0a280a32003-10-12 16:49:16 +00002257 }
2258
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002259 if (size) {
2260 cln->data = ngx_palloc(r->pool, size);
2261 if (cln->data == NULL) {
2262 return NULL;
2263 }
Igor Sysoev0a280a32003-10-12 16:49:16 +00002264
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002265 } else {
2266 cln->data = NULL;
2267 }
2268
2269 cln->handler = NULL;
2270 cln->next = r->cleanup;
2271
2272 r->cleanup = cln;
2273
2274 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2275 "http cleanup add: %p", cln);
2276
2277 return cln;
2278}
Igor Sysoev0a280a32003-10-12 16:49:16 +00002279
2280
Igor Sysoevaa828612005-02-09 14:31:07 +00002281static char *
2282ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002283{
Igor Sysoevc9151062007-06-05 06:44:08 +00002284 char *rv;
2285 void *mconf;
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002286 ngx_uint_t i;
Igor Sysoevc9151062007-06-05 06:44:08 +00002287 ngx_conf_t pcf;
2288 ngx_http_module_t *module;
2289 ngx_http_conf_ctx_t *ctx, *http_ctx;
2290 ngx_http_core_srv_conf_t *cscf, **cscfp;
Igor Sysoev8889b652007-07-29 18:11:39 +00002291 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002292
Igor Sysoevc1571722005-03-19 12:38:37 +00002293 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2294 if (ctx == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002295 return NGX_CONF_ERROR;
2296 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002297
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002298 http_ctx = cf->ctx;
2299 ctx->main_conf = http_ctx->main_conf;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002300
Igor Sysoeva9830112003-05-19 16:39:14 +00002301 /* the server{}'s srv_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002302
Igor Sysoevaa828612005-02-09 14:31:07 +00002303 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2304 if (ctx->srv_conf == NULL) {
2305 return NGX_CONF_ERROR;
2306 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002307
Igor Sysoeva9830112003-05-19 16:39:14 +00002308 /* the server{}'s loc_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002309
Igor Sysoevaa828612005-02-09 14:31:07 +00002310 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2311 if (ctx->loc_conf == NULL) {
2312 return NGX_CONF_ERROR;
2313 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002314
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002315 for (i = 0; ngx_modules[i]; i++) {
2316 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002317 continue;
2318 }
2319
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002320 module = ngx_modules[i]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002321
2322 if (module->create_srv_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002323 mconf = module->create_srv_conf(cf);
2324 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002325 return NGX_CONF_ERROR;
2326 }
2327
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002328 ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002329 }
2330
2331 if (module->create_loc_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002332 mconf = module->create_loc_conf(cf);
2333 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002334 return NGX_CONF_ERROR;
2335 }
2336
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002337 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002338 }
2339 }
2340
Igor Sysoevaa828612005-02-09 14:31:07 +00002341
2342 /* the server configuration context */
Igor Sysoeva9830112003-05-19 16:39:14 +00002343
Igor Sysoev6253ca12003-05-27 12:18:54 +00002344 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00002345 cscf->ctx = ctx;
2346
Igor Sysoevaa828612005-02-09 14:31:07 +00002347
Igor Sysoev6253ca12003-05-27 12:18:54 +00002348 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
Igor Sysoevaa828612005-02-09 14:31:07 +00002349
Igor Sysoevc1571722005-03-19 12:38:37 +00002350 cscfp = ngx_array_push(&cmcf->servers);
2351 if (cscfp == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002352 return NGX_CONF_ERROR;
2353 }
2354
Igor Sysoeva9830112003-05-19 16:39:14 +00002355 *cscfp = cscf;
2356
Igor Sysoevaa828612005-02-09 14:31:07 +00002357
Igor Sysoeva9830112003-05-19 16:39:14 +00002358 /* parse inside server{} */
2359
Igor Sysoev7b190b42005-06-07 15:56:31 +00002360 pcf = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002361 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00002362 cf->cmd_type = NGX_HTTP_SRV_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002363
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002364 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002365
Igor Sysoev7b190b42005-06-07 15:56:31 +00002366 *cf = pcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002367
Igor Sysoeva9830112003-05-19 16:39:14 +00002368 return rv;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002369}
2370
2371
Igor Sysoevaa828612005-02-09 14:31:07 +00002372static char *
2373ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002374{
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002375 char *rv;
Igor Sysoev22f6d862008-12-11 10:21:08 +00002376 u_char *mod;
2377 size_t len;
2378 ngx_str_t *value, *name;
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002379 ngx_uint_t i;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002380 ngx_conf_t save;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002381 ngx_http_module_t *module;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002382 ngx_http_conf_ctx_t *ctx, *pctx;
Igor Sysoeve55988c2008-05-24 14:14:13 +00002383 ngx_http_core_loc_conf_t *clcf, *pclcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002384
Igor Sysoevc1571722005-03-19 12:38:37 +00002385 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2386 if (ctx == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002387 return NGX_CONF_ERROR;
2388 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002389
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002390 pctx = cf->ctx;
2391 ctx->main_conf = pctx->main_conf;
2392 ctx->srv_conf = pctx->srv_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002393
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002394 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2395 if (ctx->loc_conf == NULL) {
2396 return NGX_CONF_ERROR;
2397 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002398
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002399 for (i = 0; ngx_modules[i]; i++) {
2400 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002401 continue;
2402 }
2403
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002404 module = ngx_modules[i]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002405
2406 if (module->create_loc_conf) {
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002407 ctx->loc_conf[ngx_modules[i]->ctx_index] =
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002408 module->create_loc_conf(cf);
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002409 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002410 return NGX_CONF_ERROR;
2411 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002412 }
2413 }
2414
Igor Sysoev6253ca12003-05-27 12:18:54 +00002415 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00002416 clcf->loc_conf = ctx->loc_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002417
Igor Sysoev3b30a902003-12-25 20:26:58 +00002418 value = cf->args->elts;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002419
2420 if (cf->args->nelts == 3) {
Igor Sysoev22f6d862008-12-11 10:21:08 +00002421
2422 len = value[1].len;
2423 mod = value[1].data;
2424 name = &value[2];
2425
2426 if (len == 1 && mod[0] == '=') {
2427
2428 clcf->name = *name;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002429 clcf->exact_match = 1;
2430
Igor Sysoev22f6d862008-12-11 10:21:08 +00002431 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
2432
2433 clcf->name = *name;
Igor Sysoevd43bee82004-11-20 19:52:20 +00002434 clcf->noregex = 1;
2435
Igor Sysoev22f6d862008-12-11 10:21:08 +00002436 } else if (len == 1 && mod[0] == '~') {
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00002437
Igor Sysoev22f6d862008-12-11 10:21:08 +00002438 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002439 return NGX_CONF_ERROR;
2440 }
2441
Igor Sysoev22f6d862008-12-11 10:21:08 +00002442 } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
2443
2444 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2445 return NGX_CONF_ERROR;
2446 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002447
2448 } else {
2449 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002450 "invalid location modifier \"%V\"", &value[1]);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002451 return NGX_CONF_ERROR;
2452 }
2453
2454 } else {
Igor Sysoev8889b652007-07-29 18:11:39 +00002455
Igor Sysoev22f6d862008-12-11 10:21:08 +00002456 name = &value[1];
Igor Sysoev8889b652007-07-29 18:11:39 +00002457
Igor Sysoev22f6d862008-12-11 10:21:08 +00002458 if (name->data[0] == '=') {
2459
2460 clcf->name.len = name->len - 1;
2461 clcf->name.data = name->data + 1;
2462 clcf->exact_match = 1;
2463
2464 } else if (name->data[0] == '^' && name->data[1] == '~') {
2465
2466 clcf->name.len = name->len - 2;
2467 clcf->name.data = name->data + 2;
2468 clcf->noregex = 1;
2469
2470 } else if (name->data[0] == '~') {
2471
2472 name->len--;
2473 name->data++;
2474
2475 if (name->data[0] == '*') {
2476
2477 name->len--;
2478 name->data++;
2479
2480 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2481 return NGX_CONF_ERROR;
2482 }
2483
2484 } else {
2485 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2486 return NGX_CONF_ERROR;
2487 }
2488 }
2489
2490 } else {
2491
2492 clcf->name = *name;
2493
2494 if (name->data[0] == '@') {
2495 clcf->named = 1;
2496 }
Igor Sysoev8889b652007-07-29 18:11:39 +00002497 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002498 }
2499
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002500 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
2501
Igor Sysoeve55988c2008-05-24 14:14:13 +00002502 if (pclcf->name.len) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002503
Igor Sysoeve55988c2008-05-24 14:14:13 +00002504 /* nested location */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002505
Igor Sysoev805d9db2005-02-03 19:33:37 +00002506#if 0
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002507 clcf->prev_location = pclcf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002508#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002509
2510 if (pclcf->exact_match) {
2511 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002512 "location \"%V\" could not be inside "
2513 "the exact location \"%V\"",
2514 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002515 return NGX_CONF_ERROR;
2516 }
2517
Igor Sysoev8889b652007-07-29 18:11:39 +00002518 if (pclcf->named) {
2519 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2520 "location \"%V\" could not be inside "
2521 "the named location \"%V\"",
2522 &clcf->name, &pclcf->name);
2523 return NGX_CONF_ERROR;
2524 }
2525
Igor Sysoeve55988c2008-05-24 14:14:13 +00002526 if (clcf->named) {
2527 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2528 "named location \"%V\" must be "
2529 "on server level only",
2530 &clcf->name);
2531 return NGX_CONF_ERROR;
2532 }
2533
Igor Sysoev22f6d862008-12-11 10:21:08 +00002534 len = pclcf->name.len;
2535
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00002536#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002537 if (clcf->regex == NULL
Igor Sysoev22f6d862008-12-11 10:21:08 +00002538 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00002539#else
Igor Sysoev22f6d862008-12-11 10:21:08 +00002540 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00002541#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002542 {
2543 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002544 "location \"%V\" is outside location \"%V\"",
2545 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002546 return NGX_CONF_ERROR;
2547 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002548 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002549
Igor Sysoeve55988c2008-05-24 14:14:13 +00002550 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
2551 return NGX_CONF_ERROR;
2552 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002553
Igor Sysoev805d9db2005-02-03 19:33:37 +00002554 save = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002555 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00002556 cf->cmd_type = NGX_HTTP_LOC_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002557
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002558 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002559
2560 *cf = save;
2561
Igor Sysoev79a80482003-05-14 17:13:13 +00002562 return rv;
2563}
2564
2565
Igor Sysoev22f6d862008-12-11 10:21:08 +00002566static ngx_int_t
2567ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
2568 ngx_str_t *regex, ngx_uint_t caseless)
2569{
2570#if (NGX_PCRE)
2571 ngx_str_t err;
2572 u_char errstr[NGX_MAX_CONF_ERRSTR];
2573
2574 err.len = NGX_MAX_CONF_ERRSTR;
2575 err.data = errstr;
2576
2577 clcf->regex = ngx_regex_compile(regex, caseless ? NGX_REGEX_CASELESS: 0,
2578 cf->pool, &err);
2579
2580 if (clcf->regex == NULL) {
2581 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
2582 return NGX_ERROR;
2583 }
2584
2585 clcf->name = *regex;
Igor Sysoev925baa02009-03-06 12:49:22 +00002586 clcf->captures = (ngx_regex_capture_count(clcf->regex) > 0);
Igor Sysoev22f6d862008-12-11 10:21:08 +00002587
2588 return NGX_OK;
2589
2590#else
2591
2592 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2593 "the using of the regex \"%V\" requires PCRE library",
2594 regex);
2595 return NGX_ERROR;
2596
2597#endif
2598}
2599
2600
Igor Sysoevaa828612005-02-09 14:31:07 +00002601static char *
2602ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev79a80482003-05-14 17:13:13 +00002603{
Igor Sysoev7bdb7202006-04-19 15:30:56 +00002604 ngx_http_core_loc_conf_t *lcf = conf;
2605
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002606 char *rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002607 ngx_conf_t save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002608
Igor Sysoev7bdb7202006-04-19 15:30:56 +00002609 if (lcf->types == NULL) {
2610 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
2611 if (lcf->types == NULL) {
2612 return NGX_CONF_ERROR;
2613 }
2614 }
2615
Igor Sysoev805d9db2005-02-03 19:33:37 +00002616 save = *cf;
2617 cf->handler = ngx_http_core_type;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002618 cf->handler_conf = conf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002619
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002620 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002621
2622 *cf = save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002623
2624 return rv;
2625}
2626
2627
Igor Sysoevaa828612005-02-09 14:31:07 +00002628static char *
2629ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002630{
2631 ngx_http_core_loc_conf_t *lcf = conf;
Igor Sysoev79a80482003-05-14 17:13:13 +00002632
Igor Sysoeveba03e62007-03-29 10:27:24 +00002633 ngx_str_t *value, *content_type, *old, file;
Igor Sysoev6a078332008-08-04 10:18:36 +00002634 ngx_uint_t i, n, hash;
Igor Sysoev24025022005-12-16 15:07:08 +00002635 ngx_hash_key_t *type;
Igor Sysoev79a80482003-05-14 17:13:13 +00002636
Igor Sysoeveba03e62007-03-29 10:27:24 +00002637 value = cf->args->elts;
2638
2639 if (ngx_strcmp(value[0].data, "include") == 0) {
2640 file = value[1];
2641
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002642 if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
Igor Sysoeveba03e62007-03-29 10:27:24 +00002643 return NGX_CONF_ERROR;
2644 }
2645
2646 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
2647
2648 return ngx_conf_parse(cf, &file);
2649 }
2650
Igor Sysoev24025022005-12-16 15:07:08 +00002651 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
2652 if (content_type == NULL) {
2653 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00002654 }
2655
Igor Sysoev24025022005-12-16 15:07:08 +00002656 *content_type = value[0];
Igor Sysoev79a80482003-05-14 17:13:13 +00002657
2658 for (i = 1; i < cf->args->nelts; i++) {
Igor Sysoev79a80482003-05-14 17:13:13 +00002659
Igor Sysoev6a078332008-08-04 10:18:36 +00002660 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
Igor Sysoev24025022005-12-16 15:07:08 +00002661
2662 type = lcf->types->elts;
2663 for (n = 0; n < lcf->types->nelts; n++) {
2664 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
2665 old = type[n].value;
2666 type[n].value = content_type;
2667
2668 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2669 "duplicate extention \"%V\", "
2670 "content type: \"%V\", "
2671 "old content type: \"%V\"",
2672 &value[i], content_type, old);
2673 continue;
2674 }
2675 }
2676
2677
2678 type = ngx_array_push(lcf->types);
Igor Sysoevc1571722005-03-19 12:38:37 +00002679 if (type == NULL) {
Igor Sysoevdc3b2a72004-09-14 19:39:54 +00002680 return NGX_CONF_ERROR;
2681 }
2682
Igor Sysoev24025022005-12-16 15:07:08 +00002683 type->key = value[i];
Igor Sysoev6a078332008-08-04 10:18:36 +00002684 type->key_hash = hash;
Igor Sysoev24025022005-12-16 15:07:08 +00002685 type->value = content_type;
Igor Sysoev79a80482003-05-14 17:13:13 +00002686 }
2687
2688 return NGX_CONF_OK;
2689}
2690
2691
Igor Sysoev899b44e2005-05-12 14:58:06 +00002692static ngx_int_t
2693ngx_http_core_preconfiguration(ngx_conf_t *cf)
2694{
2695 return ngx_http_variables_add_core_vars(cf);
2696}
2697
2698
Igor Sysoevaa828612005-02-09 14:31:07 +00002699static void *
2700ngx_http_core_create_main_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002701{
Igor Sysoev805d9db2005-02-03 19:33:37 +00002702 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002703
Igor Sysoevc1571722005-03-19 12:38:37 +00002704 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
2705 if (cmcf == NULL) {
Igor Sysoev805d9db2005-02-03 19:33:37 +00002706 return NGX_CONF_ERROR;
2707 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002708
Igor Sysoev8184d1b2005-03-04 14:06:57 +00002709 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002710 sizeof(ngx_http_core_srv_conf_t *))
Igor Sysoev6f134cc2006-05-23 14:54:58 +00002711 != NGX_OK)
Igor Sysoev805d9db2005-02-03 19:33:37 +00002712 {
2713 return NGX_CONF_ERROR;
2714 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002715
Igor Sysoev305a9d82005-12-26 17:07:48 +00002716 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
2717 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002718
Igor Sysoevffe71442006-02-08 15:33:12 +00002719 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
2720 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
2721
Igor Sysoeva9830112003-05-19 16:39:14 +00002722 return cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002723}
2724
2725
Igor Sysoevaa828612005-02-09 14:31:07 +00002726static char *
2727ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002728{
Igor Sysoev6253ca12003-05-27 12:18:54 +00002729 ngx_http_core_main_conf_t *cmcf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00002730
Igor Sysoev305a9d82005-12-26 17:07:48 +00002731 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
2732 cmcf->server_names_hash_max_size = 512;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002733 }
2734
Igor Sysoev305a9d82005-12-26 17:07:48 +00002735 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2736 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002737 }
Igor Sysoeva9830112003-05-19 16:39:14 +00002738
Igor Sysoev305a9d82005-12-26 17:07:48 +00002739 cmcf->server_names_hash_bucket_size =
2740 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
2741
Igor Sysoevffe71442006-02-08 15:33:12 +00002742
2743 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
2744 cmcf->variables_hash_max_size = 512;
2745 }
2746
2747 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2748 cmcf->variables_hash_bucket_size = 64;
2749 }
2750
2751 cmcf->variables_hash_bucket_size =
2752 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
2753
Igor Sysoeva9830112003-05-19 16:39:14 +00002754 return NGX_CONF_OK;
2755}
2756
2757
Igor Sysoevaa828612005-02-09 14:31:07 +00002758static void *
2759ngx_http_core_create_srv_conf(ngx_conf_t *cf)
Igor Sysoeva9830112003-05-19 16:39:14 +00002760{
2761 ngx_http_core_srv_conf_t *cscf;
2762
Igor Sysoevc1571722005-03-19 12:38:37 +00002763 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
2764 if (cscf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002765 return NGX_CONF_ERROR;
2766 }
2767
Igor Sysoev85080d02004-09-22 16:18:21 +00002768 /*
Igor Sysoev02025fd2005-01-18 13:03:58 +00002769 * set by ngx_pcalloc():
Igor Sysoevaa828612005-02-09 14:31:07 +00002770 *
Igor Sysoev02025fd2005-01-18 13:03:58 +00002771 * conf->client_large_buffers.num = 0;
2772 */
Igor Sysoev85080d02004-09-22 16:18:21 +00002773
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002774 if (ngx_array_init(&cscf->listen, cf->temp_pool, 4,
2775 sizeof(ngx_http_listen_t))
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002776 != NGX_OK)
Igor Sysoevaa828612005-02-09 14:31:07 +00002777 {
2778 return NGX_CONF_ERROR;
2779 }
2780
Igor Sysoevda173ab2006-08-30 10:39:17 +00002781 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
Igor Sysoev305a9d82005-12-26 17:07:48 +00002782 sizeof(ngx_http_server_name_t))
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002783 != NGX_OK)
Igor Sysoevaa828612005-02-09 14:31:07 +00002784 {
2785 return NGX_CONF_ERROR;
2786 }
Igor Sysoeva9830112003-05-19 16:39:14 +00002787
Igor Sysoev10a543a2004-03-16 07:10:12 +00002788 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002789 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
2790 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
2791 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev3362b8d2005-05-14 18:42:03 +00002792 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
Igor Sysoev8decab32007-10-18 11:36:58 +00002793 cscf->merge_slashes = NGX_CONF_UNSET;
Igor Sysoev753792e2008-09-24 14:02:50 +00002794 cscf->underscores_in_headers = NGX_CONF_UNSET;
Igor Sysoev187fcd82003-05-23 11:53:01 +00002795
Igor Sysoeva9830112003-05-19 16:39:14 +00002796 return cscf;
2797}
2798
2799
Igor Sysoevaa828612005-02-09 14:31:07 +00002800static char *
2801ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeva9830112003-05-19 16:39:14 +00002802{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002803 ngx_http_core_srv_conf_t *prev = parent;
2804 ngx_http_core_srv_conf_t *conf = child;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002805
Igor Sysoev305a9d82005-12-26 17:07:48 +00002806 ngx_http_listen_t *ls;
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002807 struct sockaddr_in *sin;
Igor Sysoev305a9d82005-12-26 17:07:48 +00002808 ngx_http_server_name_t *sn;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002809
Igor Sysoev7578ec92003-06-02 15:24:30 +00002810 /* TODO: it does not merge, it inits only */
Igor Sysoeva9830112003-05-19 16:39:14 +00002811
2812 if (conf->listen.nelts == 0) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002813 ls = ngx_array_push(&conf->listen);
2814 if (ls == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002815 return NGX_CONF_ERROR;
2816 }
2817
Igor Sysoevb145b062005-06-15 18:33:41 +00002818 ngx_memzero(ls, sizeof(ngx_http_listen_t));
2819
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002820 sin = (struct sockaddr_in *) &ls->sockaddr;
2821
2822 sin->sin_family = AF_INET;
Igor Sysoev1b735832004-11-11 14:07:14 +00002823#if (NGX_WIN32)
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002824 sin->sin_port = htons(80);
Igor Sysoev1c104622003-06-03 15:42:58 +00002825#else
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002826 sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
Igor Sysoev1c104622003-06-03 15:42:58 +00002827#endif
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002828 sin->sin_addr.s_addr = INADDR_ANY;
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002829
Igor Sysoeve10385e2009-02-21 10:23:30 +00002830 ls->socklen = sizeof(struct sockaddr_in);
2831
Igor Sysoev031a6e22007-08-09 13:32:21 +00002832 ls->conf.backlog = NGX_LISTEN_BACKLOG;
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002833 ls->conf.rcvbuf = -1;
2834 ls->conf.sndbuf = -1;
Igor Sysoeve10385e2009-02-21 10:23:30 +00002835 ls->conf.wildcard = 1;
2836
2837 (void) ngx_sock_ntop((struct sockaddr *) &ls->sockaddr, ls->conf.addr,
2838 NGX_SOCKADDR_STRLEN, 1);
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002839 }
2840
Igor Sysoev9e580192006-02-01 18:22:15 +00002841 if (conf->server_name.data == NULL) {
Igor Sysoev3be52572008-05-16 14:39:06 +00002842 conf->server_name = cf->cycle->hostname;
Igor Sysoev9e580192006-02-01 18:22:15 +00002843
2844 sn = ngx_array_push(&conf->server_names);
2845 if (sn == NULL) {
2846 return NGX_CONF_ERROR;
2847 }
2848
Igor Sysoev12446d82007-10-17 13:22:26 +00002849#if (NGX_PCRE)
2850 sn->regex = NULL;
Igor Sysoev7ac9f362009-03-06 12:50:20 +00002851 sn->captures = 0;
Igor Sysoev12446d82007-10-17 13:22:26 +00002852#endif
2853 sn->core_srv_conf = conf;
Igor Sysoev9e580192006-02-01 18:22:15 +00002854 sn->name.len = conf->server_name.len;
2855 sn->name.data = conf->server_name.data;
Igor Sysoevad22e012003-01-15 07:02:27 +00002856 }
2857
Igor Sysoev239baac2003-06-11 15:28:34 +00002858 ngx_conf_merge_size_value(conf->connection_pool_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00002859 prev->connection_pool_size, 256);
Igor Sysoev187fcd82003-05-23 11:53:01 +00002860 ngx_conf_merge_size_value(conf->request_pool_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00002861 prev->request_pool_size, 4096);
Igor Sysoev187fcd82003-05-23 11:53:01 +00002862 ngx_conf_merge_msec_value(conf->client_header_timeout,
2863 prev->client_header_timeout, 60000);
2864 ngx_conf_merge_size_value(conf->client_header_buffer_size,
2865 prev->client_header_buffer_size, 1024);
Igor Sysoevf7abd722004-09-23 06:32:00 +00002866 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
2867 prev->large_client_header_buffers,
2868 4, ngx_pagesize);
2869
2870 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
2871 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2872 "the \"large_client_header_buffers\" size must be "
2873 "equal to or bigger than \"connection_pool_size\"");
2874 return NGX_CONF_ERROR;
2875 }
2876
Igor Sysoev3362b8d2005-05-14 18:42:03 +00002877 ngx_conf_merge_value(conf->ignore_invalid_headers,
2878 prev->ignore_invalid_headers, 1);
2879
Igor Sysoev8decab32007-10-18 11:36:58 +00002880 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
2881
Igor Sysoev753792e2008-09-24 14:02:50 +00002882 ngx_conf_merge_value(conf->underscores_in_headers,
2883 prev->underscores_in_headers, 0);
2884
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002885 return NGX_CONF_OK;
2886}
2887
2888
Igor Sysoevaa828612005-02-09 14:31:07 +00002889static void *
2890ngx_http_core_create_loc_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002891{
Igor Sysoev805d9db2005-02-03 19:33:37 +00002892 ngx_http_core_loc_conf_t *lcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002893
Igor Sysoevc1571722005-03-19 12:38:37 +00002894 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
2895 if (lcf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002896 return NGX_CONF_ERROR;
2897 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002898
Igor Sysoev02025fd2005-01-18 13:03:58 +00002899 /*
2900 * set by ngx_pcalloc():
2901 *
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002902 * lcf->root = { 0, NULL };
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002903 * lcf->limit_except = 0;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002904 * lcf->post_action = { 0, NULL };
Igor Sysoev02025fd2005-01-18 13:03:58 +00002905 * lcf->types = NULL;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002906 * lcf->default_type = { 0, NULL };
Igor Sysoev02025fd2005-01-18 13:03:58 +00002907 * lcf->err_log = NULL;
2908 * lcf->error_pages = NULL;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00002909 * lcf->try_files = NULL;
Igor Sysoev02025fd2005-01-18 13:03:58 +00002910 * lcf->client_body_path = NULL;
2911 * lcf->regex = NULL;
2912 * lcf->exact_match = 0;
2913 * lcf->auto_redirect = 0;
2914 * lcf->alias = 0;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002915 * lcf->gzip_proxied = 0;
Igor Sysoev02025fd2005-01-18 13:03:58 +00002916 */
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002917
Igor Sysoev1765f472006-07-07 16:33:19 +00002918 lcf->client_max_body_size = NGX_CONF_UNSET;
Igor Sysoevdbb27762004-04-01 16:20:53 +00002919 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002920 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev6d7f8652007-12-29 21:43:49 +00002921 lcf->satisfy = NGX_CONF_UNSET_UINT;
Igor Sysoev863325f2008-12-01 14:22:51 +00002922 lcf->if_modified_since = NGX_CONF_UNSET_UINT;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002923 lcf->internal = NGX_CONF_UNSET;
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00002924 lcf->client_body_in_file_only = NGX_CONF_UNSET;
Igor Sysoev5bf3d252003-10-22 07:05:29 +00002925 lcf->sendfile = NGX_CONF_UNSET;
Igor Sysoevc9b57dc2007-05-07 06:33:39 +00002926 lcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
Igor Sysoev385af282008-07-30 12:34:04 +00002927 lcf->directio = NGX_CONF_UNSET;
Igor Sysoev3c3ca172004-01-05 20:55:48 +00002928 lcf->tcp_nopush = NGX_CONF_UNSET;
Igor Sysoev924bd792004-10-11 15:07:03 +00002929 lcf->tcp_nodelay = NGX_CONF_UNSET;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002930 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
2931 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
Igor Sysoev7823cc32004-07-14 16:01:42 +00002932 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
2933 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002934 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002935 lcf->keepalive_header = NGX_CONF_UNSET;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002936 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
2937 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev13f5ff92007-11-27 11:33:52 +00002938 lcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev0ab91b92004-06-06 19:49:18 +00002939 lcf->reset_timedout_connection = NGX_CONF_UNSET;
Igor Sysoev3f24ae22007-12-29 15:30:39 +00002940 lcf->server_name_in_redirect = NGX_CONF_UNSET;
Igor Sysoev7b190b42005-06-07 15:56:31 +00002941 lcf->port_in_redirect = NGX_CONF_UNSET;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002942 lcf->msie_padding = NGX_CONF_UNSET;
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002943 lcf->msie_refresh = NGX_CONF_UNSET;
Igor Sysoev5192b362005-07-08 14:34:20 +00002944 lcf->log_not_found = NGX_CONF_UNSET;
Igor Sysoev2eec1e12008-09-27 15:08:02 +00002945 lcf->log_subrequest = NGX_CONF_UNSET;
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002946 lcf->recursive_error_pages = NGX_CONF_UNSET;
Igor Sysoev070cf222007-10-22 10:17:34 +00002947 lcf->server_tokens = NGX_CONF_UNSET;
Igor Sysoev24025022005-12-16 15:07:08 +00002948 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
2949 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002950
Igor Sysoev140c7552007-09-01 12:12:48 +00002951 lcf->open_file_cache = NGX_CONF_UNSET_PTR;
Igor Sysoev9b9616e2007-12-21 16:19:48 +00002952 lcf->open_file_cache_valid = NGX_CONF_UNSET;
Igor Sysoevf3b0e492007-12-22 13:19:39 +00002953 lcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
Igor Sysoev140c7552007-09-01 12:12:48 +00002954 lcf->open_file_cache_errors = NGX_CONF_UNSET;
Igor Sysoev9afd58f2007-09-03 08:41:42 +00002955 lcf->open_file_cache_events = NGX_CONF_UNSET;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002956
Igor Sysoevc16b0052007-12-27 14:21:59 +00002957#if (NGX_HTTP_GZIP)
2958 lcf->gzip_vary = NGX_CONF_UNSET;
2959 lcf->gzip_http_version = NGX_CONF_UNSET_UINT;
Igor Sysoev8eac7262007-12-28 13:15:11 +00002960#if (NGX_PCRE)
Igor Sysoevc16b0052007-12-27 14:21:59 +00002961 lcf->gzip_disable = NGX_CONF_UNSET_PTR;
Igor Sysoev54477e42008-08-26 15:09:28 +00002962 lcf->gzip_disable_msie6 = 3;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002963#endif
Igor Sysoev8eac7262007-12-28 13:15:11 +00002964#endif
Igor Sysoevc16b0052007-12-27 14:21:59 +00002965
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002966 return lcf;
2967}
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002968
Igor Sysoev79a80482003-05-14 17:13:13 +00002969
Igor Sysoev24025022005-12-16 15:07:08 +00002970static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
2971static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
2972static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
2973
2974static ngx_hash_key_t ngx_http_core_default_types[] = {
2975 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
2976 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
2977 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
2978 { ngx_null_string, 0, NULL }
Igor Sysoev79a80482003-05-14 17:13:13 +00002979};
2980
2981
Igor Sysoevaa828612005-02-09 14:31:07 +00002982static char *
Igor Sysoev24025022005-12-16 15:07:08 +00002983ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeve2a31542003-04-08 15:40:10 +00002984{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002985 ngx_http_core_loc_conf_t *prev = parent;
2986 ngx_http_core_loc_conf_t *conf = child;
Igor Sysoev79a80482003-05-14 17:13:13 +00002987
Igor Sysoevaa828612005-02-09 14:31:07 +00002988 ngx_uint_t i;
Igor Sysoev24025022005-12-16 15:07:08 +00002989 ngx_hash_key_t *type;
2990 ngx_hash_init_t types_hash;
Igor Sysoev79a80482003-05-14 17:13:13 +00002991
Igor Sysoev34303462006-01-24 16:08:27 +00002992 if (conf->root.data == NULL) {
Igor Sysoev79a80482003-05-14 17:13:13 +00002993
Igor Sysoev455a7fc2006-03-21 08:20:41 +00002994 conf->alias = prev->alias;
Igor Sysoev34303462006-01-24 16:08:27 +00002995 conf->root = prev->root;
2996 conf->root_lengths = prev->root_lengths;
2997 conf->root_values = prev->root_values;
2998
2999 if (prev->root.data == NULL) {
3000 conf->root.len = sizeof("html") - 1;
3001 conf->root.data = (u_char *) "html";
3002
Igor Sysoev1f4220e2009-02-24 10:42:23 +00003003 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
Igor Sysoev34303462006-01-24 16:08:27 +00003004 return NGX_CONF_ERROR;
3005 }
3006 }
Igor Sysoev6d2a14a2004-09-27 16:03:21 +00003007 }
3008
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003009 if (conf->post_action.data == NULL) {
3010 conf->post_action = prev->post_action;
3011 }
3012
Igor Sysoev1765f472006-07-07 16:33:19 +00003013 ngx_conf_merge_uint_value(conf->types_hash_max_size,
3014 prev->types_hash_max_size, 1024);
Igor Sysoev79a80482003-05-14 17:13:13 +00003015
Igor Sysoev1765f472006-07-07 16:33:19 +00003016 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
3017 prev->types_hash_bucket_size,
3018 ngx_cacheline_size);
Igor Sysoev24025022005-12-16 15:07:08 +00003019
3020 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
3021 ngx_cacheline_size);
3022
3023 /*
3024 * the special handling the "types" directive in the "http" section
3025 * to inherit the http's conf->types_hash to all servers
3026 */
3027
3028 if (prev->types && prev->types_hash.buckets == NULL) {
3029
3030 types_hash.hash = &prev->types_hash;
3031 types_hash.key = ngx_hash_key_lc;
3032 types_hash.max_size = conf->types_hash_max_size;
3033 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003034 types_hash.name = "types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00003035 types_hash.pool = cf->pool;
3036 types_hash.temp_pool = NULL;
3037
3038 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
3039 != NGX_OK)
3040 {
3041 return NGX_CONF_ERROR;
3042 }
3043 }
3044
3045 if (conf->types == NULL) {
3046 conf->types = prev->types;
3047 conf->types_hash = prev->types_hash;
3048 }
3049
3050 if (conf->types == NULL) {
3051 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
3052 if (conf->types == NULL) {
3053 return NGX_CONF_ERROR;
3054 }
3055
3056 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
3057 type = ngx_array_push(conf->types);
3058 if (type == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00003059 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00003060 }
3061
Igor Sysoev24025022005-12-16 15:07:08 +00003062 type->key = ngx_http_core_default_types[i].key;
3063 type->key_hash =
3064 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
3065 ngx_http_core_default_types[i].key.len);
3066 type->value = ngx_http_core_default_types[i].value;
3067 }
3068 }
Igor Sysoev79a80482003-05-14 17:13:13 +00003069
Igor Sysoev24025022005-12-16 15:07:08 +00003070 if (conf->types_hash.buckets == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00003071
Igor Sysoev24025022005-12-16 15:07:08 +00003072 types_hash.hash = &conf->types_hash;
3073 types_hash.key = ngx_hash_key_lc;
3074 types_hash.max_size = conf->types_hash_max_size;
3075 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003076 types_hash.name = "mime_types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00003077 types_hash.pool = cf->pool;
3078 types_hash.temp_pool = NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00003079
Igor Sysoev24025022005-12-16 15:07:08 +00003080 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
3081 != NGX_OK)
3082 {
3083 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00003084 }
3085 }
3086
Igor Sysoev890fc962003-07-20 21:15:59 +00003087 if (conf->err_log == NULL) {
3088 if (prev->err_log) {
3089 conf->err_log = prev->err_log;
3090 } else {
Igor Sysoev630ad0c2004-04-16 05:14:16 +00003091 conf->err_log = cf->cycle->new_log;
Igor Sysoev890fc962003-07-20 21:15:59 +00003092 }
3093 }
3094
Igor Sysoev74e95c22003-11-09 20:03:38 +00003095 if (conf->error_pages == NULL && prev->error_pages) {
3096 conf->error_pages = prev->error_pages;
3097 }
3098
Igor Sysoev6253ca12003-05-27 12:18:54 +00003099 ngx_conf_merge_str_value(conf->default_type,
Igor Sysoevaa828612005-02-09 14:31:07 +00003100 prev->default_type, "text/plain");
Igor Sysoev6253ca12003-05-27 12:18:54 +00003101
Igor Sysoev1765f472006-07-07 16:33:19 +00003102 ngx_conf_merge_off_value(conf->client_max_body_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00003103 prev->client_max_body_size, 1 * 1024 * 1024);
Igor Sysoevdbb27762004-04-01 16:20:53 +00003104 ngx_conf_merge_size_value(conf->client_body_buffer_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00003105 prev->client_body_buffer_size,
3106 (size_t) 2 * ngx_pagesize);
Igor Sysoev2b0c76c2003-10-27 21:01:00 +00003107 ngx_conf_merge_msec_value(conf->client_body_timeout,
Igor Sysoev7af6b162004-02-09 07:46:43 +00003108 prev->client_body_timeout, 60000);
Igor Sysoev899b44e2005-05-12 14:58:06 +00003109
Igor Sysoev2d028f82007-12-29 16:38:23 +00003110 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
3111 NGX_HTTP_SATISFY_ALL);
Igor Sysoev863325f2008-12-01 14:22:51 +00003112 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
Igor Sysoev2c336482009-02-10 15:05:05 +00003113 NGX_HTTP_IMS_EXACT);
Igor Sysoev899b44e2005-05-12 14:58:06 +00003114 ngx_conf_merge_value(conf->internal, prev->internal, 0);
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00003115 ngx_conf_merge_value(conf->client_body_in_file_only,
3116 prev->client_body_in_file_only, 0);
Igor Sysoev5bf3d252003-10-22 07:05:29 +00003117 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
Igor Sysoevc9b57dc2007-05-07 06:33:39 +00003118 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
3119 prev->sendfile_max_chunk, 0);
Igor Sysoev385af282008-07-30 12:34:04 +00003120 ngx_conf_merge_off_value(conf->directio, prev->directio,
3121 NGX_MAX_OFF_T_VALUE);
Igor Sysoev3c3ca172004-01-05 20:55:48 +00003122 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003123 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
Igor Sysoev899b44e2005-05-12 14:58:06 +00003124
Igor Sysoev7af6b162004-02-09 07:46:43 +00003125 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
Igor Sysoevb5faed22003-10-29 08:30:44 +00003126 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
Igor Sysoev7823cc32004-07-14 16:01:42 +00003127 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
3128 1460);
3129 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00003130 ngx_conf_merge_msec_value(conf->keepalive_timeout,
Igor Sysoev307c3ad2004-09-17 16:07:35 +00003131 prev->keepalive_timeout, 75000);
3132 ngx_conf_merge_sec_value(conf->keepalive_header,
3133 prev->keepalive_header, 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00003134 ngx_conf_merge_msec_value(conf->lingering_time,
3135 prev->lingering_time, 30000);
3136 ngx_conf_merge_msec_value(conf->lingering_timeout,
3137 prev->lingering_timeout, 5000);
Igor Sysoev13f5ff92007-11-27 11:33:52 +00003138 ngx_conf_merge_msec_value(conf->resolver_timeout,
3139 prev->resolver_timeout, 30000);
3140
3141 if (conf->resolver == NULL) {
Igor Sysoev6b2fce42007-12-03 10:05:19 +00003142
Igor Sysoevf39876c2008-03-06 08:48:55 +00003143 if (prev->resolver == NULL) {
3144
3145 /*
3146 * create dummy resolver in http {} context
3147 * to inherit it in all servers
3148 */
3149
3150 prev->resolver = ngx_resolver_create(cf, NULL);
3151 if (prev->resolver == NULL) {
Igor Sysoevd2d673a2008-02-07 08:57:07 +00003152 return NGX_CONF_ERROR;
Igor Sysoev6b2fce42007-12-03 10:05:19 +00003153 }
3154 }
Igor Sysoev433608c2008-05-14 07:54:52 +00003155
Igor Sysoevf39876c2008-03-06 08:48:55 +00003156 conf->resolver = prev->resolver;
Igor Sysoev13f5ff92007-11-27 11:33:52 +00003157 }
Igor Sysoev79a80482003-05-14 17:13:13 +00003158
Igor Sysoev02025fd2005-01-18 13:03:58 +00003159 ngx_conf_merge_path_value(conf->client_body_temp_path,
3160 prev->client_body_temp_path,
3161 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
3162 ngx_garbage_collector_temp_handler, cf);
3163
Igor Sysoev0ab91b92004-06-06 19:49:18 +00003164 ngx_conf_merge_value(conf->reset_timedout_connection,
Igor Sysoevaa828612005-02-09 14:31:07 +00003165 prev->reset_timedout_connection, 0);
Igor Sysoev3f24ae22007-12-29 15:30:39 +00003166 ngx_conf_merge_value(conf->server_name_in_redirect,
3167 prev->server_name_in_redirect, 1);
Igor Sysoev7b190b42005-06-07 15:56:31 +00003168 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00003169 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003170 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
Igor Sysoev5192b362005-07-08 14:34:20 +00003171 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
Igor Sysoev2eec1e12008-09-27 15:08:02 +00003172 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003173 ngx_conf_merge_value(conf->recursive_error_pages,
3174 prev->recursive_error_pages, 0);
Igor Sysoev070cf222007-10-22 10:17:34 +00003175 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00003176
Igor Sysoev140c7552007-09-01 12:12:48 +00003177 ngx_conf_merge_ptr_value(conf->open_file_cache,
Igor Sysoev513fec72007-12-27 08:40:14 +00003178 prev->open_file_cache, NULL);
Igor Sysoev140c7552007-09-01 12:12:48 +00003179
Igor Sysoev9b9616e2007-12-21 16:19:48 +00003180 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
Igor Sysoev513fec72007-12-27 08:40:14 +00003181 prev->open_file_cache_valid, 60);
Igor Sysoev140c7552007-09-01 12:12:48 +00003182
Igor Sysoevf3b0e492007-12-22 13:19:39 +00003183 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
Igor Sysoev513fec72007-12-27 08:40:14 +00003184 prev->open_file_cache_min_uses, 1);
Igor Sysoevf3b0e492007-12-22 13:19:39 +00003185
Igor Sysoev140c7552007-09-01 12:12:48 +00003186 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
Igor Sysoev513fec72007-12-27 08:40:14 +00003187 prev->open_file_cache_errors, 0);
Igor Sysoev865c1502003-11-30 20:03:18 +00003188
Igor Sysoev9afd58f2007-09-03 08:41:42 +00003189 ngx_conf_merge_sec_value(conf->open_file_cache_events,
Igor Sysoev513fec72007-12-27 08:40:14 +00003190 prev->open_file_cache_events, 0);
Igor Sysoevc16b0052007-12-27 14:21:59 +00003191#if (NGX_HTTP_GZIP)
3192
3193 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
3194 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
3195 NGX_HTTP_VERSION_11);
3196 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
3197 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
3198
Igor Sysoev8eac7262007-12-28 13:15:11 +00003199#if (NGX_PCRE)
Igor Sysoevc16b0052007-12-27 14:21:59 +00003200 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
Igor Sysoev8eac7262007-12-28 13:15:11 +00003201#endif
Igor Sysoevc16b0052007-12-27 14:21:59 +00003202
Igor Sysoev54477e42008-08-26 15:09:28 +00003203 if (conf->gzip_disable_msie6 == 3) {
3204 conf->gzip_disable_msie6 =
3205 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
3206 }
3207
Igor Sysoevc16b0052007-12-27 14:21:59 +00003208#endif
Igor Sysoev9afd58f2007-09-03 08:41:42 +00003209
Igor Sysoeve2a31542003-04-08 15:40:10 +00003210 return NGX_CONF_OK;
3211}
3212
Igor Sysoev79a80482003-05-14 17:13:13 +00003213
Igor Sysoevaa828612005-02-09 14:31:07 +00003214static char *
3215ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003216{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003217 ngx_http_core_srv_conf_t *scf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00003218
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003219 ngx_str_t *value, size;
3220 ngx_url_t u;
3221 ngx_uint_t n;
3222 ngx_http_listen_t *ls;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003223
Igor Sysoeve2ff3ea2004-09-14 15:55:24 +00003224 /*
3225 * TODO: check duplicate 'listen' directives,
3226 * add resolved name to server names ???
3227 */
Igor Sysoev6ddfbf02003-05-15 15:42:53 +00003228
Igor Sysoevb145b062005-06-15 18:33:41 +00003229 value = cf->args->elts;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003230
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003231 ngx_memzero(&u, sizeof(ngx_url_t));
Igor Sysoevb145b062005-06-15 18:33:41 +00003232
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003233 u.url = value[1];
3234 u.listen = 1;
Igor Sysoevbf3aaac2006-12-12 16:46:16 +00003235 u.default_port = 80;
Igor Sysoevb145b062005-06-15 18:33:41 +00003236
Igor Sysoev7ed63ee2007-10-08 08:55:12 +00003237 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003238 if (u.err) {
3239 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3240 "%s in \"%V\" of the \"listen\" directive",
3241 u.err, &u.url);
3242 }
Igor Sysoevb145b062005-06-15 18:33:41 +00003243
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003244 return NGX_CONF_ERROR;
Igor Sysoevb145b062005-06-15 18:33:41 +00003245 }
3246
Igor Sysoevc1571722005-03-19 12:38:37 +00003247 ls = ngx_array_push(&scf->listen);
3248 if (ls == NULL) {
Igor Sysoeve2ff3ea2004-09-14 15:55:24 +00003249 return NGX_CONF_ERROR;
3250 }
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003251
Igor Sysoevb145b062005-06-15 18:33:41 +00003252 ngx_memzero(ls, sizeof(ngx_http_listen_t));
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003253
Igor Sysoeva35eacc2009-02-21 07:02:02 +00003254 ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen);
3255
3256 ls->socklen = u.socklen;
Igor Sysoev4b96baa2007-09-15 17:11:06 +00003257 ls->file_name = cf->conf_file->file.name.data;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003258 ls->line = cf->conf_file->line;
Igor Sysoev031a6e22007-08-09 13:32:21 +00003259 ls->conf.backlog = NGX_LISTEN_BACKLOG;
Igor Sysoevc2068d02005-10-19 12:33:58 +00003260 ls->conf.rcvbuf = -1;
3261 ls->conf.sndbuf = -1;
Igor Sysoeva35eacc2009-02-21 07:02:02 +00003262 ls->conf.wildcard = u.wildcard;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003263
Igor Sysoeva35eacc2009-02-21 07:02:02 +00003264 (void) ngx_sock_ntop((struct sockaddr *) &ls->sockaddr, ls->conf.addr,
3265 NGX_SOCKADDR_STRLEN, 1);
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003266
Igor Sysoevb145b062005-06-15 18:33:41 +00003267 if (cf->args->nelts == 2) {
3268 return NGX_CONF_OK;
3269 }
Igor Sysoevaa828612005-02-09 14:31:07 +00003270
Igor Sysoevb145b062005-06-15 18:33:41 +00003271 if (ngx_strcmp(value[2].data, "default") == 0) {
3272 ls->conf.default_server = 1;
3273 n = 3;
Igor Sysoev24025022005-12-16 15:07:08 +00003274
Igor Sysoevb145b062005-06-15 18:33:41 +00003275 } else {
3276 n = 2;
3277 }
Igor Sysoev13933252003-05-29 13:02:09 +00003278
Igor Sysoevb145b062005-06-15 18:33:41 +00003279 for ( /* void */ ; n < cf->args->nelts; n++) {
3280
3281 if (ls->conf.default_server == 0) {
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00003282 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoevb145b062005-06-15 18:33:41 +00003283 "\"%V\" parameter can be specified for "
3284 "the default \"listen\" directive only",
3285 &value[n]);
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00003286 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00003287 }
3288
Igor Sysoevb145b062005-06-15 18:33:41 +00003289 if (ngx_strcmp(value[n].data, "bind") == 0) {
3290 ls->conf.bind = 1;
3291 continue;
3292 }
3293
Igor Sysoevc2068d02005-10-19 12:33:58 +00003294 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
3295 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
Igor Sysoevb145b062005-06-15 18:33:41 +00003296 ls->conf.bind = 1;
3297
3298 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
3299 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3300 "invalid backlog \"%V\"", &value[n]);
3301 return NGX_CONF_ERROR;
3302 }
3303
3304 continue;
3305 }
3306
Igor Sysoevc2068d02005-10-19 12:33:58 +00003307 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
3308 size.len = value[n].len - 7;
3309 size.data = value[n].data + 7;
3310
3311 ls->conf.rcvbuf = ngx_parse_size(&size);
3312 ls->conf.bind = 1;
3313
3314 if (ls->conf.rcvbuf == NGX_ERROR) {
3315 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3316 "invalid rcvbuf \"%V\"", &value[n]);
3317 return NGX_CONF_ERROR;
3318 }
3319
3320 continue;
3321 }
3322
3323 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
3324 size.len = value[n].len - 7;
3325 size.data = value[n].data + 7;
3326
3327 ls->conf.sndbuf = ngx_parse_size(&size);
3328 ls->conf.bind = 1;
3329
3330 if (ls->conf.sndbuf == NGX_ERROR) {
3331 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3332 "invalid sndbuf \"%V\"", &value[n]);
3333 return NGX_CONF_ERROR;
3334 }
3335
3336 continue;
3337 }
3338
3339 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
Igor Sysoevb145b062005-06-15 18:33:41 +00003340#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
Igor Sysoevc2068d02005-10-19 12:33:58 +00003341 ls->conf.accept_filter = (char *) &value[n].data[14];
Igor Sysoevb145b062005-06-15 18:33:41 +00003342 ls->conf.bind = 1;
3343#else
3344 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3345 "accept filters \"%V\" are not supported "
3346 "on this platform, ignored",
3347 &value[n]);
3348#endif
3349 continue;
3350 }
3351
3352 if (ngx_strcmp(value[n].data, "deferred") == 0) {
3353#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3354 ls->conf.deferred_accept = 1;
3355 ls->conf.bind = 1;
3356#else
3357 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3358 "the deferred accept is not supported "
3359 "on this platform, ignored");
3360#endif
3361 continue;
3362 }
3363
Igor Sysoev6d94b512009-03-13 14:20:34 +00003364 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
3365#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3366 struct sockaddr *sa;
3367
3368 sa = (struct sockaddr *) ls->sockaddr;
3369
3370 if (sa->sa_family == AF_INET6) {
3371
3372 if (ngx_strcmp(&value[n].data[10], "n") == 0) {
3373 ls->conf.ipv6only = 1;
3374
3375 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
3376 ls->conf.ipv6only = 2;
3377
3378 } else {
3379 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3380 "invalid ipv6only flags \"%s\"",
3381 &value[n].data[9]);
3382 return NGX_CONF_ERROR;
3383 }
3384
3385 ls->conf.bind = 1;
3386
3387 } else {
3388 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3389 "ipv6only is not supported "
3390 "on addr \"%s\", ignored",
3391 ls->conf.addr);
3392 }
3393
3394 continue;
3395#else
3396 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3397 "bind ipv6only is not supported "
3398 "on this platform");
3399 return NGX_CONF_ERROR;
3400#endif
3401 }
3402
Igor Sysoevf100c782008-09-01 14:19:01 +00003403 if (ngx_strcmp(value[n].data, "ssl") == 0) {
3404#if (NGX_HTTP_SSL)
3405 ls->conf.ssl = 1;
3406 continue;
3407#else
3408 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3409 "the \"ssl\" parameter requires "
3410 "ngx_http_ssl_module");
3411 return NGX_CONF_ERROR;
3412#endif
3413 }
3414
Igor Sysoevb145b062005-06-15 18:33:41 +00003415 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3416 "the invalid \"%V\" parameter", &value[n]);
3417 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00003418 }
3419
3420 return NGX_CONF_OK;
3421}
3422
3423
Igor Sysoevaa828612005-02-09 14:31:07 +00003424static char *
3425ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev13933252003-05-29 13:02:09 +00003426{
Igor Sysoev305a9d82005-12-26 17:07:48 +00003427 ngx_http_core_srv_conf_t *cscf = conf;
Igor Sysoev13933252003-05-29 13:02:09 +00003428
Igor Sysoev305a9d82005-12-26 17:07:48 +00003429 u_char ch;
3430 ngx_str_t *value, name;
3431 ngx_uint_t i;
3432 ngx_http_server_name_t *sn;
Igor Sysoevb1af9bb2004-06-25 14:42:03 +00003433
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003434 value = cf->args->elts;
Igor Sysoev13933252003-05-29 13:02:09 +00003435
Igor Sysoev305a9d82005-12-26 17:07:48 +00003436 ch = value[1].data[0];
3437
Igor Sysoevb29426d2008-08-21 12:56:10 +00003438 if (cscf->server_name.data == NULL) {
3439 if (value[1].len) {
3440 name = value[1];
Igor Sysoev305a9d82005-12-26 17:07:48 +00003441
Igor Sysoevb29426d2008-08-21 12:56:10 +00003442 if (ch == '.') {
3443 name.len--;
3444 name.data++;
3445 }
Igor Sysoev305a9d82005-12-26 17:07:48 +00003446
Igor Sysoevb29426d2008-08-21 12:56:10 +00003447 cscf->server_name.len = name.len;
3448 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
3449 if (cscf->server_name.data == NULL) {
3450 return NGX_CONF_ERROR;
3451 }
3452
3453 } else {
3454 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3455 "the first server name must not be empty");
Igor Sysoev305a9d82005-12-26 17:07:48 +00003456 return NGX_CONF_ERROR;
3457 }
3458 }
3459
3460 for (i = 1; i < cf->args->nelts; i++) {
3461
3462 ch = value[i].data[0];
3463
Igor Sysoevb29426d2008-08-21 12:56:10 +00003464 if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
Igor Sysoev305a9d82005-12-26 17:07:48 +00003465 || (ch == '.' && value[i].len < 2))
3466 {
3467 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3468 "server name \"%V\" is invalid", &value[i]);
3469 return NGX_CONF_ERROR;
3470 }
3471
Igor Sysoev7a588602007-04-02 06:27:30 +00003472 if (ngx_strchr(value[i].data, '/')) {
3473 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
3474 "server name \"%V\" has strange symbols",
3475 &value[i]);
3476 }
3477
Igor Sysoevc24de1e2007-12-29 19:05:21 +00003478 if (value[i].len == 1 && ch == '*') {
3479 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3480 "\"server_name *\" is unsupported, use "
3481 "\"server_name_in_redirect off\" instead");
3482 return NGX_CONF_ERROR;
3483 }
3484
Igor Sysoev305a9d82005-12-26 17:07:48 +00003485 sn = ngx_array_push(&cscf->server_names);
Igor Sysoevc1571722005-03-19 12:38:37 +00003486 if (sn == NULL) {
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00003487 return NGX_CONF_ERROR;
3488 }
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003489
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003490#if (NGX_PCRE)
3491 sn->regex = NULL;
Igor Sysoev7ac9f362009-03-06 12:50:20 +00003492 sn->captures = 0;
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003493#endif
3494 sn->core_srv_conf = cscf;
Igor Sysoev99c3ab92007-12-27 09:17:20 +00003495 sn->name = value[i];
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003496
3497 if (value[i].data[0] != '~') {
3498 continue;
3499 }
3500
3501#if (NGX_PCRE)
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00003502 {
3503 ngx_str_t err;
3504 u_char errstr[NGX_MAX_CONF_ERRSTR];
3505
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003506 err.len = NGX_MAX_CONF_ERRSTR;
3507 err.data = errstr;
3508
3509 value[i].len--;
3510 value[i].data++;
3511
Igor Sysoev5fd09312008-05-15 14:44:47 +00003512 sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err);
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003513
3514 if (sn->regex == NULL) {
3515 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
3516 return NGX_CONF_ERROR;
3517 }
3518
Igor Sysoev7ac9f362009-03-06 12:50:20 +00003519 sn->captures = (ngx_regex_capture_count(sn->regex) > 0);
Igor Sysoev99c3ab92007-12-27 09:17:20 +00003520 sn->name = value[i];
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00003521 }
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003522#else
3523 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3524 "the using of the regex \"%V\" "
3525 "requires PCRE library", &value[i]);
3526
3527 return NGX_CONF_ERROR;
3528#endif
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003529 }
Igor Sysoev13933252003-05-29 13:02:09 +00003530
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003531 return NGX_CONF_OK;
3532}
Igor Sysoev9d639522003-07-07 06:11:50 +00003533
3534
Igor Sysoevaa828612005-02-09 14:31:07 +00003535static char *
3536ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev10a543a2004-03-16 07:10:12 +00003537{
3538 ngx_http_core_loc_conf_t *lcf = conf;
3539
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003540 ngx_str_t *value;
3541 ngx_uint_t alias, n;
3542 ngx_http_script_compile_t sc;
Igor Sysoev10a543a2004-03-16 07:10:12 +00003543
3544 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
3545
3546 if (lcf->root.data) {
Igor Sysoeva741f8d2004-03-30 20:31:58 +00003547
3548 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
3549
3550 if ((ngx_uint_t) lcf->alias == alias) {
Igor Sysoev10a543a2004-03-16 07:10:12 +00003551 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003552 "\"%V\" directive is duplicate",
3553 &cmd->name);
Igor Sysoev10a543a2004-03-16 07:10:12 +00003554 } else {
3555 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003556 "\"%V\" directive is duplicate, "
Igor Sysoev10a543a2004-03-16 07:10:12 +00003557 "\"%s\" directive is specified before",
Igor Sysoev1b735832004-11-11 14:07:14 +00003558 &cmd->name, lcf->alias ? "alias" : "root");
Igor Sysoev10a543a2004-03-16 07:10:12 +00003559 }
3560
3561 return NGX_CONF_ERROR;
3562 }
3563
Igor Sysoev8889b652007-07-29 18:11:39 +00003564 if (lcf->named && alias) {
3565 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3566 "the \"alias\" directive may not be used "
3567 "inside named location");
3568
3569 return NGX_CONF_ERROR;
3570 }
3571
Igor Sysoev10a543a2004-03-16 07:10:12 +00003572 value = cf->args->elts;
3573
Igor Sysoev10b98942007-04-02 05:43:21 +00003574 if (ngx_strstr(value[1].data, "$document_root")
3575 || ngx_strstr(value[1].data, "${document_root}"))
Igor Sysoevceab3692007-04-01 09:03:14 +00003576 {
3577 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3578 "the $document_root variable may not be used "
3579 "in the \"%V\" directive",
3580 &cmd->name);
3581
3582 return NGX_CONF_ERROR;
3583 }
3584
Igor Sysoev4ca2acf2008-09-29 04:47:22 +00003585 if (ngx_strstr(value[1].data, "$realpath_root")
3586 || ngx_strstr(value[1].data, "${realpath_root}"))
3587 {
3588 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3589 "the $realpath_root variable may not be used "
3590 "in the \"%V\" directive",
3591 &cmd->name);
3592
3593 return NGX_CONF_ERROR;
3594 }
3595
Igor Sysoev10a543a2004-03-16 07:10:12 +00003596 lcf->alias = alias;
3597 lcf->root = value[1];
3598
Igor Sysoev71057632004-08-30 19:24:51 +00003599 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
3600 lcf->root.len--;
3601 }
3602
Igor Sysoev8f125582006-07-28 15:16:17 +00003603 if (lcf->root.data[0] != '$') {
Igor Sysoev1f4220e2009-02-24 10:42:23 +00003604 if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) != NGX_OK) {
Igor Sysoev8f125582006-07-28 15:16:17 +00003605 return NGX_CONF_ERROR;
3606 }
Igor Sysoev34303462006-01-24 16:08:27 +00003607 }
3608
3609 n = ngx_http_script_variables_count(&lcf->root);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003610
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003611 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3612
Igor Sysoev925baa02009-03-06 12:49:22 +00003613 if (n) {
3614 sc.cf = cf;
3615 sc.source = &lcf->root;
3616 sc.lengths = &lcf->root_lengths;
3617 sc.values = &lcf->root_values;
3618 sc.variables = n;
3619 sc.complete_lengths = 1;
3620 sc.complete_values = 1;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003621
Igor Sysoev925baa02009-03-06 12:49:22 +00003622 if (ngx_http_script_compile(&sc) != NGX_OK) {
3623 return NGX_CONF_ERROR;
3624 }
3625 }
3626
3627#if (NGX_PCRE)
3628
3629 if (alias && lcf->regex
3630 && (ngx_regex_capture_count(lcf->regex) <= 0 || sc.ncaptures == 0))
3631 {
3632 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3633 "the \"alias\" directive must use captures "
3634 "inside location given by regular expression");
3635
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003636 return NGX_CONF_ERROR;
3637 }
3638
Igor Sysoev925baa02009-03-06 12:49:22 +00003639#endif
3640
Igor Sysoev10a543a2004-03-16 07:10:12 +00003641 return NGX_CONF_OK;
3642}
3643
3644
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003645static ngx_http_method_name_t ngx_methods_names[] = {
Igor Sysoev722231f2007-02-14 18:51:19 +00003646 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
3647 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
3648 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
3649 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
3650 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
3651 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
3652 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
3653 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
3654 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
3655 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
3656 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
3657 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
3658 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003659 { NULL, 0 }
3660};
3661
3662
3663static char *
3664ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3665{
Igor Sysoeve55988c2008-05-24 14:14:13 +00003666 ngx_http_core_loc_conf_t *pclcf = conf;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003667
3668 char *rv;
3669 void *mconf;
3670 ngx_str_t *value;
3671 ngx_uint_t i;
3672 ngx_conf_t save;
3673 ngx_http_module_t *module;
3674 ngx_http_conf_ctx_t *ctx, *pctx;
3675 ngx_http_method_name_t *name;
Igor Sysoeve55988c2008-05-24 14:14:13 +00003676 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003677
Igor Sysoeve55988c2008-05-24 14:14:13 +00003678 if (pclcf->limit_except) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003679 return "duplicate";
3680 }
3681
Igor Sysoeve55988c2008-05-24 14:14:13 +00003682 pclcf->limit_except = 0xffffffff;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003683
3684 value = cf->args->elts;
3685
3686 for (i = 1; i < cf->args->nelts; i++) {
3687 for (name = ngx_methods_names; name->name; name++) {
3688
3689 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
Igor Sysoeve55988c2008-05-24 14:14:13 +00003690 pclcf->limit_except &= name->method;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003691 goto next;
3692 }
3693 }
3694
3695 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3696 "invalid method \"%V\"", &value[i]);
3697 return NGX_CONF_ERROR;
3698
3699 next:
3700 continue;
3701 }
3702
Igor Sysoeve55988c2008-05-24 14:14:13 +00003703 if (!(pclcf->limit_except & NGX_HTTP_GET)) {
3704 pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003705 }
3706
3707 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
3708 if (ctx == NULL) {
3709 return NGX_CONF_ERROR;
3710 }
3711
3712 pctx = cf->ctx;
3713 ctx->main_conf = pctx->main_conf;
3714 ctx->srv_conf = pctx->srv_conf;
3715
3716 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
3717 if (ctx->loc_conf == NULL) {
3718 return NGX_CONF_ERROR;
3719 }
3720
3721 for (i = 0; ngx_modules[i]; i++) {
3722 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
3723 continue;
3724 }
3725
3726 module = ngx_modules[i]->ctx;
3727
3728 if (module->create_loc_conf) {
3729
3730 mconf = module->create_loc_conf(cf);
3731 if (mconf == NULL) {
3732 return NGX_CONF_ERROR;
3733 }
3734
3735 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
3736 }
3737 }
3738
3739
Igor Sysoeve55988c2008-05-24 14:14:13 +00003740 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
3741 pclcf->limit_except_loc_conf = ctx->loc_conf;
3742 clcf->loc_conf = ctx->loc_conf;
3743 clcf->name = pclcf->name;
3744 clcf->noname = 1;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003745
Igor Sysoeve55988c2008-05-24 14:14:13 +00003746 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003747 return NGX_CONF_ERROR;
3748 }
3749
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003750 save = *cf;
3751 cf->ctx = ctx;
3752 cf->cmd_type = NGX_HTTP_LMT_CONF;
3753
3754 rv = ngx_conf_parse(cf, NULL);
3755
3756 *cf = save;
3757
3758 return rv;
3759}
3760
3761
Igor Sysoevaa828612005-02-09 14:31:07 +00003762static char *
Igor Sysoev385af282008-07-30 12:34:04 +00003763ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3764{
3765 ngx_http_core_loc_conf_t *clcf = conf;
3766
3767 ngx_str_t *value;
3768
3769 if (clcf->directio != NGX_CONF_UNSET) {
3770 return "is duplicate";
3771 }
3772
3773 value = cf->args->elts;
3774
3775 if (ngx_strcmp(value[1].data, "off") == 0) {
Igor Sysoevad1e1232008-10-16 13:31:00 +00003776 clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
Igor Sysoev385af282008-07-30 12:34:04 +00003777 return NGX_CONF_OK;
3778 }
3779
3780 clcf->directio = ngx_parse_offset(&value[1]);
3781 if (clcf->directio == (off_t) NGX_ERROR) {
3782 return "invalid value";
3783 }
3784
3785 return NGX_CONF_OK;
3786}
3787
3788
3789static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00003790ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev74e95c22003-11-09 20:03:38 +00003791{
3792 ngx_http_core_loc_conf_t *lcf = conf;
3793
Igor Sysoev615fe7f2008-04-29 10:06:43 +00003794 u_char *args;
Igor Sysoev08e63d42006-08-14 15:09:38 +00003795 ngx_int_t overwrite;
3796 ngx_str_t *value, uri;
3797 ngx_uint_t i, n, nvar;
3798 ngx_array_t *uri_lengths, *uri_values;
3799 ngx_http_err_page_t *err;
3800 ngx_http_script_compile_t sc;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003801
3802 if (lcf->error_pages == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00003803 lcf->error_pages = ngx_array_create(cf->pool, 4,
Igor Sysoev74e95c22003-11-09 20:03:38 +00003804 sizeof(ngx_http_err_page_t));
3805 if (lcf->error_pages == NULL) {
3806 return NGX_CONF_ERROR;
3807 }
3808 }
3809
3810 value = cf->args->elts;
3811
Igor Sysoev732a2712004-04-21 18:54:33 +00003812 i = cf->args->nelts - 2;
3813
3814 if (value[i].data[0] == '=') {
3815 if (i == 1) {
3816 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003817 "invalid value \"%V\"", &value[i]);
Igor Sysoev732a2712004-04-21 18:54:33 +00003818 return NGX_CONF_ERROR;
3819 }
3820
Igor Sysoeva2573672005-10-05 14:46:21 +00003821 if (value[i].len > 1) {
3822 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
Igor Sysoev732a2712004-04-21 18:54:33 +00003823
Igor Sysoeva2573672005-10-05 14:46:21 +00003824 if (overwrite == NGX_ERROR) {
3825 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3826 "invalid value \"%V\"", &value[i]);
3827 return NGX_CONF_ERROR;
3828 }
3829
3830 } else {
3831 overwrite = 0;
Igor Sysoev732a2712004-04-21 18:54:33 +00003832 }
3833
3834 n = 2;
3835
3836 } else {
Igor Sysoeva2573672005-10-05 14:46:21 +00003837 overwrite = -1;
Igor Sysoev732a2712004-04-21 18:54:33 +00003838 n = 1;
3839 }
3840
Igor Sysoev08e63d42006-08-14 15:09:38 +00003841 uri = value[cf->args->nelts - 1];
3842 uri_lengths = NULL;
3843 uri_values = NULL;
3844
3845 nvar = ngx_http_script_variables_count(&uri);
3846
3847 if (nvar) {
3848 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3849
3850 sc.cf = cf;
3851 sc.source = &uri;
3852 sc.lengths = &uri_lengths;
3853 sc.values = &uri_values;
3854 sc.variables = nvar;
3855 sc.complete_lengths = 1;
3856 sc.complete_values = 1;
3857
3858 if (ngx_http_script_compile(&sc) != NGX_OK) {
3859 return NGX_CONF_ERROR;
3860 }
3861 }
3862
Igor Sysoev615fe7f2008-04-29 10:06:43 +00003863 args = (u_char *) ngx_strchr(uri.data, '?');
3864
Igor Sysoev732a2712004-04-21 18:54:33 +00003865 for (i = 1; i < cf->args->nelts - n; i++) {
Igor Sysoevc1571722005-03-19 12:38:37 +00003866 err = ngx_array_push(lcf->error_pages);
3867 if (err == NULL) {
Igor Sysoev732a2712004-04-21 18:54:33 +00003868 return NGX_CONF_ERROR;
3869 }
3870
Igor Sysoev3f4685f2004-04-25 20:13:21 +00003871 err->status = ngx_atoi(value[i].data, value[i].len);
Igor Sysoevaa828612005-02-09 14:31:07 +00003872
Igor Sysoev586f7a52006-09-25 17:48:34 +00003873 if (err->status == NGX_ERROR || err->status == 499) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003874 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003875 "invalid value \"%V\"", &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00003876 return NGX_CONF_ERROR;
3877 }
3878
Igor Sysoev3f4685f2004-04-25 20:13:21 +00003879 if (err->status < 400 || err->status > 599) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003880 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003881 "value \"%V\" must be between 400 and 599",
3882 &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00003883 return NGX_CONF_ERROR;
3884 }
3885
Igor Sysoevfb140922008-03-10 14:45:41 +00003886 if (overwrite >= 0) {
3887 err->overwrite = overwrite;
3888
3889 } else {
3890 switch (err->status) {
3891 case NGX_HTTP_TO_HTTPS:
3892 case NGX_HTTPS_CERT_ERROR:
3893 case NGX_HTTPS_NO_CERT:
3894 err->overwrite = NGX_HTTP_BAD_REQUEST;
3895 break;
3896
3897 default:
3898 err->overwrite = err->status;
3899 break;
3900 }
3901 }
Igor Sysoeva2573672005-10-05 14:46:21 +00003902
Igor Sysoev615fe7f2008-04-29 10:06:43 +00003903 if (args) {
3904 err->uri.len = args - uri.data;
3905 err->uri.data = uri.data;
3906 args++;
3907 err->args.len = (uri.data + uri.len) - args;
3908 err->args.data = args;
3909
3910 } else {
3911 err->uri = uri;
3912 err->args.len = 0;
3913 err->args.data = NULL;
3914 }
3915
Igor Sysoev08e63d42006-08-14 15:09:38 +00003916 err->uri_lengths = uri_lengths;
3917 err->uri_values = uri_values;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003918 }
3919
3920 return NGX_CONF_OK;
3921}
3922
3923
Igor Sysoevaa828612005-02-09 14:31:07 +00003924static char *
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003925ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3926{
3927 ngx_http_core_loc_conf_t *clcf = conf;
3928
3929 ngx_str_t *value;
3930 ngx_uint_t i, n;
3931 ngx_http_try_file_t *tf;
3932 ngx_http_script_compile_t sc;
3933 ngx_http_core_main_conf_t *cmcf;
3934
3935 if (clcf->try_files) {
3936 return "is duplicate";
3937 }
3938
3939 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
3940
3941 cmcf->try_files = 1;
3942
3943 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
3944 if (tf == NULL) {
3945 return NGX_CONF_ERROR;
3946 }
3947
3948 clcf->try_files = tf;
3949
3950 value = cf->args->elts;
3951
3952 for (i = 0; i < cf->args->nelts - 1; i++) {
3953
3954 tf[i].name = value[i + 1];
3955
Igor Sysoev319dc272009-01-21 12:11:22 +00003956 if (tf[i].name.data[tf[i].name.len - 1] == '/') {
3957 tf[i].test_dir = 1;
3958 tf[i].name.len--;
Igor Sysoevcd70a522009-03-20 16:47:23 +00003959 tf[i].name.data[tf[i].name.len] = '\0';
Igor Sysoev319dc272009-01-21 12:11:22 +00003960 }
3961
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003962 n = ngx_http_script_variables_count(&tf[i].name);
3963
3964 if (n) {
3965 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3966
3967 sc.cf = cf;
3968 sc.source = &tf[i].name;
3969 sc.lengths = &tf[i].lengths;
3970 sc.values = &tf[i].values;
3971 sc.variables = n;
3972 sc.complete_lengths = 1;
3973 sc.complete_values = 1;
3974
3975 if (ngx_http_script_compile(&sc) != NGX_OK) {
3976 return NGX_CONF_ERROR;
3977 }
3978
3979 } else {
3980 /* add trailing '\0' to length */
3981 tf[i].name.len++;
3982 }
3983 }
3984
3985 return NGX_CONF_OK;
3986}
3987
3988
3989static char *
Igor Sysoev140c7552007-09-01 12:12:48 +00003990ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3991{
3992 ngx_http_core_loc_conf_t *lcf = conf;
3993
3994 time_t inactive;
3995 ngx_str_t *value, s;
3996 ngx_int_t max;
3997 ngx_uint_t i;
3998
3999 if (lcf->open_file_cache != NGX_CONF_UNSET_PTR) {
4000 return "is duplicate";
4001 }
4002
4003 value = cf->args->elts;
4004
4005 max = 0;
4006 inactive = 60;
4007
4008 for (i = 1; i < cf->args->nelts; i++) {
4009
4010 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
4011
4012 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
4013 if (max == NGX_ERROR) {
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004014 goto failed;
Igor Sysoev140c7552007-09-01 12:12:48 +00004015 }
4016
4017 continue;
4018 }
4019
4020 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
4021
4022 s.len = value[i].len - 9;
4023 s.data = value[i].data + 9;
4024
4025 inactive = ngx_parse_time(&s, 1);
4026 if (inactive < 0) {
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004027 goto failed;
Igor Sysoev140c7552007-09-01 12:12:48 +00004028 }
4029
4030 continue;
4031 }
4032
4033 if (ngx_strcmp(value[i].data, "off") == 0) {
4034
4035 lcf->open_file_cache = NULL;
4036
4037 continue;
4038 }
4039
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004040 failed:
4041
Igor Sysoev140c7552007-09-01 12:12:48 +00004042 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4043 "invalid \"open_file_cache\" parameter \"%V\"",
4044 &value[i]);
4045 return NGX_CONF_ERROR;
4046 }
4047
4048 if (lcf->open_file_cache == NULL) {
4049 return NGX_CONF_OK;
4050 }
4051
4052 if (max == 0) {
4053 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4054 "\"open_file_cache\" must have \"max\" parameter");
4055 return NGX_CONF_ERROR;
4056 }
4057
4058 lcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
4059 if (lcf->open_file_cache) {
4060 return NGX_CONF_OK;
4061 }
4062
4063 return NGX_CONF_ERROR;
4064}
4065
4066
4067static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00004068ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4069{
4070 ngx_http_core_loc_conf_t *lcf = conf;
4071
4072 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
4073 if (lcf->err_log == NULL) {
4074 return NGX_CONF_ERROR;
4075 }
4076
4077 return ngx_set_error_log_levels(cf, lcf->err_log);
4078}
4079
4080
4081static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00004082ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004083{
4084 ngx_http_core_loc_conf_t *lcf = conf;
4085
4086 ngx_str_t *value;
4087
4088 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
4089 return "is duplicate";
4090 }
4091
4092 value = cf->args->elts;
4093
4094 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
Igor Sysoevaa828612005-02-09 14:31:07 +00004095
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004096 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
4097 return "invalid value";
4098 }
4099
4100 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
4101 return "value must be less than 597 hours";
4102 }
4103
4104 if (cf->args->nelts == 2) {
4105 return NGX_CONF_OK;
4106 }
4107
4108 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
Igor Sysoevaa828612005-02-09 14:31:07 +00004109
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004110 if (lcf->keepalive_header == NGX_ERROR) {
4111 return "invalid value";
4112 }
4113
4114 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
4115 return "value must be less than 68 years";
4116 }
4117
4118 return NGX_CONF_OK;
4119}
4120
4121
Igor Sysoevaa828612005-02-09 14:31:07 +00004122static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00004123ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev9d639522003-07-07 06:11:50 +00004124{
4125 ngx_http_core_loc_conf_t *lcf = conf;
4126
Igor Sysoev899b44e2005-05-12 14:58:06 +00004127 if (lcf->internal != NGX_CONF_UNSET) {
4128 return "is duplicate";
Igor Sysoev03420a62004-01-20 20:40:08 +00004129 }
Igor Sysoev9d639522003-07-07 06:11:50 +00004130
Igor Sysoev899b44e2005-05-12 14:58:06 +00004131 lcf->internal = 1;
4132
4133 return NGX_CONF_OK;
Igor Sysoev9d639522003-07-07 06:11:50 +00004134}
Igor Sysoevb5faed22003-10-29 08:30:44 +00004135
4136
Igor Sysoevaa828612005-02-09 14:31:07 +00004137static char *
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004138ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4139{
4140 ngx_http_core_loc_conf_t *clcf = conf;
4141
4142 ngx_url_t u;
4143 ngx_str_t *value;
4144
Igor Sysoevf39876c2008-03-06 08:48:55 +00004145 if (clcf->resolver) {
4146 return "is duplicate";
4147 }
4148
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004149 value = cf->args->elts;
4150
Igor Sysoev4d65f652007-11-30 22:08:59 +00004151 ngx_memzero(&u, sizeof(ngx_url_t));
4152
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004153 u.host = value[1];
4154 u.port = 53;
4155
4156 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
4157 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
4158 return NGX_CONF_ERROR;
4159 }
4160
Igor Sysoevdfd55112008-03-04 10:42:05 +00004161 clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004162 if (clcf->resolver == NULL) {
4163 return NGX_OK;
4164 }
4165
4166 return NGX_CONF_OK;
4167}
4168
4169
Igor Sysoevc16b0052007-12-27 14:21:59 +00004170#if (NGX_HTTP_GZIP)
4171
4172static char *
4173ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4174{
Igor Sysoevc16b0052007-12-27 14:21:59 +00004175 ngx_http_core_loc_conf_t *clcf = conf;
4176
Igor Sysoev54477e42008-08-26 15:09:28 +00004177#if (NGX_PCRE)
4178
Igor Sysoevc16b0052007-12-27 14:21:59 +00004179 ngx_str_t err, *value;
4180 ngx_uint_t i;
4181 ngx_regex_elt_t *re;
4182 u_char errstr[NGX_MAX_CONF_ERRSTR];
4183
4184 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
4185 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
4186 sizeof(ngx_regex_elt_t));
4187 if (clcf->gzip_disable == NULL) {
4188 return NGX_CONF_ERROR;
4189 }
4190 }
4191
4192 value = cf->args->elts;
4193
4194 err.len = NGX_MAX_CONF_ERRSTR;
4195 err.data = errstr;
4196
4197 for (i = 1; i < cf->args->nelts; i++) {
4198
Igor Sysoev54477e42008-08-26 15:09:28 +00004199 if (ngx_strcmp(value[1].data, "msie6") == 0) {
4200 clcf->gzip_disable_msie6 = 1;
4201 continue;
4202 }
4203
Igor Sysoevc16b0052007-12-27 14:21:59 +00004204 re = ngx_array_push(clcf->gzip_disable);
4205 if (re == NULL) {
4206 return NGX_CONF_ERROR;
4207 }
4208
4209 re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool,
4210 &err);
4211
4212 if (re->regex == NULL) {
4213 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
4214 return NGX_CONF_ERROR;
4215 }
4216
4217 re->name = value[i].data;
4218 }
4219
4220 return NGX_CONF_OK;
4221
4222#else
Igor Sysoev54477e42008-08-26 15:09:28 +00004223 ngx_str_t *value;
4224
4225 value = cf->args->elts;
4226
4227 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "msie6") == 0) {
4228 clcf->gzip_disable_msie6 = 1;
4229 return NGX_CONF_OK;
4230 }
4231
Igor Sysoevc16b0052007-12-27 14:21:59 +00004232 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev54477e42008-08-26 15:09:28 +00004233 "without PCRE library \"gzip_disable\" supports "
4234 "builtin \"msie6\" mask only");
Igor Sysoevc16b0052007-12-27 14:21:59 +00004235
4236 return NGX_CONF_ERROR;
4237#endif
4238}
4239
4240#endif
4241
4242
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004243static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00004244ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
Igor Sysoevb5faed22003-10-29 08:30:44 +00004245{
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00004246#if (NGX_FREEBSD)
Igor Sysoev42b12b32004-12-02 18:40:46 +00004247 ssize_t *np = data;
Igor Sysoev924bd792004-10-11 15:07:03 +00004248
Igor Sysoev08e63d42006-08-14 15:09:38 +00004249 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
Igor Sysoevb5faed22003-10-29 08:30:44 +00004250 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4251 "\"send_lowat\" must be less than %d "
4252 "(sysctl net.inet.tcp.sendspace)",
4253 ngx_freebsd_net_inet_tcp_sendspace);
4254
4255 return NGX_CONF_ERROR;
4256 }
4257
Igor Sysoevf6906042004-11-25 16:17:31 +00004258#elif !(NGX_HAVE_SO_SNDLOWAT)
Igor Sysoev42b12b32004-12-02 18:40:46 +00004259 ssize_t *np = data;
Igor Sysoevb5faed22003-10-29 08:30:44 +00004260
4261 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4262 "\"send_lowat\" is not supported, ignored");
4263
Igor Sysoev924bd792004-10-11 15:07:03 +00004264 *np = 0;
4265
Igor Sysoevb5faed22003-10-29 08:30:44 +00004266#endif
4267
4268 return NGX_CONF_OK;
4269}
Igor Sysoev08d068f2007-05-07 09:20:42 +00004270
4271
4272static char *
4273ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
4274{
4275 size_t *sp = data;
4276
4277 if (*sp < NGX_MIN_POOL_SIZE) {
4278 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4279 "pool must be no less than %uz", NGX_MIN_POOL_SIZE);
4280
4281 return NGX_CONF_ERROR;
4282 }
4283
4284 return NGX_CONF_OK;
4285}