blob: 1766e1298c9fe93a9f934f749f6baae5d261ca26 [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 Sysoevbfff0342009-08-30 09:52:39 +0000107#if (NGX_HAVE_FILE_AIO)
108
109static ngx_conf_enum_t ngx_http_core_aio[] = {
110 { ngx_string("off"), NGX_HTTP_AIO_OFF },
111 { ngx_string("on"), NGX_HTTP_AIO_ON },
112#if (NGX_HAVE_AIO_SENDFILE)
113 { ngx_string("sendfile"), NGX_HTTP_AIO_SENDFILE },
114#endif
115 { ngx_null_string, 0 }
116};
117
118#endif
119
120
Igor Sysoev2d028f82007-12-29 16:38:23 +0000121static ngx_conf_enum_t ngx_http_core_satisfy[] = {
122 { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
123 { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
124 { ngx_null_string, 0 }
125};
126
127
Igor Sysoev863325f2008-12-01 14:22:51 +0000128static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
Igor Sysoev2c336482009-02-10 15:05:05 +0000129 { ngx_string("off"), NGX_HTTP_IMS_OFF },
130 { ngx_string("exact"), NGX_HTTP_IMS_EXACT },
131 { ngx_string("before"), NGX_HTTP_IMS_BEFORE },
Igor Sysoev863325f2008-12-01 14:22:51 +0000132 { ngx_null_string, 0 }
133};
134
135
Igor Sysoev52859f22009-03-23 13:14:51 +0000136static ngx_path_init_t ngx_http_client_temp_path = {
137 ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 }
138};
139
140
Igor Sysoevc16b0052007-12-27 14:21:59 +0000141#if (NGX_HTTP_GZIP)
142
143static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
144 { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
145 { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
146 { ngx_null_string, 0 }
147};
148
149
150static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
151 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
152 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
153 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
154 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
155 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
156 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
157 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
158 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
159 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
160 { ngx_null_string, 0 }
161};
162
163
164static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
165static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store");
166static ngx_str_t ngx_http_gzip_private = ngx_string("private");
167
168#endif
169
170
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000171static ngx_command_t ngx_http_core_commands[] = {
172
Igor Sysoevffe71442006-02-08 15:33:12 +0000173 { ngx_string("variables_hash_max_size"),
174 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
175 ngx_conf_set_num_slot,
176 NGX_HTTP_MAIN_CONF_OFFSET,
177 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
178 NULL },
179
180 { ngx_string("variables_hash_bucket_size"),
181 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
182 ngx_conf_set_num_slot,
183 NGX_HTTP_MAIN_CONF_OFFSET,
184 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
185 NULL },
186
Igor Sysoev305a9d82005-12-26 17:07:48 +0000187 { ngx_string("server_names_hash_max_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000188 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
189 ngx_conf_set_num_slot,
190 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +0000191 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000192 NULL },
193
Igor Sysoev305a9d82005-12-26 17:07:48 +0000194 { ngx_string("server_names_hash_bucket_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000195 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
196 ngx_conf_set_num_slot,
197 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +0000198 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000199 NULL },
200
Igor Sysoev865c1502003-11-30 20:03:18 +0000201 { ngx_string("server"),
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000202 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000203 ngx_http_core_server,
Igor Sysoev865c1502003-11-30 20:03:18 +0000204 0,
205 0,
206 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000207
Igor Sysoev865c1502003-11-30 20:03:18 +0000208 { ngx_string("connection_pool_size"),
209 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
210 ngx_conf_set_size_slot,
211 NGX_HTTP_SRV_CONF_OFFSET,
212 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
Igor Sysoev08d068f2007-05-07 09:20:42 +0000213 &ngx_http_core_pool_size_p },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000214
Igor Sysoev865c1502003-11-30 20:03:18 +0000215 { ngx_string("request_pool_size"),
216 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
217 ngx_conf_set_size_slot,
218 NGX_HTTP_SRV_CONF_OFFSET,
219 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
Igor Sysoev08d068f2007-05-07 09:20:42 +0000220 &ngx_http_core_pool_size_p },
Igor Sysoev187fcd82003-05-23 11:53:01 +0000221
Igor Sysoev865c1502003-11-30 20:03:18 +0000222 { ngx_string("client_header_timeout"),
223 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
224 ngx_conf_set_msec_slot,
225 NGX_HTTP_SRV_CONF_OFFSET,
226 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
227 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000228
Igor Sysoev865c1502003-11-30 20:03:18 +0000229 { ngx_string("client_header_buffer_size"),
230 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
231 ngx_conf_set_size_slot,
232 NGX_HTTP_SRV_CONF_OFFSET,
233 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
234 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000235
Igor Sysoevf7abd722004-09-23 06:32:00 +0000236 { ngx_string("large_client_header_buffers"),
Igor Sysoev85080d02004-09-22 16:18:21 +0000237 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
238 ngx_conf_set_bufs_slot,
239 NGX_HTTP_SRV_CONF_OFFSET,
Igor Sysoevf7abd722004-09-23 06:32:00 +0000240 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
Igor Sysoev865c1502003-11-30 20:03:18 +0000241 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000242
Igor Sysoev8290d282006-02-03 12:58:48 +0000243 { ngx_string("optimize_server_names"),
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
245 ngx_conf_set_flag_slot,
Igor Sysoev5cdb2ce2008-05-24 15:43:48 +0000246 NGX_HTTP_LOC_CONF_OFFSET,
247 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
248 &ngx_conf_deprecated_optimize_server_names },
Igor Sysoev34303462006-01-24 16:08:27 +0000249
Igor Sysoev3362b8d2005-05-14 18:42:03 +0000250 { ngx_string("ignore_invalid_headers"),
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
252 ngx_conf_set_flag_slot,
253 NGX_HTTP_SRV_CONF_OFFSET,
254 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
255 NULL },
256
Igor Sysoev8decab32007-10-18 11:36:58 +0000257 { ngx_string("merge_slashes"),
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
259 ngx_conf_set_flag_slot,
260 NGX_HTTP_SRV_CONF_OFFSET,
261 offsetof(ngx_http_core_srv_conf_t, merge_slashes),
262 NULL },
263
Igor Sysoev753792e2008-09-24 14:02:50 +0000264 { ngx_string("underscores_in_headers"),
265 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
266 ngx_conf_set_flag_slot,
267 NGX_HTTP_SRV_CONF_OFFSET,
268 offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
269 NULL },
270
Igor Sysoev865c1502003-11-30 20:03:18 +0000271 { ngx_string("location"),
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000272 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000273 ngx_http_core_location,
Igor Sysoev865c1502003-11-30 20:03:18 +0000274 NGX_HTTP_SRV_CONF_OFFSET,
275 0,
276 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000277
Igor Sysoev865c1502003-11-30 20:03:18 +0000278 { ngx_string("listen"),
Igor Sysoevb145b062005-06-15 18:33:41 +0000279 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000280 ngx_http_core_listen,
Igor Sysoev865c1502003-11-30 20:03:18 +0000281 NGX_HTTP_SRV_CONF_OFFSET,
282 0,
283 NULL },
Igor Sysoeva19a85e2003-01-28 15:56:37 +0000284
Igor Sysoev865c1502003-11-30 20:03:18 +0000285 { ngx_string("server_name"),
286 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000287 ngx_http_core_server_name,
Igor Sysoev865c1502003-11-30 20:03:18 +0000288 NGX_HTTP_SRV_CONF_OFFSET,
289 0,
290 NULL },
Igor Sysoev13933252003-05-29 13:02:09 +0000291
Igor Sysoev24025022005-12-16 15:07:08 +0000292 { ngx_string("types_hash_max_size"),
293 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
294 ngx_conf_set_num_slot,
295 NGX_HTTP_LOC_CONF_OFFSET,
296 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
297 NULL },
298
299 { ngx_string("types_hash_bucket_size"),
300 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
301 ngx_conf_set_num_slot,
302 NGX_HTTP_LOC_CONF_OFFSET,
303 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
304 NULL },
305
Igor Sysoev865c1502003-11-30 20:03:18 +0000306 { ngx_string("types"),
307 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
308 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000309 ngx_http_core_types,
Igor Sysoev865c1502003-11-30 20:03:18 +0000310 NGX_HTTP_LOC_CONF_OFFSET,
311 0,
312 NULL },
Igor Sysoev79a80482003-05-14 17:13:13 +0000313
Igor Sysoev865c1502003-11-30 20:03:18 +0000314 { ngx_string("default_type"),
315 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
316 ngx_conf_set_str_slot,
317 NGX_HTTP_LOC_CONF_OFFSET,
318 offsetof(ngx_http_core_loc_conf_t, default_type),
319 NULL },
Igor Sysoev6253ca12003-05-27 12:18:54 +0000320
Igor Sysoev865c1502003-11-30 20:03:18 +0000321 { ngx_string("root"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000322 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
323 |NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000324 ngx_http_core_root,
Igor Sysoev865c1502003-11-30 20:03:18 +0000325 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000326 0,
327 NULL },
328
329 { ngx_string("alias"),
330 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000331 ngx_http_core_root,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000332 NGX_HTTP_LOC_CONF_OFFSET,
333 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000334 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000335
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000336 { ngx_string("limit_except"),
337 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
338 ngx_http_core_limit_except,
339 NGX_HTTP_LOC_CONF_OFFSET,
340 0,
341 NULL },
342
Igor Sysoevae02c192004-03-19 05:25:53 +0000343 { ngx_string("client_max_body_size"),
344 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev1765f472006-07-07 16:33:19 +0000345 ngx_conf_set_off_slot,
Igor Sysoevae02c192004-03-19 05:25:53 +0000346 NGX_HTTP_LOC_CONF_OFFSET,
347 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
348 NULL },
349
Igor Sysoevdbb27762004-04-01 16:20:53 +0000350 { ngx_string("client_body_buffer_size"),
351 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
352 ngx_conf_set_size_slot,
353 NGX_HTTP_LOC_CONF_OFFSET,
354 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
355 NULL },
356
Igor Sysoev865c1502003-11-30 20:03:18 +0000357 { ngx_string("client_body_timeout"),
358 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
359 ngx_conf_set_msec_slot,
360 NGX_HTTP_LOC_CONF_OFFSET,
361 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
362 NULL },
Igor Sysoev2b0c76c2003-10-27 21:01:00 +0000363
Igor Sysoev02025fd2005-01-18 13:03:58 +0000364 { ngx_string("client_body_temp_path"),
365 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
366 ngx_conf_set_path_slot,
367 NGX_HTTP_LOC_CONF_OFFSET,
368 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
Igor Sysoev52859f22009-03-23 13:14:51 +0000369 NULL },
Igor Sysoev02025fd2005-01-18 13:03:58 +0000370
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000371 { ngx_string("client_body_in_file_only"),
Igor Sysoeve6460ea2009-05-14 11:39:06 +0000372 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev64304df2007-01-24 09:14:08 +0000373 ngx_conf_set_enum_slot,
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000374 NGX_HTTP_LOC_CONF_OFFSET,
375 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
Igor Sysoev64304df2007-01-24 09:14:08 +0000376 &ngx_http_core_request_body_in_file },
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000377
Igor Sysoevbfbded72009-05-14 11:41:33 +0000378 { ngx_string("client_body_in_single_buffer"),
379 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
380 ngx_conf_set_flag_slot,
381 NGX_HTTP_LOC_CONF_OFFSET,
382 offsetof(ngx_http_core_loc_conf_t, client_body_in_single_buffer),
383 NULL },
384
Igor Sysoev865c1502003-11-30 20:03:18 +0000385 { ngx_string("sendfile"),
Igor Sysoev300de4f2007-01-21 17:42:28 +0000386 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
387 |NGX_CONF_TAKE1,
Igor Sysoev865c1502003-11-30 20:03:18 +0000388 ngx_conf_set_flag_slot,
389 NGX_HTTP_LOC_CONF_OFFSET,
390 offsetof(ngx_http_core_loc_conf_t, sendfile),
391 NULL },
Igor Sysoev5bf3d252003-10-22 07:05:29 +0000392
Igor Sysoevc9b57dc2007-05-07 06:33:39 +0000393 { ngx_string("sendfile_max_chunk"),
394 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
395 ngx_conf_set_size_slot,
396 NGX_HTTP_LOC_CONF_OFFSET,
397 offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
398 NULL },
399
Igor Sysoeva9625062009-08-28 08:12:35 +0000400#if (NGX_HAVE_FILE_AIO)
401
402 { ngx_string("aio"),
Igor Sysoevbfff0342009-08-30 09:52:39 +0000403 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
404 ngx_conf_set_enum_slot,
Igor Sysoeva9625062009-08-28 08:12:35 +0000405 NGX_HTTP_LOC_CONF_OFFSET,
406 offsetof(ngx_http_core_loc_conf_t, aio),
Igor Sysoevbfff0342009-08-30 09:52:39 +0000407 &ngx_http_core_aio },
Igor Sysoeva9625062009-08-28 08:12:35 +0000408
409#endif
410
Igor Sysoev32661712009-09-30 13:21:52 +0000411 { ngx_string("read_ahead"),
412 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
413 ngx_conf_set_size_slot,
414 NGX_HTTP_LOC_CONF_OFFSET,
415 offsetof(ngx_http_core_loc_conf_t, read_ahead),
416 NULL },
417
Igor Sysoev385af282008-07-30 12:34:04 +0000418 { ngx_string("directio"),
419 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
420 ngx_http_core_directio,
421 NGX_HTTP_LOC_CONF_OFFSET,
422 0,
423 NULL },
424
Igor Sysoev6fb506a2009-08-28 08:15:55 +0000425 { ngx_string("directio_alignment"),
426 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
427 ngx_conf_set_off_slot,
428 NGX_HTTP_LOC_CONF_OFFSET,
429 offsetof(ngx_http_core_loc_conf_t, directio_alignment),
430 NULL },
431
Igor Sysoev3c3ca172004-01-05 20:55:48 +0000432 { ngx_string("tcp_nopush"),
433 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
434 ngx_conf_set_flag_slot,
435 NGX_HTTP_LOC_CONF_OFFSET,
436 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
437 NULL },
438
Igor Sysoev924bd792004-10-11 15:07:03 +0000439 { ngx_string("tcp_nodelay"),
440 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
441 ngx_conf_set_flag_slot,
442 NGX_HTTP_LOC_CONF_OFFSET,
443 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
444 NULL },
445
Igor Sysoev865c1502003-11-30 20:03:18 +0000446 { ngx_string("send_timeout"),
447 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
448 ngx_conf_set_msec_slot,
449 NGX_HTTP_LOC_CONF_OFFSET,
450 offsetof(ngx_http_core_loc_conf_t, send_timeout),
451 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000452
Igor Sysoev865c1502003-11-30 20:03:18 +0000453 { ngx_string("send_lowat"),
454 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
455 ngx_conf_set_size_slot,
456 NGX_HTTP_LOC_CONF_OFFSET,
457 offsetof(ngx_http_core_loc_conf_t, send_lowat),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000458 &ngx_http_core_lowat_post },
Igor Sysoevb5faed22003-10-29 08:30:44 +0000459
Igor Sysoev7823cc32004-07-14 16:01:42 +0000460 { ngx_string("postpone_output"),
461 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
462 ngx_conf_set_size_slot,
463 NGX_HTTP_LOC_CONF_OFFSET,
464 offsetof(ngx_http_core_loc_conf_t, postpone_output),
465 NULL },
466
467 { ngx_string("limit_rate"),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000468 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
469 |NGX_CONF_TAKE1,
Igor Sysoev7823cc32004-07-14 16:01:42 +0000470 ngx_conf_set_size_slot,
471 NGX_HTTP_LOC_CONF_OFFSET,
472 offsetof(ngx_http_core_loc_conf_t, limit_rate),
473 NULL },
474
Igor Sysoev80027fc2009-06-02 14:01:50 +0000475 { ngx_string("limit_rate_after"),
476 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
477 |NGX_CONF_TAKE1,
478 ngx_conf_set_size_slot,
479 NGX_HTTP_LOC_CONF_OFFSET,
480 offsetof(ngx_http_core_loc_conf_t, limit_rate_after),
481 NULL },
482
Igor Sysoev865c1502003-11-30 20:03:18 +0000483 { ngx_string("keepalive_timeout"),
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000484 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000485 ngx_http_core_keepalive,
Igor Sysoev865c1502003-11-30 20:03:18 +0000486 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000487 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000488 NULL },
Igor Sysoevfa73aac2003-05-21 13:28:21 +0000489
Igor Sysoeve9591282009-05-25 15:38:36 +0000490 { ngx_string("keepalive_requests"),
491 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
492 ngx_conf_set_num_slot,
493 NGX_HTTP_LOC_CONF_OFFSET,
494 offsetof(ngx_http_core_loc_conf_t, keepalive_requests),
495 NULL },
496
Igor Sysoev2d028f82007-12-29 16:38:23 +0000497 { ngx_string("satisfy"),
498 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
499 ngx_conf_set_enum_slot,
500 NGX_HTTP_LOC_CONF_OFFSET,
501 offsetof(ngx_http_core_loc_conf_t, satisfy),
502 &ngx_http_core_satisfy },
503
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000504 { ngx_string("satisfy_any"),
505 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
506 ngx_conf_set_flag_slot,
507 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev2d028f82007-12-29 16:38:23 +0000508 offsetof(ngx_http_core_loc_conf_t, satisfy),
509 &ngx_conf_deprecated_satisfy_any },
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000510
Igor Sysoev899b44e2005-05-12 14:58:06 +0000511 { ngx_string("internal"),
512 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
513 ngx_http_core_internal,
514 NGX_HTTP_LOC_CONF_OFFSET,
515 0,
516 NULL },
517
Igor Sysoev865c1502003-11-30 20:03:18 +0000518 { ngx_string("lingering_time"),
519 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
520 ngx_conf_set_msec_slot,
521 NGX_HTTP_LOC_CONF_OFFSET,
522 offsetof(ngx_http_core_loc_conf_t, lingering_time),
523 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000524
Igor Sysoev865c1502003-11-30 20:03:18 +0000525 { ngx_string("lingering_timeout"),
526 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
527 ngx_conf_set_msec_slot,
528 NGX_HTTP_LOC_CONF_OFFSET,
529 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
530 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000531
Igor Sysoev0ab91b92004-06-06 19:49:18 +0000532 { ngx_string("reset_timedout_connection"),
533 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
534 ngx_conf_set_flag_slot,
535 NGX_HTTP_LOC_CONF_OFFSET,
536 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
537 NULL },
538
Igor Sysoev3f24ae22007-12-29 15:30:39 +0000539 { ngx_string("server_name_in_redirect"),
540 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
541 ngx_conf_set_flag_slot,
542 NGX_HTTP_LOC_CONF_OFFSET,
543 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
544 NULL },
545
Igor Sysoev7b190b42005-06-07 15:56:31 +0000546 { ngx_string("port_in_redirect"),
547 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
548 ngx_conf_set_flag_slot,
549 NGX_HTTP_LOC_CONF_OFFSET,
550 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
551 NULL },
552
Igor Sysoev865c1502003-11-30 20:03:18 +0000553 { ngx_string("msie_padding"),
554 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
555 ngx_conf_set_flag_slot,
556 NGX_HTTP_LOC_CONF_OFFSET,
557 offsetof(ngx_http_core_loc_conf_t, msie_padding),
558 NULL },
Igor Sysoev12b4b002003-10-24 06:53:41 +0000559
Igor Sysoev3f8dc592006-08-28 16:57:48 +0000560 { ngx_string("msie_refresh"),
561 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
562 ngx_conf_set_flag_slot,
563 NGX_HTTP_LOC_CONF_OFFSET,
564 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
565 NULL },
566
Igor Sysoev5192b362005-07-08 14:34:20 +0000567 { ngx_string("log_not_found"),
568 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
569 ngx_conf_set_flag_slot,
570 NGX_HTTP_LOC_CONF_OFFSET,
571 offsetof(ngx_http_core_loc_conf_t, log_not_found),
572 NULL },
573
Igor Sysoev2eec1e12008-09-27 15:08:02 +0000574 { ngx_string("log_subrequest"),
575 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
576 ngx_conf_set_flag_slot,
577 NGX_HTTP_LOC_CONF_OFFSET,
578 offsetof(ngx_http_core_loc_conf_t, log_subrequest),
579 NULL },
580
Igor Sysoev3f8dc592006-08-28 16:57:48 +0000581 { ngx_string("recursive_error_pages"),
582 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
583 ngx_conf_set_flag_slot,
584 NGX_HTTP_LOC_CONF_OFFSET,
585 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
586 NULL },
587
Igor Sysoev070cf222007-10-22 10:17:34 +0000588 { ngx_string("server_tokens"),
589 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
590 ngx_conf_set_flag_slot,
591 NGX_HTTP_LOC_CONF_OFFSET,
592 offsetof(ngx_http_core_loc_conf_t, server_tokens),
593 NULL },
594
Igor Sysoev863325f2008-12-01 14:22:51 +0000595 { ngx_string("if_modified_since"),
596 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
597 ngx_conf_set_enum_slot,
598 NGX_HTTP_LOC_CONF_OFFSET,
599 offsetof(ngx_http_core_loc_conf_t, if_modified_since),
600 &ngx_http_core_if_modified_since },
601
Igor Sysoev865c1502003-11-30 20:03:18 +0000602 { ngx_string("error_page"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000603 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
604 |NGX_CONF_2MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000605 ngx_http_core_error_page,
Igor Sysoev865c1502003-11-30 20:03:18 +0000606 NGX_HTTP_LOC_CONF_OFFSET,
607 0,
608 NULL },
Igor Sysoev74e95c22003-11-09 20:03:38 +0000609
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +0000610 { ngx_string("try_files"),
Igor Sysoeve018a9c2009-03-20 16:48:45 +0000611 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +0000612 ngx_http_core_try_files,
613 NGX_HTTP_LOC_CONF_OFFSET,
614 0,
615 NULL },
616
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000617 { ngx_string("post_action"),
618 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
619 |NGX_CONF_TAKE1,
620 ngx_conf_set_str_slot,
621 NGX_HTTP_LOC_CONF_OFFSET,
622 offsetof(ngx_http_core_loc_conf_t, post_action),
623 NULL },
624
Igor Sysoev865c1502003-11-30 20:03:18 +0000625 { ngx_string("error_log"),
Igor Sysoev03420a62004-01-20 20:40:08 +0000626 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000627 ngx_http_core_error_log,
Igor Sysoev865c1502003-11-30 20:03:18 +0000628 NGX_HTTP_LOC_CONF_OFFSET,
629 0,
630 NULL },
Igor Sysoev890fc962003-07-20 21:15:59 +0000631
Igor Sysoev865c1502003-11-30 20:03:18 +0000632 { ngx_string("open_file_cache"),
Igor Sysoev140c7552007-09-01 12:12:48 +0000633 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
634 ngx_http_core_open_file_cache,
Igor Sysoev865c1502003-11-30 20:03:18 +0000635 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev140c7552007-09-01 12:12:48 +0000636 offsetof(ngx_http_core_loc_conf_t, open_file_cache),
Igor Sysoev865c1502003-11-30 20:03:18 +0000637 NULL },
638
Igor Sysoev9b9616e2007-12-21 16:19:48 +0000639 { ngx_string("open_file_cache_valid"),
640 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
641 ngx_conf_set_sec_slot,
642 NGX_HTTP_LOC_CONF_OFFSET,
643 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
644 NULL },
645
Igor Sysoev140c7552007-09-01 12:12:48 +0000646 { ngx_string("open_file_cache_retest"),
647 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
648 ngx_conf_set_sec_slot,
649 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev9b9616e2007-12-21 16:19:48 +0000650 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
651 &ngx_conf_deprecated_open_file_cache_retest },
Igor Sysoev140c7552007-09-01 12:12:48 +0000652
Igor Sysoevf3b0e492007-12-22 13:19:39 +0000653 { ngx_string("open_file_cache_min_uses"),
654 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
655 ngx_conf_set_num_slot,
656 NGX_HTTP_LOC_CONF_OFFSET,
657 offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
658 NULL },
659
Igor Sysoev140c7552007-09-01 12:12:48 +0000660 { ngx_string("open_file_cache_errors"),
661 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
662 ngx_conf_set_flag_slot,
663 NGX_HTTP_LOC_CONF_OFFSET,
664 offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
665 NULL },
Igor Sysoev67f88e92004-03-12 16:57:08 +0000666
Igor Sysoev9afd58f2007-09-03 08:41:42 +0000667 { ngx_string("open_file_cache_events"),
668 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
669 ngx_conf_set_flag_slot,
670 NGX_HTTP_LOC_CONF_OFFSET,
671 offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
672 NULL },
673
Igor Sysoev13f5ff92007-11-27 11:33:52 +0000674 { ngx_string("resolver"),
675 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
676 ngx_http_core_resolver,
677 NGX_HTTP_LOC_CONF_OFFSET,
678 0,
679 NULL },
680
681 { ngx_string("resolver_timeout"),
682 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
683 ngx_conf_set_msec_slot,
684 NGX_HTTP_LOC_CONF_OFFSET,
685 offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
686 NULL },
687
Igor Sysoevc16b0052007-12-27 14:21:59 +0000688#if (NGX_HTTP_GZIP)
689
690 { ngx_string("gzip_vary"),
691 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
692 ngx_conf_set_flag_slot,
693 NGX_HTTP_LOC_CONF_OFFSET,
694 offsetof(ngx_http_core_loc_conf_t, gzip_vary),
695 NULL },
696
697 { ngx_string("gzip_http_version"),
698 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
699 ngx_conf_set_enum_slot,
700 NGX_HTTP_LOC_CONF_OFFSET,
701 offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
702 &ngx_http_gzip_http_version },
703
704 { ngx_string("gzip_proxied"),
705 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
706 ngx_conf_set_bitmask_slot,
707 NGX_HTTP_LOC_CONF_OFFSET,
708 offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
709 &ngx_http_gzip_proxied_mask },
710
711 { ngx_string("gzip_disable"),
712 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
713 ngx_http_gzip_disable,
714 NGX_HTTP_LOC_CONF_OFFSET,
715 0,
716 NULL },
717
718#endif
719
Igor Sysoev865c1502003-11-30 20:03:18 +0000720 ngx_null_command
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000721};
722
723
Igor Sysoev8f125582006-07-28 15:16:17 +0000724static ngx_http_module_t ngx_http_core_module_ctx = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000725 ngx_http_core_preconfiguration, /* preconfiguration */
Igor Sysoev09c684b2005-11-09 17:25:55 +0000726 NULL, /* postconfiguration */
Igor Sysoev78329332003-11-10 17:17:31 +0000727
Igor Sysoeva9830112003-05-19 16:39:14 +0000728 ngx_http_core_create_main_conf, /* create main configuration */
729 ngx_http_core_init_main_conf, /* init main configuration */
Igor Sysoevdc479b42003-03-20 16:09:44 +0000730
Igor Sysoeva9830112003-05-19 16:39:14 +0000731 ngx_http_core_create_srv_conf, /* create server configuration */
732 ngx_http_core_merge_srv_conf, /* merge server configuration */
733
734 ngx_http_core_create_loc_conf, /* create location configuration */
735 ngx_http_core_merge_loc_conf /* merge location configuration */
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000736};
737
738
739ngx_module_t ngx_http_core_module = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000740 NGX_MODULE_V1,
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000741 &ngx_http_core_module_ctx, /* module context */
742 ngx_http_core_commands, /* module directives */
Igor Sysoev6253ca12003-05-27 12:18:54 +0000743 NGX_HTTP_MODULE, /* module type */
Igor Sysoeve5733802005-09-08 14:36:09 +0000744 NULL, /* init master */
Igor Sysoev899b44e2005-05-12 14:58:06 +0000745 NULL, /* init module */
Igor Sysoeve5733802005-09-08 14:36:09 +0000746 NULL, /* init process */
747 NULL, /* init thread */
748 NULL, /* exit thread */
749 NULL, /* exit process */
750 NULL, /* exit master */
751 NGX_MODULE_V1_PADDING
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000752};
753
754
Igor Sysoevea8536b2009-04-15 09:53:22 +0000755ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " };
Igor Sysoev88b24062008-02-07 10:38:13 +0000756
757
Igor Sysoevaa828612005-02-09 14:31:07 +0000758void
759ngx_http_handler(ngx_http_request_t *r)
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000760{
Igor Sysoevda173ab2006-08-30 10:39:17 +0000761 ngx_http_core_main_conf_t *cmcf;
762
Igor Sysoeve5a222c2005-01-25 12:27:35 +0000763 r->connection->log->action = NULL;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000764
765 r->connection->unexpected_eof = 0;
766
Igor Sysoevef316432006-08-16 13:09:33 +0000767 if (!r->internal) {
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000768 switch (r->headers_in.connection_type) {
769 case 0:
770 if (r->http_version > NGX_HTTP_VERSION_10) {
771 r->keepalive = 1;
772 } else {
773 r->keepalive = 0;
774 }
775 break;
776
777 case NGX_HTTP_CONNECTION_CLOSE:
778 r->keepalive = 0;
779 break;
780
781 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000782 r->keepalive = 1;
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000783 break;
784 }
785
786 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
787
788 /*
Igor Sysoevda173ab2006-08-30 10:39:17 +0000789 * MSIE may wait for some time if an response for
790 * a POST request was sent over a keepalive connection
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000791 */
792
Igor Sysoev9760a132003-10-21 07:47:21 +0000793 r->keepalive = 0;
794 }
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000795
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000796 if (r->headers_in.content_length_n > 0) {
797 r->lingering_close = 1;
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000798
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000799 } else {
800 r->lingering_close = 0;
801 }
Igor Sysoev9760a132003-10-21 07:47:21 +0000802
Igor Sysoevda173ab2006-08-30 10:39:17 +0000803 r->phase_handler = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000804
Igor Sysoevda173ab2006-08-30 10:39:17 +0000805 } else {
806 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
807 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
808 }
809
Igor Sysoev8a3cdc02006-09-25 17:49:49 +0000810 if (r->unparsed_uri.len) {
811 r->valid_unparsed_uri = 1;
812 }
813
814 r->valid_location = 1;
Igor Sysoev6c49a5a2009-11-12 13:41:56 +0000815#if (NGX_HTTP_GZIP)
816 r->gzip_tested = 0;
817 r->gzip_ok = 0;
818 r->gzip_vary = 0;
819#endif
Igor Sysoev8a3cdc02006-09-25 17:49:49 +0000820
Igor Sysoevda173ab2006-08-30 10:39:17 +0000821 r->write_event_handler = ngx_http_core_run_phases;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000822 ngx_http_core_run_phases(r);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000823}
Igor Sysoeve2a31542003-04-08 15:40:10 +0000824
825
Igor Sysoevda173ab2006-08-30 10:39:17 +0000826void
Igor Sysoevaa828612005-02-09 14:31:07 +0000827ngx_http_core_run_phases(ngx_http_request_t *r)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000828{
Igor Sysoev865c1502003-11-30 20:03:18 +0000829 ngx_int_t rc;
Igor Sysoevda173ab2006-08-30 10:39:17 +0000830 ngx_http_phase_handler_t *ph;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000831 ngx_http_core_main_conf_t *cmcf;
832
833 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
834
Igor Sysoevda173ab2006-08-30 10:39:17 +0000835 ph = cmcf->phase_engine.handlers;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000836
Igor Sysoevda173ab2006-08-30 10:39:17 +0000837 while (ph[r->phase_handler].checker) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000838
Igor Sysoevda173ab2006-08-30 10:39:17 +0000839 rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
Igor Sysoev805d9db2005-02-03 19:33:37 +0000840
Igor Sysoevda173ab2006-08-30 10:39:17 +0000841 if (rc == NGX_OK) {
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000842 return;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000843 }
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000844 }
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000845}
846
847
Igor Sysoevaa828612005-02-09 14:31:07 +0000848ngx_int_t
Igor Sysoevda173ab2006-08-30 10:39:17 +0000849ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
850{
851 ngx_int_t rc;
852
853 /*
854 * generic phase checker,
855 * used by the post read, server rewrite, rewrite, and pre-access phases
856 */
857
858 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
859 "generic phase: %ui", r->phase_handler);
860
861 rc = ph->handler(r);
862
863 if (rc == NGX_OK) {
864 r->phase_handler = ph->next;
865 return NGX_AGAIN;
866 }
867
868 if (rc == NGX_DECLINED) {
869 r->phase_handler++;
870 return NGX_AGAIN;
871 }
872
873 if (rc == NGX_AGAIN || rc == NGX_DONE) {
874 return NGX_OK;
875 }
876
877 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
878
879 ngx_http_finalize_request(r, rc);
880
881 return NGX_OK;
882}
883
884
885ngx_int_t
886ngx_http_core_find_config_phase(ngx_http_request_t *r,
887 ngx_http_phase_handler_t *ph)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000888{
Igor Sysoev966e2a52007-08-15 15:57:26 +0000889 u_char *p;
890 size_t len;
Igor Sysoev303df472008-12-26 13:43:42 +0000891 ngx_int_t rc;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000892 ngx_http_core_loc_conf_t *clcf;
Igor Sysoeve2a31542003-04-08 15:40:10 +0000893
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000894 r->content_handler = NULL;
895 r->uri_changed = 0;
896
Igor Sysoeve55988c2008-05-24 14:14:13 +0000897 rc = ngx_http_core_find_location(r);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000898
Igor Sysoevdc911282008-08-17 18:02:55 +0000899 if (rc == NGX_ERROR) {
Igor Sysoevda173ab2006-08-30 10:39:17 +0000900 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
901 return NGX_OK;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000902 }
903
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000904 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
905
Igor Sysoev899b44e2005-05-12 14:58:06 +0000906 if (!r->internal && clcf->internal) {
Igor Sysoevda173ab2006-08-30 10:39:17 +0000907 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
908 return NGX_OK;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000909 }
910
Igor Sysoeva2573672005-10-05 14:46:21 +0000911 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
912 "using configuration \"%s%V\"",
913 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
914 &clcf->name);
915
Igor Sysoevb85fd592005-08-23 15:36:54 +0000916 ngx_http_update_location_config(r);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000917
918 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1765f472006-07-07 16:33:19 +0000919 "http cl:%O max:%O",
Igor Sysoev1b735832004-11-11 14:07:14 +0000920 r->headers_in.content_length_n, clcf->client_max_body_size);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000921
922 if (r->headers_in.content_length_n != -1
Igor Sysoev08e63d42006-08-14 15:09:38 +0000923 && !r->discard_body
Igor Sysoev89690bf2004-03-23 06:01:52 +0000924 && clcf->client_max_body_size
Igor Sysoev1765f472006-07-07 16:33:19 +0000925 && clcf->client_max_body_size < r->headers_in.content_length_n)
Igor Sysoev89690bf2004-03-23 06:01:52 +0000926 {
927 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoeve345d262007-10-18 15:53:38 +0000928 "client intended to send too large body: %O bytes",
Igor Sysoev89690bf2004-03-23 06:01:52 +0000929 r->headers_in.content_length_n);
930
Igor Sysoev21e3e052009-09-01 12:47:34 +0000931 (void) ngx_http_discard_request_body(r);
Igor Sysoevda173ab2006-08-30 10:39:17 +0000932 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
933 return NGX_OK;
Igor Sysoev89690bf2004-03-23 06:01:52 +0000934 }
935
Igor Sysoeve55988c2008-05-24 14:14:13 +0000936 if (rc == NGX_DONE) {
Igor Sysoevaab4d8c2004-09-06 18:45:00 +0000937 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
938 if (r->headers_out.location == NULL) {
Igor Sysoevda173ab2006-08-30 10:39:17 +0000939 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
940 return NGX_OK;
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000941 }
942
Igor Sysoev899b44e2005-05-12 14:58:06 +0000943 /*
944 * we do not need to set the r->headers_out.location->hash and
945 * r->headers_out.location->key fields
946 */
947
Igor Sysoev966e2a52007-08-15 15:57:26 +0000948 if (r->args.len == 0) {
949 r->headers_out.location->value = clcf->name;
950
951 } else {
952 len = clcf->name.len + 1 + r->args.len;
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +0000953 p = ngx_pnalloc(r->pool, len);
Igor Sysoev966e2a52007-08-15 15:57:26 +0000954
955 if (p == NULL) {
956 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
957 return NGX_OK;
958 }
959
960 r->headers_out.location->value.len = len;
961 r->headers_out.location->value.data = p;
962
963 p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
964 *p++ = '?';
965 ngx_memcpy(p, r->args.data, r->args.len);
966 }
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000967
Igor Sysoevda173ab2006-08-30 10:39:17 +0000968 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
969 return NGX_OK;
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000970 }
971
Igor Sysoevda173ab2006-08-30 10:39:17 +0000972 r->phase_handler++;
973 return NGX_AGAIN;
974}
975
976
977ngx_int_t
978ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
979 ngx_http_phase_handler_t *ph)
980{
Igor Sysoevb0780752008-06-15 19:07:35 +0000981 ngx_http_core_srv_conf_t *cscf;
982
Igor Sysoevda173ab2006-08-30 10:39:17 +0000983 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
984 "post rewrite phase: %ui", r->phase_handler);
985
986 if (!r->uri_changed) {
987 r->phase_handler++;
988 return NGX_AGAIN;
989 }
990
991 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
992 "uri changes: %d", r->uri_changes);
993
994 /*
995 * gcc before 3.3 compiles the broken code for
996 * if (r->uri_changes-- == 0)
997 * if the r->uri_changes is defined as
998 * unsigned uri_changes:4
999 */
1000
1001 r->uri_changes--;
1002
1003 if (r->uri_changes == 0) {
1004 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1005 "rewrite or internal redirection cycle "
1006 "while processing \"%V\"", &r->uri);
1007
1008 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1009 return NGX_OK;
1010 }
1011
1012 r->phase_handler = ph->next;
1013
Igor Sysoevb0780752008-06-15 19:07:35 +00001014 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1015 r->loc_conf = cscf->ctx->loc_conf;
1016
Igor Sysoevda173ab2006-08-30 10:39:17 +00001017 return NGX_AGAIN;
1018}
1019
1020
1021ngx_int_t
1022ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
1023{
1024 ngx_int_t rc;
1025 ngx_http_core_loc_conf_t *clcf;
1026
1027 if (r != r->main) {
1028 r->phase_handler = ph->next;
1029 return NGX_AGAIN;
1030 }
1031
1032 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1033 "access phase: %ui", r->phase_handler);
1034
1035 rc = ph->handler(r);
1036
1037 if (rc == NGX_DECLINED) {
1038 r->phase_handler++;
1039 return NGX_AGAIN;
1040 }
1041
1042 if (rc == NGX_AGAIN || rc == NGX_DONE) {
1043 return NGX_OK;
1044 }
1045
1046 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1047
Igor Sysoev2d028f82007-12-29 16:38:23 +00001048 if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
Igor Sysoevda173ab2006-08-30 10:39:17 +00001049
1050 if (rc == NGX_OK) {
1051 r->phase_handler++;
1052 return NGX_AGAIN;
1053 }
1054
1055 } else {
1056 if (rc == NGX_OK) {
1057 r->access_code = 0;
1058
1059 if (r->headers_out.www_authenticate) {
1060 r->headers_out.www_authenticate->hash = 0;
1061 }
1062
1063 r->phase_handler = ph->next;
1064 return NGX_AGAIN;
1065 }
1066
1067 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
1068 r->access_code = rc;
1069
1070 r->phase_handler++;
1071 return NGX_AGAIN;
1072 }
1073 }
1074
1075 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
1076
1077 ngx_http_finalize_request(r, rc);
1078 return NGX_OK;
1079}
1080
1081
1082ngx_int_t
1083ngx_http_core_post_access_phase(ngx_http_request_t *r,
1084 ngx_http_phase_handler_t *ph)
1085{
1086 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1087 "post access phase: %ui", r->phase_handler);
1088
1089 if (r->access_code) {
1090
1091 if (r->access_code == NGX_HTTP_FORBIDDEN) {
1092 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1093 "access forbidden by rule");
1094 }
1095
1096 ngx_http_finalize_request(r, r->access_code);
1097 return NGX_OK;
1098 }
1099
1100 r->phase_handler++;
1101 return NGX_AGAIN;
1102}
1103
1104
1105ngx_int_t
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001106ngx_http_core_try_files_phase(ngx_http_request_t *r,
1107 ngx_http_phase_handler_t *ph)
1108{
Igor Sysoev67392e82009-01-27 16:22:02 +00001109 size_t len, root, alias, reserve, allocated;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001110 u_char *p, *name;
Igor Sysoevb03aa7f2009-03-19 13:42:27 +00001111 ngx_str_t path, args;
Igor Sysoev319dc272009-01-21 12:11:22 +00001112 ngx_uint_t test_dir;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001113 ngx_http_try_file_t *tf;
1114 ngx_open_file_info_t of;
1115 ngx_http_script_code_pt code;
1116 ngx_http_script_engine_t e;
1117 ngx_http_core_loc_conf_t *clcf;
1118 ngx_http_script_len_code_pt lcode;
1119
1120 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1121 "try files phase: %ui", r->phase_handler);
1122
1123 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1124
1125 if (clcf->try_files == NULL) {
1126 r->phase_handler++;
1127 return NGX_AGAIN;
1128 }
1129
1130 allocated = 0;
1131 root = 0;
1132 name = NULL;
Igor Sysoev67392e82009-01-27 16:22:02 +00001133 /* suppress MSVC warning */
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001134 path.data = NULL;
1135
1136 tf = clcf->try_files;
1137
1138 alias = clcf->alias ? clcf->name.len : 0;
1139
1140 for ( ;; ) {
1141
1142 if (tf->lengths) {
1143 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
1144
1145 e.ip = tf->lengths->elts;
1146 e.request = r;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001147
1148 /* 1 is for terminating '\0' as in static names */
1149 len = 1;
1150
1151 while (*(uintptr_t *) e.ip) {
1152 lcode = *(ngx_http_script_len_code_pt *) e.ip;
1153 len += lcode(&e);
1154 }
1155
1156 } else {
1157 len = tf->name.len;
1158 }
1159
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001160 /* 16 bytes are preallocation */
Igor Sysoev42c67dd2009-03-01 19:10:36 +00001161 reserve = ngx_abs((ssize_t) (len - r->uri.len)) + alias + 16;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001162
1163 if (reserve > allocated) {
1164
1165 /* we just need to allocate path and to copy a root */
1166
1167 if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) {
1168 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1169 return NGX_OK;
1170 }
1171
1172 name = path.data + root;
1173 allocated = path.len - root - (r->uri.len - alias);
1174 }
1175
1176 if (tf->values == NULL) {
1177
1178 /* tf->name.len includes the terminating '\0' */
1179
1180 ngx_memcpy(name, tf->name.data, tf->name.len);
1181
1182 path.len = (name + tf->name.len - 1) - path.data;
1183
1184 } else {
1185 e.ip = tf->values->elts;
1186 e.pos = name;
Igor Sysoev195860b2008-12-24 07:14:01 +00001187 e.flushed = 1;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001188
1189 while (*(uintptr_t *) e.ip) {
1190 code = *(ngx_http_script_code_pt *) e.ip;
1191 code((ngx_http_script_engine_t *) &e);
1192 }
1193
1194 path.len = e.pos - path.data;
1195
Igor Sysoev51ed97f2009-03-14 17:10:25 +00001196 *e.pos = '\0';
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001197
1198 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
1199 ngx_memcpy(name, name + alias, len - alias);
1200 path.len -= alias;
1201 }
1202 }
1203
Igor Sysoev319dc272009-01-21 12:11:22 +00001204 test_dir = tf->test_dir;
1205
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001206 tf++;
1207
Igor Sysoevc7ce3a92009-03-20 16:50:53 +00001208 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1209 "try to use file: \"%s\" \"%s\"", name, path.data);
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001210
1211 if (tf->lengths == NULL && tf->name.len == 0) {
1212
Igor Sysoevecd82282009-04-11 11:02:36 +00001213 if (tf->code) {
1214 ngx_http_finalize_request(r, tf->code);
1215 return NGX_OK;
1216 }
1217
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001218 path.len -= root;
1219 path.data += root;
1220
1221 if (path.data[0] == '@') {
1222 (void) ngx_http_named_location(r, &path);
1223
1224 } else {
Igor Sysoevb03aa7f2009-03-19 13:42:27 +00001225 ngx_http_split_args(r, &path, &args);
1226
1227 (void) ngx_http_internal_redirect(r, &path, &args);
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001228 }
1229
Igor Sysoevfb30a182009-08-31 11:21:04 +00001230 ngx_http_finalize_request(r, NGX_DONE);
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001231 return NGX_OK;
1232 }
1233
1234 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
1235
1236 of.directio = clcf->directio;
1237 of.valid = clcf->open_file_cache_valid;
1238 of.min_uses = clcf->open_file_cache_min_uses;
Igor Sysoevf1cc4572009-04-27 09:55:53 +00001239 of.test_only = 1;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001240 of.errors = clcf->open_file_cache_errors;
1241 of.events = clcf->open_file_cache_events;
1242
1243 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
1244 != NGX_OK)
1245 {
Igor Sysoev7f6d71b2009-09-25 09:13:08 +00001246 if (of.err != NGX_ENOENT
1247 && of.err != NGX_ENOTDIR
1248 && of.err != NGX_ENAMETOOLONG)
1249 {
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001250 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
Igor Sysoevf1cc4572009-04-27 09:55:53 +00001251 "%s \"%s\" failed", of.failed, path.data);
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001252 }
1253
1254 continue;
1255 }
1256
Igor Sysoev319dc272009-01-21 12:11:22 +00001257 if (of.is_dir && !test_dir) {
Igor Sysoev977fd902009-01-19 11:24:25 +00001258 continue;
1259 }
1260
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001261 path.len -= root;
1262 path.data += root;
1263
1264 if (!alias) {
1265 r->uri = path;
1266
1267 } else {
1268 r->uri.len = alias + path.len;
1269 r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
1270 if (r->uri.data == NULL) {
1271 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1272 return NGX_OK;
1273 }
1274
1275 p = ngx_copy(r->uri.data, clcf->name.data, alias);
1276 ngx_memcpy(p, name, path.len);
1277 }
1278
Igor Sysoevc28d6322009-07-14 08:38:28 +00001279 ngx_http_set_exten(r);
Igor Sysoevb17bf522009-02-14 17:26:26 +00001280
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00001281 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1282 "try file uri: \"%V\"", &r->uri);
1283
1284 r->phase_handler++;
1285 return NGX_AGAIN;
1286 }
1287
1288 /* not reached */
1289}
1290
1291
1292ngx_int_t
Igor Sysoevda173ab2006-08-30 10:39:17 +00001293ngx_http_core_content_phase(ngx_http_request_t *r,
1294 ngx_http_phase_handler_t *ph)
1295{
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001296 size_t root;
Igor Sysoevda173ab2006-08-30 10:39:17 +00001297 ngx_int_t rc;
1298 ngx_str_t path;
1299
1300 if (r->content_handler) {
1301 r->write_event_handler = ngx_http_request_empty_handler;
1302 ngx_http_finalize_request(r, r->content_handler(r));
1303 return NGX_OK;
1304 }
1305
1306 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1307 "content phase: %ui", r->phase_handler);
1308
1309 rc = ph->handler(r);
1310
Igor Sysoevda173ab2006-08-30 10:39:17 +00001311 if (rc != NGX_DECLINED) {
1312 ngx_http_finalize_request(r, rc);
1313 return NGX_OK;
1314 }
1315
1316 /* rc == NGX_DECLINED */
1317
1318 ph++;
1319
1320 if (ph->checker) {
1321 r->phase_handler++;
1322 return NGX_AGAIN;
1323 }
1324
1325 /* no content handler was found */
1326
1327 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
1328
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001329 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
Igor Sysoevda173ab2006-08-30 10:39:17 +00001330 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev9d2811b2007-09-27 09:39:29 +00001331 "directory index of \"%s\" is forbidden", path.data);
Igor Sysoevda173ab2006-08-30 10:39:17 +00001332 }
1333
1334 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
1335 return NGX_OK;
1336 }
1337
1338 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
1339
1340 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
Igor Sysoevb85fd592005-08-23 15:36:54 +00001341 return NGX_OK;
1342}
1343
1344
1345void
1346ngx_http_update_location_config(ngx_http_request_t *r)
1347{
1348 ngx_http_core_loc_conf_t *clcf;
1349
1350 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1351
Igor Sysoev94e32ce2006-04-07 14:08:04 +00001352 if (r->method & clcf->limit_except) {
1353 r->loc_conf = clcf->limit_except_loc_conf;
1354 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1355 }
1356
Igor Sysoevb0518172006-04-26 15:21:08 +00001357 if (r == r->main) {
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00001358 r->connection->log->file = clcf->error_log->file;
Igor Sysoev4ca98f62007-03-28 14:38:33 +00001359
Igor Sysoevb0518172006-04-26 15:21:08 +00001360 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00001361 r->connection->log->log_level = clcf->error_log->log_level;
Igor Sysoevb0518172006-04-26 15:21:08 +00001362 }
Igor Sysoevb85fd592005-08-23 15:36:54 +00001363 }
1364
1365 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
1366 r->connection->sendfile = 1;
1367
1368 } else {
1369 r->connection->sendfile = 0;
1370 }
1371
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00001372 if (clcf->client_body_in_file_only) {
1373 r->request_body_in_file_only = 1;
1374 r->request_body_in_persistent_file = 1;
Igor Sysoevcd5b99a2007-01-25 08:45:04 +00001375 r->request_body_in_clean_file =
1376 clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
Igor Sysoev7bdb7202006-04-19 15:30:56 +00001377 r->request_body_file_log_level = NGX_LOG_NOTICE;
1378
1379 } else {
1380 r->request_body_file_log_level = NGX_LOG_WARN;
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00001381 }
1382
Igor Sysoevbfbded72009-05-14 11:41:33 +00001383 r->request_body_in_single_buf = clcf->client_body_in_single_buffer;
1384
Igor Sysoeve9591282009-05-25 15:38:36 +00001385 if (r->keepalive) {
1386 if (clcf->keepalive_timeout == 0) {
1387 r->keepalive = 0;
1388
1389 } else if (r->connection->requests >= clcf->keepalive_requests) {
1390 r->keepalive = 0;
1391 }
Igor Sysoevb85fd592005-08-23 15:36:54 +00001392 }
1393
1394 if (!clcf->tcp_nopush) {
1395 /* disable TCP_NOPUSH/TCP_CORK use */
1396 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
1397 }
1398
Igor Sysoevc2807ec2006-02-16 15:26:46 +00001399 if (r->limit_rate == 0) {
1400 r->limit_rate = clcf->limit_rate;
1401 }
Igor Sysoev5192b362005-07-08 14:34:20 +00001402
Igor Sysoev6253ca12003-05-27 12:18:54 +00001403 if (clcf->handler) {
Igor Sysoevb3e73d82003-10-10 15:10:50 +00001404 r->content_handler = clcf->handler;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001405 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001406}
1407
1408
Igor Sysoevdc911282008-08-17 18:02:55 +00001409/*
1410 * NGX_OK - exact or regex match
1411 * NGX_DONE - auto redirect
1412 * NGX_AGAIN - inclusive match
1413 * NGX_ERROR - regex error
1414 * NGX_DECLINED - no match
1415 */
1416
Igor Sysoevaa828612005-02-09 14:31:07 +00001417static ngx_int_t
Igor Sysoeve55988c2008-05-24 14:14:13 +00001418ngx_http_core_find_location(ngx_http_request_t *r)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001419{
Igor Sysoeve55988c2008-05-24 14:14:13 +00001420 ngx_int_t rc;
1421 ngx_http_core_loc_conf_t *pclcf;
Igor Sysoev9a702422008-08-17 17:58:16 +00001422#if (NGX_PCRE)
Igor Sysoevc05f20e2009-11-16 12:19:02 +00001423 ngx_int_t n;
Igor Sysoev9a702422008-08-17 17:58:16 +00001424 ngx_uint_t noregex;
1425 ngx_http_core_loc_conf_t *clcf, **clcfp;
1426
1427 noregex = 0;
1428#endif
Igor Sysoeve55988c2008-05-24 14:14:13 +00001429
1430 pclcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1431
1432 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
1433
1434 if (rc == NGX_AGAIN) {
Igor Sysoev9a702422008-08-17 17:58:16 +00001435
1436#if (NGX_PCRE)
1437 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1438
1439 noregex = clcf->noregex;
1440#endif
1441
Igor Sysoeve55988c2008-05-24 14:14:13 +00001442 /* look up nested locations */
Igor Sysoev9a702422008-08-17 17:58:16 +00001443
Igor Sysoeve55988c2008-05-24 14:14:13 +00001444 rc = ngx_http_core_find_location(r);
1445 }
1446
1447 if (rc == NGX_OK || rc == NGX_DONE) {
1448 return rc;
1449 }
1450
1451 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1452
1453#if (NGX_PCRE)
Igor Sysoeve55988c2008-05-24 14:14:13 +00001454
Igor Sysoev9a702422008-08-17 17:58:16 +00001455 if (noregex == 0 && pclcf->regex_locations) {
Igor Sysoeve55988c2008-05-24 14:14:13 +00001456
1457 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
1458
1459 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1460 "test location: ~ \"%V\"", &(*clcfp)->name);
1461
Igor Sysoevc05f20e2009-11-16 12:19:02 +00001462 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
Igor Sysoev925baa02009-03-06 12:49:22 +00001463
Igor Sysoevc05f20e2009-11-16 12:19:02 +00001464 if (n == NGX_OK) {
1465 r->loc_conf = (*clcfp)->loc_conf;
Igor Sysoev925baa02009-03-06 12:49:22 +00001466
Igor Sysoevc05f20e2009-11-16 12:19:02 +00001467 /* look up nested locations */
1468
1469 rc = ngx_http_core_find_location(r);
1470
1471 return (rc == NGX_ERROR) ? rc : NGX_OK;
Igor Sysoev925baa02009-03-06 12:49:22 +00001472 }
1473
Igor Sysoevc05f20e2009-11-16 12:19:02 +00001474 if (n == NGX_DECLINED) {
Igor Sysoeve55988c2008-05-24 14:14:13 +00001475 continue;
1476 }
1477
Igor Sysoevc05f20e2009-11-16 12:19:02 +00001478 return NGX_ERROR;
Igor Sysoeve55988c2008-05-24 14:14:13 +00001479 }
1480 }
Igor Sysoev307ab0d2007-08-12 15:25:09 +00001481#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001482
Igor Sysoeve55988c2008-05-24 14:14:13 +00001483 return rc;
1484}
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001485
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001486
Igor Sysoeve55988c2008-05-24 14:14:13 +00001487/*
1488 * NGX_OK - exact match
1489 * NGX_DONE - auto redirect
1490 * NGX_AGAIN - inclusive match
1491 * NGX_DECLINED - no match
1492 */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001493
Igor Sysoeve55988c2008-05-24 14:14:13 +00001494static ngx_int_t
1495ngx_http_core_find_static_location(ngx_http_request_t *r,
1496 ngx_http_location_tree_node_t *node)
1497{
1498 u_char *uri;
1499 size_t len, n;
1500 ngx_int_t rc, rv;
1501
1502 len = r->uri.len;
1503 uri = r->uri.data;
1504
1505 rv = NGX_DECLINED;
1506
1507 for ( ;; ) {
1508
1509 if (node == NULL) {
1510 return rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001511 }
1512
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001513 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoeve55988c2008-05-24 14:14:13 +00001514 "test location: \"%*s\"", node->len, node->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001515
Igor Sysoeve55988c2008-05-24 14:14:13 +00001516 n = (len <= (size_t) node->len) ? len : node->len;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001517
Igor Sysoev0f17f6c2008-07-29 16:55:11 +00001518 rc = ngx_filename_cmp(uri, node->name, n);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001519
Igor Sysoeve55988c2008-05-24 14:14:13 +00001520 if (rc != 0) {
1521 node = (rc < 0) ? node->left : node->right;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001522
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001523 continue;
1524 }
1525
Igor Sysoeve55988c2008-05-24 14:14:13 +00001526 if (len > (size_t) node->len) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001527
Igor Sysoeve55988c2008-05-24 14:14:13 +00001528 if (node->inclusive) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001529
Igor Sysoeve55988c2008-05-24 14:14:13 +00001530 r->loc_conf = node->inclusive->loc_conf;
1531 rv = NGX_AGAIN;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001532
Igor Sysoeve55988c2008-05-24 14:14:13 +00001533 node = node->tree;
1534 uri += n;
1535 len -= n;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001536
1537 continue;
Igor Sysoevea521232004-07-26 16:21:18 +00001538 }
1539
Igor Sysoeve55988c2008-05-24 14:14:13 +00001540 /* exact only */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001541
Igor Sysoeve55988c2008-05-24 14:14:13 +00001542 node = node->right;
Igor Sysoev307ab0d2007-08-12 15:25:09 +00001543
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001544 continue;
1545 }
1546
Igor Sysoeve55988c2008-05-24 14:14:13 +00001547 if (len == (size_t) node->len) {
1548
1549 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1550 node->inclusive->loc_conf;
1551 return NGX_OK;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001552 }
1553
Igor Sysoeve55988c2008-05-24 14:14:13 +00001554 /* len < node->len */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001555
Igor Sysoeve55988c2008-05-24 14:14:13 +00001556 if (len + 1 == (size_t) node->len && node->auto_redirect) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001557
Igor Sysoeve55988c2008-05-24 14:14:13 +00001558 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1559 node->inclusive->loc_conf;
1560 rv = NGX_DONE;
1561 }
1562
1563 node = node->left;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001564 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001565}
1566
1567
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001568void *
1569ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1570{
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001571 u_char c, *lowcase;
1572 size_t len;
1573 ngx_uint_t i, hash;
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001574
Igor Sysoev1cfb9722009-11-30 13:15:10 +00001575 if (types_hash->size == 0) {
1576 return (void *) 4;
1577 }
1578
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001579 if (r->headers_out.content_type.len == 0) {
1580 return NULL;
1581 }
1582
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001583 len = r->headers_out.content_type_len;
1584
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001585 if (r->headers_out.content_type_lowcase == NULL) {
1586
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001587 lowcase = ngx_pnalloc(r->pool, len);
1588 if (lowcase == NULL) {
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001589 return NULL;
1590 }
1591
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001592 r->headers_out.content_type_lowcase = lowcase;
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001593
1594 hash = 0;
1595
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001596 for (i = 0; i < len; i++) {
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001597 c = ngx_tolower(r->headers_out.content_type.data[i]);
1598 hash = ngx_hash(hash, c);
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001599 lowcase[i] = c;
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001600 }
1601
1602 r->headers_out.content_type_hash = hash;
1603 }
1604
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001605 return ngx_hash_find(types_hash, r->headers_out.content_type_hash,
1606 r->headers_out.content_type_lowcase, len);
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001607}
1608
1609
Igor Sysoevaa828612005-02-09 14:31:07 +00001610ngx_int_t
1611ngx_http_set_content_type(ngx_http_request_t *r)
Igor Sysoev865c1502003-11-30 20:03:18 +00001612{
Igor Sysoev6a078332008-08-04 10:18:36 +00001613 u_char c, *exten;
Igor Sysoev24025022005-12-16 15:07:08 +00001614 ngx_str_t *type;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001615 ngx_uint_t i, hash;
Igor Sysoev865c1502003-11-30 20:03:18 +00001616 ngx_http_core_loc_conf_t *clcf;
1617
Igor Sysoev08e63d42006-08-14 15:09:38 +00001618 if (r->headers_out.content_type.len) {
1619 return NGX_OK;
1620 }
1621
Igor Sysoev865c1502003-11-30 20:03:18 +00001622 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1623
1624 if (r->exten.len) {
Igor Sysoev805d9db2005-02-03 19:33:37 +00001625
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001626 hash = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001627
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001628 for (i = 0; i < r->exten.len; i++) {
1629 c = r->exten.data[i];
1630
1631 if (c >= 'A' && c <= 'Z') {
1632
Igor Sysoev6a078332008-08-04 10:18:36 +00001633 exten = ngx_pnalloc(r->pool, r->exten.len);
1634 if (exten == NULL) {
Igor Sysoev1f4220e2009-02-24 10:42:23 +00001635 return NGX_ERROR;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001636 }
1637
Igor Sysoev6a078332008-08-04 10:18:36 +00001638 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001639
1640 r->exten.data = exten;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001641
1642 break;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001643 }
1644
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001645 hash = ngx_hash(hash, c);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001646 }
1647
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001648 type = ngx_hash_find(&clcf->types_hash, hash,
Igor Sysoev24025022005-12-16 15:07:08 +00001649 r->exten.data, r->exten.len);
Igor Sysoev865c1502003-11-30 20:03:18 +00001650
Igor Sysoev24025022005-12-16 15:07:08 +00001651 if (type) {
Igor Sysoevef809b82006-06-28 16:00:26 +00001652 r->headers_out.content_type_len = type->len;
Igor Sysoev24025022005-12-16 15:07:08 +00001653 r->headers_out.content_type = *type;
Igor Sysoevef809b82006-06-28 16:00:26 +00001654
Igor Sysoev24025022005-12-16 15:07:08 +00001655 return NGX_OK;
Igor Sysoev865c1502003-11-30 20:03:18 +00001656 }
1657 }
1658
Igor Sysoevef809b82006-06-28 16:00:26 +00001659 r->headers_out.content_type_len = clcf->default_type.len;
Igor Sysoev24025022005-12-16 15:07:08 +00001660 r->headers_out.content_type = clcf->default_type;
Igor Sysoev865c1502003-11-30 20:03:18 +00001661
1662 return NGX_OK;
1663}
1664
1665
Igor Sysoevc28d6322009-07-14 08:38:28 +00001666void
Igor Sysoevaa828612005-02-09 14:31:07 +00001667ngx_http_set_exten(ngx_http_request_t *r)
Igor Sysoev3b30a902003-12-25 20:26:58 +00001668{
1669 ngx_int_t i;
1670
1671 r->exten.len = 0;
1672 r->exten.data = NULL;
1673
1674 for (i = r->uri.len - 1; i > 1; i--) {
1675 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001676
Igor Sysoev3b30a902003-12-25 20:26:58 +00001677 r->exten.len = r->uri.len - i - 1;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001678 r->exten.data = &r->uri.data[i + 1];
Igor Sysoev3b30a902003-12-25 20:26:58 +00001679
Igor Sysoevc28d6322009-07-14 08:38:28 +00001680 return;
Igor Sysoev3b30a902003-12-25 20:26:58 +00001681
1682 } else if (r->uri.data[i] == '/') {
Igor Sysoevc28d6322009-07-14 08:38:28 +00001683 return;
Igor Sysoev3b30a902003-12-25 20:26:58 +00001684 }
1685 }
1686
Igor Sysoevc28d6322009-07-14 08:38:28 +00001687 return;
Igor Sysoev3b30a902003-12-25 20:26:58 +00001688}
1689
1690
Igor Sysoevaa828612005-02-09 14:31:07 +00001691ngx_int_t
Igor Sysoev208eed22005-10-07 13:30:52 +00001692ngx_http_send_header(ngx_http_request_t *r)
1693{
1694 if (r->err_status) {
1695 r->headers_out.status = r->err_status;
1696 r->headers_out.status_line.len = 0;
1697 }
1698
1699 return ngx_http_top_header_filter(r);
1700}
1701
1702
1703ngx_int_t
1704ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1705{
Igor Sysoev8bb39122009-05-08 14:31:59 +00001706 ngx_int_t rc;
1707 ngx_connection_t *c;
Igor Sysoev208eed22005-10-07 13:30:52 +00001708
Igor Sysoev8bb39122009-05-08 14:31:59 +00001709 c = r->connection;
1710
1711 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001712 "http output filter \"%V?%V\"", &r->uri, &r->args);
Igor Sysoev208eed22005-10-07 13:30:52 +00001713
1714 rc = ngx_http_top_body_filter(r, in);
1715
1716 if (rc == NGX_ERROR) {
1717 /* NGX_ERROR may be returned by any filter */
Igor Sysoev8bb39122009-05-08 14:31:59 +00001718 c->error = 1;
Igor Sysoev208eed22005-10-07 13:30:52 +00001719 }
1720
1721 return rc;
1722}
1723
1724
1725u_char *
1726ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001727 size_t *root_length, size_t reserved)
Igor Sysoev208eed22005-10-07 13:30:52 +00001728{
Igor Sysoev8fea8852006-03-15 09:53:04 +00001729 u_char *last;
1730 size_t alias;
1731 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev208eed22005-10-07 13:30:52 +00001732
1733 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1734
1735 alias = clcf->alias ? clcf->name.len : 0;
1736
Igor Sysoev34303462006-01-24 16:08:27 +00001737 if (alias && !r->valid_location) {
1738 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1739 "\"alias\" could not be used in location \"%V\" "
1740 "where URI was rewritten", &clcf->name);
1741 return NULL;
1742 }
1743
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001744 if (clcf->root_lengths == NULL) {
Igor Sysoev208eed22005-10-07 13:30:52 +00001745
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001746 *root_length = clcf->root.len;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001747
Igor Sysoevbb7d6152009-03-14 19:20:34 +00001748 path->len = clcf->root.len + reserved + r->uri.len - alias + 1;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001749
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +00001750 path->data = ngx_pnalloc(r->pool, path->len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001751 if (path->data == NULL) {
1752 return NULL;
1753 }
1754
1755 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001756
Igor Sysoev8fea8852006-03-15 09:53:04 +00001757 } else {
Igor Sysoev1e5ef6b2009-03-26 15:24:19 +00001758
1759#if (NGX_PCRE)
1760 ngx_uint_t captures;
1761
Igor Sysoevc05f20e2009-11-16 12:19:02 +00001762 captures = alias && clcf->regex;
Igor Sysoev1e5ef6b2009-03-26 15:24:19 +00001763 reserved += captures ? 1 : r->uri.len - alias + 1;
1764#else
1765 reserved += r->uri.len - alias + 1;
1766#endif
Igor Sysoevf76a6c22009-03-18 12:21:19 +00001767
1768 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
Igor Sysoevc55a1042006-08-09 19:59:45 +00001769 clcf->root_values->elts)
Igor Sysoev8f125582006-07-28 15:16:17 +00001770 == NULL)
1771 {
1772 return NULL;
1773 }
1774
Igor Sysoev1f4220e2009-02-24 10:42:23 +00001775 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) {
Igor Sysoev8fea8852006-03-15 09:53:04 +00001776 return NULL;
1777 }
1778
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001779 *root_length = path->len - reserved;
1780 last = path->data + *root_length;
Igor Sysoev925baa02009-03-06 12:49:22 +00001781
Igor Sysoev1e5ef6b2009-03-26 15:24:19 +00001782#if (NGX_PCRE)
1783 if (captures) {
Igor Sysoev925baa02009-03-06 12:49:22 +00001784 *last = '\0';
1785 return last;
1786 }
Igor Sysoev1e5ef6b2009-03-26 15:24:19 +00001787#endif
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001788 }
1789
Igor Sysoev8fea8852006-03-15 09:53:04 +00001790 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
Igor Sysoev208eed22005-10-07 13:30:52 +00001791
1792 return last;
1793}
1794
1795
1796ngx_int_t
Igor Sysoevceb99292005-09-06 16:09:32 +00001797ngx_http_auth_basic_user(ngx_http_request_t *r)
1798{
1799 ngx_str_t auth, encoded;
1800 ngx_uint_t len;
1801
1802 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1803 return NGX_DECLINED;
1804 }
1805
1806 if (r->headers_in.authorization == NULL) {
1807 r->headers_in.user.data = (u_char *) "";
1808 return NGX_DECLINED;
1809 }
1810
1811 encoded = r->headers_in.authorization->value;
1812
1813 if (encoded.len < sizeof("Basic ") - 1
Igor Sysoev722231f2007-02-14 18:51:19 +00001814 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
1815 sizeof("Basic ") - 1)
1816 != 0)
Igor Sysoevceb99292005-09-06 16:09:32 +00001817 {
1818 r->headers_in.user.data = (u_char *) "";
1819 return NGX_DECLINED;
1820 }
1821
1822 encoded.len -= sizeof("Basic ") - 1;
1823 encoded.data += sizeof("Basic ") - 1;
1824
1825 while (encoded.len && encoded.data[0] == ' ') {
1826 encoded.len--;
1827 encoded.data++;
1828 }
1829
1830 if (encoded.len == 0) {
1831 r->headers_in.user.data = (u_char *) "";
1832 return NGX_DECLINED;
1833 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001834
Igor Sysoevceb99292005-09-06 16:09:32 +00001835 auth.len = ngx_base64_decoded_length(encoded.len);
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +00001836 auth.data = ngx_pnalloc(r->pool, auth.len + 1);
Igor Sysoevceb99292005-09-06 16:09:32 +00001837 if (auth.data == NULL) {
1838 return NGX_ERROR;
1839 }
1840
1841 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
1842 r->headers_in.user.data = (u_char *) "";
1843 return NGX_DECLINED;
1844 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001845
Igor Sysoevceb99292005-09-06 16:09:32 +00001846 auth.data[auth.len] = '\0';
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001847
1848 for (len = 0; len < auth.len; len++) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001849 if (auth.data[len] == ':') {
1850 break;
1851 }
1852 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001853
Igor Sysoev09c684b2005-11-09 17:25:55 +00001854 if (len == 0 || len == auth.len) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001855 r->headers_in.user.data = (u_char *) "";
1856 return NGX_DECLINED;
1857 }
1858
1859 r->headers_in.user.len = len;
1860 r->headers_in.user.data = auth.data;
1861 r->headers_in.passwd.len = auth.len - len - 1;
1862 r->headers_in.passwd.data = &auth.data[len + 1];
1863
1864 return NGX_OK;
1865}
1866
1867
Igor Sysoevc16b0052007-12-27 14:21:59 +00001868#if (NGX_HTTP_GZIP)
1869
1870ngx_int_t
1871ngx_http_gzip_ok(ngx_http_request_t *r)
1872{
1873 time_t date, expires;
1874 ngx_uint_t p;
1875 ngx_array_t *cc;
1876 ngx_table_elt_t *e, *d;
1877 ngx_http_core_loc_conf_t *clcf;
1878
Igor Sysoev6c49a5a2009-11-12 13:41:56 +00001879 r->gzip_tested = 1;
Igor Sysoevc16b0052007-12-27 14:21:59 +00001880
1881 if (r != r->main
1882 || r->headers_in.accept_encoding == NULL
1883 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
1884 "gzip", 4 - 1)
1885 == NULL
1886
1887 /*
1888 * if the URL (without the "http://" prefix) is longer than 253 bytes,
1889 * then MSIE 4.x can not handle the compressed stream - it waits
1890 * too long, hangs up or crashes
1891 */
1892
1893 || (r->headers_in.msie4 && r->unparsed_uri.len > 200))
1894 {
1895 return NGX_DECLINED;
1896 }
1897
1898 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1899
Igor Sysoev54477e42008-08-26 15:09:28 +00001900 if (r->headers_in.msie6 && clcf->gzip_disable_msie6) {
1901 return NGX_DECLINED;
1902 }
1903
Igor Sysoevc16b0052007-12-27 14:21:59 +00001904 if (r->http_version < clcf->gzip_http_version) {
1905 return NGX_DECLINED;
1906 }
1907
1908 if (r->headers_in.via == NULL) {
1909 goto ok;
1910 }
1911
1912 p = clcf->gzip_proxied;
1913
1914 if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
1915 return NGX_DECLINED;
1916 }
1917
1918 if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
1919 goto ok;
1920 }
1921
1922 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
1923 goto ok;
1924 }
1925
1926 e = r->headers_out.expires;
1927
1928 if (e) {
1929
1930 if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
1931 return NGX_DECLINED;
1932 }
1933
1934 expires = ngx_http_parse_time(e->value.data, e->value.len);
1935 if (expires == NGX_ERROR) {
1936 return NGX_DECLINED;
1937 }
1938
1939 d = r->headers_out.date;
1940
1941 if (d) {
1942 date = ngx_http_parse_time(d->value.data, d->value.len);
1943 if (date == NGX_ERROR) {
1944 return NGX_DECLINED;
1945 }
1946
1947 } else {
1948 date = ngx_time();
1949 }
1950
1951 if (expires < date) {
1952 goto ok;
1953 }
1954
1955 return NGX_DECLINED;
1956 }
1957
1958 cc = &r->headers_out.cache_control;
1959
1960 if (cc->elts) {
1961
1962 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
1963 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
1964 NULL)
1965 >= 0)
1966 {
1967 goto ok;
1968 }
1969
1970 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
1971 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
1972 NULL)
1973 >= 0)
1974 {
1975 goto ok;
1976 }
1977
1978 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
1979 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
1980 NULL)
1981 >= 0)
1982 {
1983 goto ok;
1984 }
1985
1986 return NGX_DECLINED;
1987 }
1988
1989 if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
1990 return NGX_DECLINED;
1991 }
1992
1993 if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
1994 return NGX_DECLINED;
1995 }
1996
1997ok:
1998
1999#if (NGX_PCRE)
2000
2001 if (clcf->gzip_disable && r->headers_in.user_agent) {
2002
Igor Sysoevd5fe8182007-12-28 13:15:36 +00002003 if (ngx_regex_exec_array(clcf->gzip_disable,
Igor Sysoevc16b0052007-12-27 14:21:59 +00002004 &r->headers_in.user_agent->value,
2005 r->connection->log)
2006 != NGX_DECLINED)
2007 {
2008 return NGX_DECLINED;
2009 }
2010 }
2011
2012#endif
2013
Igor Sysoev6c49a5a2009-11-12 13:41:56 +00002014 r->gzip_ok = 1;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002015
2016 return NGX_OK;
2017}
2018
2019#endif
2020
2021
Igor Sysoevceb99292005-09-06 16:09:32 +00002022ngx_int_t
Igor Sysoev899b44e2005-05-12 14:58:06 +00002023ngx_http_subrequest(ngx_http_request_t *r,
Igor Sysoev9fcccaf2006-10-10 14:30:39 +00002024 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
Igor Sysoev960100e2006-10-13 15:20:10 +00002025 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
Igor Sysoev899b44e2005-05-12 14:58:06 +00002026{
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002027 ngx_connection_t *c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002028 ngx_http_request_t *sr;
2029 ngx_http_core_srv_conf_t *cscf;
2030 ngx_http_postponed_request_t *pr, *p;
2031
Igor Sysoevef809b82006-06-28 16:00:26 +00002032 r->main->subrequests--;
2033
2034 if (r->main->subrequests == 0) {
2035 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002036 "subrequests cycle while processing \"%V\"", uri);
Igor Sysoev5fd6d342006-11-02 13:48:28 +00002037 r->main->subrequests = 1;
Igor Sysoevef809b82006-06-28 16:00:26 +00002038 return NGX_ERROR;
2039 }
2040
Igor Sysoev899b44e2005-05-12 14:58:06 +00002041 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
2042 if (sr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002043 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002044 }
2045
2046 sr->signature = NGX_HTTP_MODULE;
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002047
2048 c = r->connection;
2049 sr->connection = c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002050
2051 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
2052 if (sr->ctx == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002053 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002054 }
2055
2056 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
Igor Sysoevc31a9bb2005-11-26 10:11:11 +00002057 sizeof(ngx_table_elt_t))
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002058 != NGX_OK)
Igor Sysoev899b44e2005-05-12 14:58:06 +00002059 {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002060 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002061 }
2062
2063 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2064 sr->main_conf = cscf->ctx->main_conf;
2065 sr->srv_conf = cscf->ctx->srv_conf;
2066 sr->loc_conf = cscf->ctx->loc_conf;
2067
2068 sr->pool = r->pool;
2069
2070 sr->headers_in = r->headers_in;
2071
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002072 ngx_http_clear_content_length(sr);
2073 ngx_http_clear_accept_ranges(sr);
2074 ngx_http_clear_last_modified(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002075
2076 sr->request_body = r->request_body;
2077
2078 sr->method = NGX_HTTP_GET;
2079 sr->http_version = r->http_version;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002080
2081 sr->request_line = r->request_line;
2082 sr->uri = *uri;
Igor Sysoev09c684b2005-11-09 17:25:55 +00002083
Igor Sysoev899b44e2005-05-12 14:58:06 +00002084 if (args) {
2085 sr->args = *args;
2086 }
Igor Sysoev09c684b2005-11-09 17:25:55 +00002087
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002088 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
2089 "http subrequest \"%V?%V\"", uri, &sr->args);
2090
Igor Sysoev960100e2006-10-13 15:20:10 +00002091 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;
2092 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
Igor Sysoev851cd732008-12-08 14:23:20 +00002093 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
Igor Sysoev09c684b2005-11-09 17:25:55 +00002094
Igor Sysoev899b44e2005-05-12 14:58:06 +00002095 sr->unparsed_uri = r->unparsed_uri;
Igor Sysoev5a45c682008-01-08 21:06:38 +00002096 sr->method_name = ngx_http_core_get_method;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002097 sr->http_protocol = r->http_protocol;
2098
Igor Sysoevc28d6322009-07-14 08:38:28 +00002099 ngx_http_set_exten(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002100
Igor Sysoevf6e1fe32005-10-04 10:38:53 +00002101 sr->main = r->main;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002102 sr->parent = r;
Igor Sysoev960100e2006-10-13 15:20:10 +00002103 sr->post_subrequest = ps;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002104 sr->read_event_handler = ngx_http_request_empty_handler;
Igor Sysoev851cd732008-12-08 14:23:20 +00002105 sr->write_event_handler = ngx_http_handler;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002106
Igor Sysoevd8e54ad2008-12-24 06:11:04 +00002107 if (c->data == r && r->postponed == NULL) {
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002108 c->data = sr;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002109 }
2110
Igor Sysoev899b44e2005-05-12 14:58:06 +00002111 sr->variables = r->variables;
2112
2113 sr->log_handler = r->log_handler;
2114
2115 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
2116 if (pr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002117 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002118 }
2119
2120 pr->request = sr;
2121 pr->out = NULL;
2122 pr->next = NULL;
2123
2124 if (r->postponed) {
2125 for (p = r->postponed; p->next; p = p->next) { /* void */ }
2126 p->next = pr;
2127
2128 } else {
2129 r->postponed = pr;
2130 }
2131
2132 sr->internal = 1;
2133
Igor Sysoev31eb8c02005-09-23 11:02:22 +00002134 sr->discard_body = r->discard_body;
Igor Sysoev303df472008-12-26 13:43:42 +00002135 sr->expect_tested = 1;
Igor Sysoevd52477f2005-05-16 13:53:20 +00002136 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
2137
Igor Sysoev6f134cc2006-05-23 14:54:58 +00002138 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
2139
Igor Sysoev851cd732008-12-08 14:23:20 +00002140 r->main->subrequests++;
Igor Sysoevb603dd42009-08-26 16:04:05 +00002141 r->main->count++;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002142
Igor Sysoev851cd732008-12-08 14:23:20 +00002143 *psr = sr;
Igor Sysoevac72bd12006-05-04 15:32:46 +00002144
Igor Sysoevddda4112009-08-30 09:47:11 +00002145 return ngx_http_post_request(sr, NULL);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002146}
2147
2148
2149ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +00002150ngx_http_internal_redirect(ngx_http_request_t *r,
2151 ngx_str_t *uri, ngx_str_t *args)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002152{
Igor Sysoevaa828612005-02-09 14:31:07 +00002153 ngx_http_core_srv_conf_t *cscf;
2154
Igor Sysoev5fede1e2006-08-18 14:17:54 +00002155 r->uri_changes--;
2156
2157 if (r->uri_changes == 0) {
2158 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002159 "rewrite or internal redirection cycle "
2160 "while internal redirect to \"%V\"", uri);
2161
Igor Sysoev526f36a2009-09-10 16:34:09 +00002162 r->main->count++;
Igor Sysoev5fede1e2006-08-18 14:17:54 +00002163 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2164 return NGX_DONE;
2165 }
2166
Igor Sysoev1b735832004-11-11 14:07:14 +00002167 r->uri = *uri;
Igor Sysoev13933252003-05-29 13:02:09 +00002168
2169 if (args) {
Igor Sysoev1b735832004-11-11 14:07:14 +00002170 r->args = *args;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002171
2172 } else {
2173 r->args.len = 0;
2174 r->args.data = NULL;
Igor Sysoev13933252003-05-29 13:02:09 +00002175 }
2176
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002177 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2178 "internal redirect: \"%V?%V\"", uri, &r->args);
2179
Igor Sysoevc28d6322009-07-14 08:38:28 +00002180 ngx_http_set_exten(r);
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002181
Igor Sysoevef316432006-08-16 13:09:33 +00002182 /* clear the modules contexts */
2183 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
Igor Sysoev0a280a32003-10-12 16:49:16 +00002184
Igor Sysoevaa828612005-02-09 14:31:07 +00002185 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2186 r->loc_conf = cscf->ctx->loc_conf;
2187
Igor Sysoevb85fd592005-08-23 15:36:54 +00002188 ngx_http_update_location_config(r);
2189
Igor Sysoev52859f22009-03-23 13:14:51 +00002190#if (NGX_HTTP_CACHE)
2191 r->cache = NULL;
2192#endif
2193
Igor Sysoev899b44e2005-05-12 14:58:06 +00002194 r->internal = 1;
Igor Sysoevb603dd42009-08-26 16:04:05 +00002195 r->main->count++;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002196
Igor Sysoev79a80482003-05-14 17:13:13 +00002197 ngx_http_handler(r);
Igor Sysoev13933252003-05-29 13:02:09 +00002198
Igor Sysoev9760a132003-10-21 07:47:21 +00002199 return NGX_DONE;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002200}
2201
2202
Igor Sysoev8889b652007-07-29 18:11:39 +00002203ngx_int_t
2204ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
2205{
Igor Sysoev8889b652007-07-29 18:11:39 +00002206 ngx_http_core_srv_conf_t *cscf;
2207 ngx_http_core_loc_conf_t **clcfp;
2208 ngx_http_core_main_conf_t *cmcf;
2209
Igor Sysoevb603dd42009-08-26 16:04:05 +00002210 r->main->count++;
2211
Igor Sysoev8889b652007-07-29 18:11:39 +00002212 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2213
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002214 if (cscf->named_locations) {
Igor Sysoev8889b652007-07-29 18:11:39 +00002215
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002216 for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
Igor Sysoev8889b652007-07-29 18:11:39 +00002217
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002218 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2219 "test location: \"%V\"", &(*clcfp)->name);
2220
2221 if (name->len != (*clcfp)->name.len
2222 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
2223 {
2224 continue;
2225 }
2226
2227 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2228 "using location: %V \"%V?%V\"",
2229 name, &r->uri, &r->args);
2230
2231 r->internal = 1;
2232 r->content_handler = NULL;
2233 r->loc_conf = (*clcfp)->loc_conf;
2234
2235 ngx_http_update_location_config(r);
2236
2237 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2238
2239 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
2240
2241 ngx_http_core_run_phases(r);
2242
2243 return NGX_DONE;
Igor Sysoev8889b652007-07-29 18:11:39 +00002244 }
Igor Sysoev8889b652007-07-29 18:11:39 +00002245 }
2246
2247 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev9e039cf2007-10-22 10:15:48 +00002248 "could not find named location \"%V\"", name);
Igor Sysoev8889b652007-07-29 18:11:39 +00002249
2250 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
Igor Sysoeve55988c2008-05-24 14:14:13 +00002251
Igor Sysoev8889b652007-07-29 18:11:39 +00002252 return NGX_DONE;
2253}
2254
2255
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002256ngx_http_cleanup_t *
2257ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
Igor Sysoev0a280a32003-10-12 16:49:16 +00002258{
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002259 ngx_http_cleanup_t *cln;
Igor Sysoev0a280a32003-10-12 16:49:16 +00002260
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002261 r = r->main;
2262
2263 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
2264 if (cln == NULL) {
2265 return NULL;
Igor Sysoev0a280a32003-10-12 16:49:16 +00002266 }
2267
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002268 if (size) {
2269 cln->data = ngx_palloc(r->pool, size);
2270 if (cln->data == NULL) {
2271 return NULL;
2272 }
Igor Sysoev0a280a32003-10-12 16:49:16 +00002273
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002274 } else {
2275 cln->data = NULL;
2276 }
2277
2278 cln->handler = NULL;
2279 cln->next = r->cleanup;
2280
2281 r->cleanup = cln;
2282
2283 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2284 "http cleanup add: %p", cln);
2285
2286 return cln;
2287}
Igor Sysoev0a280a32003-10-12 16:49:16 +00002288
2289
Igor Sysoevaa828612005-02-09 14:31:07 +00002290static char *
2291ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002292{
Igor Sysoevc9151062007-06-05 06:44:08 +00002293 char *rv;
2294 void *mconf;
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002295 ngx_uint_t i;
Igor Sysoevc9151062007-06-05 06:44:08 +00002296 ngx_conf_t pcf;
2297 ngx_http_module_t *module;
2298 ngx_http_conf_ctx_t *ctx, *http_ctx;
2299 ngx_http_core_srv_conf_t *cscf, **cscfp;
Igor Sysoev8889b652007-07-29 18:11:39 +00002300 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002301
Igor Sysoevc1571722005-03-19 12:38:37 +00002302 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2303 if (ctx == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002304 return NGX_CONF_ERROR;
2305 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002306
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002307 http_ctx = cf->ctx;
2308 ctx->main_conf = http_ctx->main_conf;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002309
Igor Sysoeva9830112003-05-19 16:39:14 +00002310 /* the server{}'s srv_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002311
Igor Sysoevaa828612005-02-09 14:31:07 +00002312 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2313 if (ctx->srv_conf == NULL) {
2314 return NGX_CONF_ERROR;
2315 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002316
Igor Sysoeva9830112003-05-19 16:39:14 +00002317 /* the server{}'s loc_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002318
Igor Sysoevaa828612005-02-09 14:31:07 +00002319 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2320 if (ctx->loc_conf == NULL) {
2321 return NGX_CONF_ERROR;
2322 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002323
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002324 for (i = 0; ngx_modules[i]; i++) {
2325 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002326 continue;
2327 }
2328
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002329 module = ngx_modules[i]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002330
2331 if (module->create_srv_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002332 mconf = module->create_srv_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->srv_conf[ngx_modules[i]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002338 }
2339
2340 if (module->create_loc_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002341 mconf = module->create_loc_conf(cf);
2342 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002343 return NGX_CONF_ERROR;
2344 }
2345
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002346 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002347 }
2348 }
2349
Igor Sysoevaa828612005-02-09 14:31:07 +00002350
2351 /* the server configuration context */
Igor Sysoeva9830112003-05-19 16:39:14 +00002352
Igor Sysoev6253ca12003-05-27 12:18:54 +00002353 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00002354 cscf->ctx = ctx;
2355
Igor Sysoevaa828612005-02-09 14:31:07 +00002356
Igor Sysoev6253ca12003-05-27 12:18:54 +00002357 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
Igor Sysoevaa828612005-02-09 14:31:07 +00002358
Igor Sysoevc1571722005-03-19 12:38:37 +00002359 cscfp = ngx_array_push(&cmcf->servers);
2360 if (cscfp == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002361 return NGX_CONF_ERROR;
2362 }
2363
Igor Sysoeva9830112003-05-19 16:39:14 +00002364 *cscfp = cscf;
2365
Igor Sysoevaa828612005-02-09 14:31:07 +00002366
Igor Sysoeva9830112003-05-19 16:39:14 +00002367 /* parse inside server{} */
2368
Igor Sysoev7b190b42005-06-07 15:56:31 +00002369 pcf = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002370 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00002371 cf->cmd_type = NGX_HTTP_SRV_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002372
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002373 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002374
Igor Sysoev7b190b42005-06-07 15:56:31 +00002375 *cf = pcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002376
Igor Sysoeva9830112003-05-19 16:39:14 +00002377 return rv;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002378}
2379
2380
Igor Sysoevaa828612005-02-09 14:31:07 +00002381static char *
2382ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002383{
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002384 char *rv;
Igor Sysoev22f6d862008-12-11 10:21:08 +00002385 u_char *mod;
2386 size_t len;
2387 ngx_str_t *value, *name;
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002388 ngx_uint_t i;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002389 ngx_conf_t save;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002390 ngx_http_module_t *module;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002391 ngx_http_conf_ctx_t *ctx, *pctx;
Igor Sysoeve55988c2008-05-24 14:14:13 +00002392 ngx_http_core_loc_conf_t *clcf, *pclcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002393
Igor Sysoevc1571722005-03-19 12:38:37 +00002394 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2395 if (ctx == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002396 return NGX_CONF_ERROR;
2397 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002398
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002399 pctx = cf->ctx;
2400 ctx->main_conf = pctx->main_conf;
2401 ctx->srv_conf = pctx->srv_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002402
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002403 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2404 if (ctx->loc_conf == NULL) {
2405 return NGX_CONF_ERROR;
2406 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002407
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002408 for (i = 0; ngx_modules[i]; i++) {
2409 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002410 continue;
2411 }
2412
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002413 module = ngx_modules[i]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002414
2415 if (module->create_loc_conf) {
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002416 ctx->loc_conf[ngx_modules[i]->ctx_index] =
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002417 module->create_loc_conf(cf);
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002418 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002419 return NGX_CONF_ERROR;
2420 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002421 }
2422 }
2423
Igor Sysoev6253ca12003-05-27 12:18:54 +00002424 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00002425 clcf->loc_conf = ctx->loc_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002426
Igor Sysoev3b30a902003-12-25 20:26:58 +00002427 value = cf->args->elts;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002428
2429 if (cf->args->nelts == 3) {
Igor Sysoev22f6d862008-12-11 10:21:08 +00002430
2431 len = value[1].len;
2432 mod = value[1].data;
2433 name = &value[2];
2434
2435 if (len == 1 && mod[0] == '=') {
2436
2437 clcf->name = *name;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002438 clcf->exact_match = 1;
2439
Igor Sysoev22f6d862008-12-11 10:21:08 +00002440 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
2441
2442 clcf->name = *name;
Igor Sysoevd43bee82004-11-20 19:52:20 +00002443 clcf->noregex = 1;
2444
Igor Sysoev22f6d862008-12-11 10:21:08 +00002445 } else if (len == 1 && mod[0] == '~') {
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00002446
Igor Sysoev22f6d862008-12-11 10:21:08 +00002447 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002448 return NGX_CONF_ERROR;
2449 }
2450
Igor Sysoev22f6d862008-12-11 10:21:08 +00002451 } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
2452
2453 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2454 return NGX_CONF_ERROR;
2455 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002456
2457 } else {
2458 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002459 "invalid location modifier \"%V\"", &value[1]);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002460 return NGX_CONF_ERROR;
2461 }
2462
2463 } else {
Igor Sysoev8889b652007-07-29 18:11:39 +00002464
Igor Sysoev22f6d862008-12-11 10:21:08 +00002465 name = &value[1];
Igor Sysoev8889b652007-07-29 18:11:39 +00002466
Igor Sysoev22f6d862008-12-11 10:21:08 +00002467 if (name->data[0] == '=') {
2468
2469 clcf->name.len = name->len - 1;
2470 clcf->name.data = name->data + 1;
2471 clcf->exact_match = 1;
2472
2473 } else if (name->data[0] == '^' && name->data[1] == '~') {
2474
2475 clcf->name.len = name->len - 2;
2476 clcf->name.data = name->data + 2;
2477 clcf->noregex = 1;
2478
2479 } else if (name->data[0] == '~') {
2480
2481 name->len--;
2482 name->data++;
2483
2484 if (name->data[0] == '*') {
2485
2486 name->len--;
2487 name->data++;
2488
2489 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2490 return NGX_CONF_ERROR;
2491 }
2492
2493 } else {
2494 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2495 return NGX_CONF_ERROR;
2496 }
2497 }
2498
2499 } else {
2500
2501 clcf->name = *name;
2502
2503 if (name->data[0] == '@') {
2504 clcf->named = 1;
2505 }
Igor Sysoev8889b652007-07-29 18:11:39 +00002506 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002507 }
2508
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002509 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
2510
Igor Sysoeve55988c2008-05-24 14:14:13 +00002511 if (pclcf->name.len) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002512
Igor Sysoeve55988c2008-05-24 14:14:13 +00002513 /* nested location */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002514
Igor Sysoev805d9db2005-02-03 19:33:37 +00002515#if 0
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002516 clcf->prev_location = pclcf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002517#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002518
2519 if (pclcf->exact_match) {
2520 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002521 "location \"%V\" could not be inside "
2522 "the exact location \"%V\"",
2523 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002524 return NGX_CONF_ERROR;
2525 }
2526
Igor Sysoev8889b652007-07-29 18:11:39 +00002527 if (pclcf->named) {
2528 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2529 "location \"%V\" could not be inside "
2530 "the named location \"%V\"",
2531 &clcf->name, &pclcf->name);
2532 return NGX_CONF_ERROR;
2533 }
2534
Igor Sysoeve55988c2008-05-24 14:14:13 +00002535 if (clcf->named) {
2536 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2537 "named location \"%V\" must be "
2538 "on server level only",
2539 &clcf->name);
2540 return NGX_CONF_ERROR;
2541 }
2542
Igor Sysoev22f6d862008-12-11 10:21:08 +00002543 len = pclcf->name.len;
2544
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00002545#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002546 if (clcf->regex == NULL
Igor Sysoev22f6d862008-12-11 10:21:08 +00002547 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00002548#else
Igor Sysoev22f6d862008-12-11 10:21:08 +00002549 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00002550#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002551 {
2552 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002553 "location \"%V\" is outside location \"%V\"",
2554 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002555 return NGX_CONF_ERROR;
2556 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002557 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002558
Igor Sysoeve55988c2008-05-24 14:14:13 +00002559 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
2560 return NGX_CONF_ERROR;
2561 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002562
Igor Sysoev805d9db2005-02-03 19:33:37 +00002563 save = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002564 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00002565 cf->cmd_type = NGX_HTTP_LOC_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002566
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002567 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002568
2569 *cf = save;
2570
Igor Sysoev79a80482003-05-14 17:13:13 +00002571 return rv;
2572}
2573
2574
Igor Sysoev22f6d862008-12-11 10:21:08 +00002575static ngx_int_t
2576ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
2577 ngx_str_t *regex, ngx_uint_t caseless)
2578{
2579#if (NGX_PCRE)
Igor Sysoevc05f20e2009-11-16 12:19:02 +00002580 ngx_regex_compile_t rc;
2581 u_char errstr[NGX_MAX_CONF_ERRSTR];
Igor Sysoev22f6d862008-12-11 10:21:08 +00002582
Igor Sysoevc05f20e2009-11-16 12:19:02 +00002583 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
2584
2585 rc.pattern = *regex;
2586 rc.err.len = NGX_MAX_CONF_ERRSTR;
2587 rc.err.data = errstr;
Igor Sysoev22f6d862008-12-11 10:21:08 +00002588
Igor Sysoev2642bf12009-07-14 08:53:37 +00002589#if (NGX_HAVE_CASELESS_FILESYSTEM)
Igor Sysoevc05f20e2009-11-16 12:19:02 +00002590 rc.options = NGX_REGEX_CASELESS;
Igor Sysoev2642bf12009-07-14 08:53:37 +00002591#endif
2592
Igor Sysoevc05f20e2009-11-16 12:19:02 +00002593 clcf->regex = ngx_http_regex_compile(cf, &rc);
Igor Sysoev22f6d862008-12-11 10:21:08 +00002594 if (clcf->regex == NULL) {
Igor Sysoev22f6d862008-12-11 10:21:08 +00002595 return NGX_ERROR;
2596 }
2597
2598 clcf->name = *regex;
2599
2600 return NGX_OK;
2601
2602#else
2603
2604 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2605 "the using of the regex \"%V\" requires PCRE library",
2606 regex);
2607 return NGX_ERROR;
2608
2609#endif
2610}
2611
2612
Igor Sysoevaa828612005-02-09 14:31:07 +00002613static char *
2614ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev79a80482003-05-14 17:13:13 +00002615{
Igor Sysoev30870b42009-11-13 19:59:54 +00002616 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev7bdb7202006-04-19 15:30:56 +00002617
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002618 char *rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002619 ngx_conf_t save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002620
Igor Sysoev30870b42009-11-13 19:59:54 +00002621 if (clcf->types == NULL) {
2622 clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
2623 if (clcf->types == NULL) {
Igor Sysoev7bdb7202006-04-19 15:30:56 +00002624 return NGX_CONF_ERROR;
2625 }
2626 }
2627
Igor Sysoev805d9db2005-02-03 19:33:37 +00002628 save = *cf;
2629 cf->handler = ngx_http_core_type;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002630 cf->handler_conf = conf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002631
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002632 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002633
2634 *cf = save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002635
2636 return rv;
2637}
2638
2639
Igor Sysoevaa828612005-02-09 14:31:07 +00002640static char *
2641ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002642{
Igor Sysoev30870b42009-11-13 19:59:54 +00002643 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev79a80482003-05-14 17:13:13 +00002644
Igor Sysoeveba03e62007-03-29 10:27:24 +00002645 ngx_str_t *value, *content_type, *old, file;
Igor Sysoev6a078332008-08-04 10:18:36 +00002646 ngx_uint_t i, n, hash;
Igor Sysoev24025022005-12-16 15:07:08 +00002647 ngx_hash_key_t *type;
Igor Sysoev79a80482003-05-14 17:13:13 +00002648
Igor Sysoeveba03e62007-03-29 10:27:24 +00002649 value = cf->args->elts;
2650
2651 if (ngx_strcmp(value[0].data, "include") == 0) {
2652 file = value[1];
2653
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002654 if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
Igor Sysoeveba03e62007-03-29 10:27:24 +00002655 return NGX_CONF_ERROR;
2656 }
2657
2658 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
2659
2660 return ngx_conf_parse(cf, &file);
2661 }
2662
Igor Sysoev24025022005-12-16 15:07:08 +00002663 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
2664 if (content_type == NULL) {
2665 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00002666 }
2667
Igor Sysoev24025022005-12-16 15:07:08 +00002668 *content_type = value[0];
Igor Sysoev79a80482003-05-14 17:13:13 +00002669
2670 for (i = 1; i < cf->args->nelts; i++) {
Igor Sysoev79a80482003-05-14 17:13:13 +00002671
Igor Sysoev6a078332008-08-04 10:18:36 +00002672 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
Igor Sysoev24025022005-12-16 15:07:08 +00002673
Igor Sysoev30870b42009-11-13 19:59:54 +00002674 type = clcf->types->elts;
2675 for (n = 0; n < clcf->types->nelts; n++) {
Igor Sysoev24025022005-12-16 15:07:08 +00002676 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
2677 old = type[n].value;
2678 type[n].value = content_type;
2679
2680 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2681 "duplicate extention \"%V\", "
2682 "content type: \"%V\", "
2683 "old content type: \"%V\"",
2684 &value[i], content_type, old);
2685 continue;
2686 }
2687 }
2688
2689
Igor Sysoev30870b42009-11-13 19:59:54 +00002690 type = ngx_array_push(clcf->types);
Igor Sysoevc1571722005-03-19 12:38:37 +00002691 if (type == NULL) {
Igor Sysoevdc3b2a72004-09-14 19:39:54 +00002692 return NGX_CONF_ERROR;
2693 }
2694
Igor Sysoev24025022005-12-16 15:07:08 +00002695 type->key = value[i];
Igor Sysoev6a078332008-08-04 10:18:36 +00002696 type->key_hash = hash;
Igor Sysoev24025022005-12-16 15:07:08 +00002697 type->value = content_type;
Igor Sysoev79a80482003-05-14 17:13:13 +00002698 }
2699
2700 return NGX_CONF_OK;
2701}
2702
2703
Igor Sysoev899b44e2005-05-12 14:58:06 +00002704static ngx_int_t
2705ngx_http_core_preconfiguration(ngx_conf_t *cf)
2706{
2707 return ngx_http_variables_add_core_vars(cf);
2708}
2709
2710
Igor Sysoevaa828612005-02-09 14:31:07 +00002711static void *
2712ngx_http_core_create_main_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002713{
Igor Sysoev805d9db2005-02-03 19:33:37 +00002714 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002715
Igor Sysoevc1571722005-03-19 12:38:37 +00002716 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
2717 if (cmcf == NULL) {
Igor Sysoev260c4322009-06-02 16:09:44 +00002718 return NULL;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002719 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002720
Igor Sysoev8184d1b2005-03-04 14:06:57 +00002721 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002722 sizeof(ngx_http_core_srv_conf_t *))
Igor Sysoev6f134cc2006-05-23 14:54:58 +00002723 != NGX_OK)
Igor Sysoev805d9db2005-02-03 19:33:37 +00002724 {
Igor Sysoev260c4322009-06-02 16:09:44 +00002725 return NULL;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002726 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002727
Igor Sysoev305a9d82005-12-26 17:07:48 +00002728 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
2729 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002730
Igor Sysoevffe71442006-02-08 15:33:12 +00002731 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
2732 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
2733
Igor Sysoeva9830112003-05-19 16:39:14 +00002734 return cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002735}
2736
2737
Igor Sysoevaa828612005-02-09 14:31:07 +00002738static char *
2739ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002740{
Igor Sysoev6253ca12003-05-27 12:18:54 +00002741 ngx_http_core_main_conf_t *cmcf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00002742
Igor Sysoev305a9d82005-12-26 17:07:48 +00002743 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
2744 cmcf->server_names_hash_max_size = 512;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002745 }
2746
Igor Sysoev305a9d82005-12-26 17:07:48 +00002747 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2748 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002749 }
Igor Sysoeva9830112003-05-19 16:39:14 +00002750
Igor Sysoev305a9d82005-12-26 17:07:48 +00002751 cmcf->server_names_hash_bucket_size =
2752 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
2753
Igor Sysoevffe71442006-02-08 15:33:12 +00002754
2755 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
2756 cmcf->variables_hash_max_size = 512;
2757 }
2758
2759 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2760 cmcf->variables_hash_bucket_size = 64;
2761 }
2762
2763 cmcf->variables_hash_bucket_size =
2764 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
2765
Igor Sysoev42f5fb12009-11-16 19:11:38 +00002766 if (cmcf->ncaptures) {
2767 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
2768 }
2769
Igor Sysoeva9830112003-05-19 16:39:14 +00002770 return NGX_CONF_OK;
2771}
2772
2773
Igor Sysoevaa828612005-02-09 14:31:07 +00002774static void *
2775ngx_http_core_create_srv_conf(ngx_conf_t *cf)
Igor Sysoeva9830112003-05-19 16:39:14 +00002776{
2777 ngx_http_core_srv_conf_t *cscf;
2778
Igor Sysoevc1571722005-03-19 12:38:37 +00002779 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
2780 if (cscf == NULL) {
Igor Sysoev260c4322009-06-02 16:09:44 +00002781 return NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002782 }
2783
Igor Sysoev85080d02004-09-22 16:18:21 +00002784 /*
Igor Sysoev02025fd2005-01-18 13:03:58 +00002785 * set by ngx_pcalloc():
Igor Sysoevaa828612005-02-09 14:31:07 +00002786 *
Igor Sysoev02025fd2005-01-18 13:03:58 +00002787 * conf->client_large_buffers.num = 0;
2788 */
Igor Sysoev85080d02004-09-22 16:18:21 +00002789
Igor Sysoevda173ab2006-08-30 10:39:17 +00002790 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
Igor Sysoev305a9d82005-12-26 17:07:48 +00002791 sizeof(ngx_http_server_name_t))
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002792 != NGX_OK)
Igor Sysoevaa828612005-02-09 14:31:07 +00002793 {
Igor Sysoev260c4322009-06-02 16:09:44 +00002794 return NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002795 }
Igor Sysoeva9830112003-05-19 16:39:14 +00002796
Igor Sysoev10a543a2004-03-16 07:10:12 +00002797 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002798 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
2799 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
2800 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev3362b8d2005-05-14 18:42:03 +00002801 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
Igor Sysoev8decab32007-10-18 11:36:58 +00002802 cscf->merge_slashes = NGX_CONF_UNSET;
Igor Sysoev753792e2008-09-24 14:02:50 +00002803 cscf->underscores_in_headers = NGX_CONF_UNSET;
Igor Sysoev187fcd82003-05-23 11:53:01 +00002804
Igor Sysoeva9830112003-05-19 16:39:14 +00002805 return cscf;
2806}
2807
2808
Igor Sysoevaa828612005-02-09 14:31:07 +00002809static char *
2810ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeva9830112003-05-19 16:39:14 +00002811{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002812 ngx_http_core_srv_conf_t *prev = parent;
2813 ngx_http_core_srv_conf_t *conf = child;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002814
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002815 struct sockaddr_in *sin;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002816 ngx_http_listen_opt_t lsopt;
Igor Sysoev305a9d82005-12-26 17:07:48 +00002817 ngx_http_server_name_t *sn;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002818
Igor Sysoev7578ec92003-06-02 15:24:30 +00002819 /* TODO: it does not merge, it inits only */
Igor Sysoeva9830112003-05-19 16:39:14 +00002820
Igor Sysoev44fa8872009-10-29 15:53:50 +00002821 ngx_conf_merge_size_value(conf->connection_pool_size,
2822 prev->connection_pool_size, 256);
2823 ngx_conf_merge_size_value(conf->request_pool_size,
2824 prev->request_pool_size, 4096);
2825 ngx_conf_merge_msec_value(conf->client_header_timeout,
2826 prev->client_header_timeout, 60000);
2827 ngx_conf_merge_size_value(conf->client_header_buffer_size,
2828 prev->client_header_buffer_size, 1024);
2829 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
2830 prev->large_client_header_buffers,
2831 4, ngx_pagesize);
2832
2833 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
2834 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2835 "the \"large_client_header_buffers\" size must be "
2836 "equal to or bigger than \"connection_pool_size\"");
2837 return NGX_CONF_ERROR;
2838 }
2839
2840 ngx_conf_merge_value(conf->ignore_invalid_headers,
2841 prev->ignore_invalid_headers, 1);
2842
2843 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
2844
2845 ngx_conf_merge_value(conf->underscores_in_headers,
2846 prev->underscores_in_headers, 0);
2847
Igor Sysoev79d630a2009-10-21 08:19:46 +00002848 if (!conf->listen) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002849 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
Igor Sysoevaa828612005-02-09 14:31:07 +00002850
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002851 sin = (struct sockaddr_in *) &lsopt.sockaddr;
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002852
2853 sin->sin_family = AF_INET;
Igor Sysoev1b735832004-11-11 14:07:14 +00002854#if (NGX_WIN32)
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002855 sin->sin_port = htons(80);
Igor Sysoev1c104622003-06-03 15:42:58 +00002856#else
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002857 sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
Igor Sysoev1c104622003-06-03 15:42:58 +00002858#endif
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002859 sin->sin_addr.s_addr = INADDR_ANY;
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002860
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002861 lsopt.socklen = sizeof(struct sockaddr_in);
Igor Sysoeve10385e2009-02-21 10:23:30 +00002862
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002863 lsopt.backlog = NGX_LISTEN_BACKLOG;
2864 lsopt.rcvbuf = -1;
2865 lsopt.sndbuf = -1;
2866 lsopt.wildcard = 1;
Igor Sysoeve10385e2009-02-21 10:23:30 +00002867
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002868 (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
Igor Sysoeve10385e2009-02-21 10:23:30 +00002869 NGX_SOCKADDR_STRLEN, 1);
Igor Sysoev79d630a2009-10-21 08:19:46 +00002870
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002871 if (ngx_http_add_listen(cf, conf, &lsopt) == NGX_OK) {
Igor Sysoev79d630a2009-10-21 08:19:46 +00002872 return NGX_CONF_OK;
2873 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002874 }
2875
Igor Sysoev9e580192006-02-01 18:22:15 +00002876 if (conf->server_name.data == NULL) {
Igor Sysoev3be52572008-05-16 14:39:06 +00002877 conf->server_name = cf->cycle->hostname;
Igor Sysoev9e580192006-02-01 18:22:15 +00002878
2879 sn = ngx_array_push(&conf->server_names);
2880 if (sn == NULL) {
2881 return NGX_CONF_ERROR;
2882 }
2883
Igor Sysoev12446d82007-10-17 13:22:26 +00002884#if (NGX_PCRE)
2885 sn->regex = NULL;
2886#endif
Igor Sysoevcd8b43c2009-10-21 16:52:10 +00002887 sn->server = conf;
Igor Sysoev9e580192006-02-01 18:22:15 +00002888 sn->name.len = conf->server_name.len;
2889 sn->name.data = conf->server_name.data;
Igor Sysoevad22e012003-01-15 07:02:27 +00002890 }
2891
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002892 return NGX_CONF_OK;
2893}
2894
2895
Igor Sysoevaa828612005-02-09 14:31:07 +00002896static void *
2897ngx_http_core_create_loc_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002898{
Igor Sysoev30870b42009-11-13 19:59:54 +00002899 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002900
Igor Sysoev30870b42009-11-13 19:59:54 +00002901 clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
2902 if (clcf == NULL) {
Igor Sysoev260c4322009-06-02 16:09:44 +00002903 return NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002904 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002905
Igor Sysoev02025fd2005-01-18 13:03:58 +00002906 /*
2907 * set by ngx_pcalloc():
2908 *
Igor Sysoev30870b42009-11-13 19:59:54 +00002909 * clcf->root = { 0, NULL };
2910 * clcf->limit_except = 0;
2911 * clcf->post_action = { 0, NULL };
2912 * clcf->types = NULL;
2913 * clcf->default_type = { 0, NULL };
2914 * clcf->error_log = NULL;
2915 * clcf->error_pages = NULL;
2916 * clcf->try_files = NULL;
2917 * clcf->client_body_path = NULL;
2918 * clcf->regex = NULL;
2919 * clcf->exact_match = 0;
2920 * clcf->auto_redirect = 0;
2921 * clcf->alias = 0;
2922 * clcf->gzip_proxied = 0;
Igor Sysoev02025fd2005-01-18 13:03:58 +00002923 */
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002924
Igor Sysoev30870b42009-11-13 19:59:54 +00002925 clcf->client_max_body_size = NGX_CONF_UNSET;
2926 clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
2927 clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
2928 clcf->satisfy = NGX_CONF_UNSET_UINT;
2929 clcf->if_modified_since = NGX_CONF_UNSET_UINT;
2930 clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
2931 clcf->client_body_in_single_buffer = NGX_CONF_UNSET;
2932 clcf->internal = NGX_CONF_UNSET;
2933 clcf->sendfile = NGX_CONF_UNSET;
2934 clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
Igor Sysoeva9625062009-08-28 08:12:35 +00002935#if (NGX_HAVE_FILE_AIO)
Igor Sysoev30870b42009-11-13 19:59:54 +00002936 clcf->aio = NGX_CONF_UNSET;
Igor Sysoeva9625062009-08-28 08:12:35 +00002937#endif
Igor Sysoev30870b42009-11-13 19:59:54 +00002938 clcf->read_ahead = NGX_CONF_UNSET_SIZE;
2939 clcf->directio = NGX_CONF_UNSET;
2940 clcf->directio_alignment = NGX_CONF_UNSET;
2941 clcf->tcp_nopush = NGX_CONF_UNSET;
2942 clcf->tcp_nodelay = NGX_CONF_UNSET;
2943 clcf->send_timeout = NGX_CONF_UNSET_MSEC;
2944 clcf->send_lowat = NGX_CONF_UNSET_SIZE;
2945 clcf->postpone_output = NGX_CONF_UNSET_SIZE;
2946 clcf->limit_rate = NGX_CONF_UNSET_SIZE;
2947 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
2948 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
2949 clcf->keepalive_header = NGX_CONF_UNSET;
2950 clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
2951 clcf->lingering_time = NGX_CONF_UNSET_MSEC;
2952 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
2953 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
2954 clcf->reset_timedout_connection = NGX_CONF_UNSET;
2955 clcf->server_name_in_redirect = NGX_CONF_UNSET;
2956 clcf->port_in_redirect = NGX_CONF_UNSET;
2957 clcf->msie_padding = NGX_CONF_UNSET;
2958 clcf->msie_refresh = NGX_CONF_UNSET;
2959 clcf->log_not_found = NGX_CONF_UNSET;
2960 clcf->log_subrequest = NGX_CONF_UNSET;
2961 clcf->recursive_error_pages = NGX_CONF_UNSET;
2962 clcf->server_tokens = NGX_CONF_UNSET;
2963 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
2964 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002965
Igor Sysoev30870b42009-11-13 19:59:54 +00002966 clcf->open_file_cache = NGX_CONF_UNSET_PTR;
2967 clcf->open_file_cache_valid = NGX_CONF_UNSET;
2968 clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
2969 clcf->open_file_cache_errors = NGX_CONF_UNSET;
2970 clcf->open_file_cache_events = NGX_CONF_UNSET;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002971
Igor Sysoevc16b0052007-12-27 14:21:59 +00002972#if (NGX_HTTP_GZIP)
Igor Sysoev30870b42009-11-13 19:59:54 +00002973 clcf->gzip_vary = NGX_CONF_UNSET;
2974 clcf->gzip_http_version = NGX_CONF_UNSET_UINT;
Igor Sysoev8eac7262007-12-28 13:15:11 +00002975#if (NGX_PCRE)
Igor Sysoev30870b42009-11-13 19:59:54 +00002976 clcf->gzip_disable = NGX_CONF_UNSET_PTR;
2977 clcf->gzip_disable_msie6 = 3;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002978#endif
Igor Sysoev8eac7262007-12-28 13:15:11 +00002979#endif
Igor Sysoevc16b0052007-12-27 14:21:59 +00002980
Igor Sysoev30870b42009-11-13 19:59:54 +00002981 return clcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002982}
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002983
Igor Sysoev79a80482003-05-14 17:13:13 +00002984
Igor Sysoev24025022005-12-16 15:07:08 +00002985static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
2986static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
2987static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
2988
2989static ngx_hash_key_t ngx_http_core_default_types[] = {
2990 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
2991 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
2992 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
2993 { ngx_null_string, 0, NULL }
Igor Sysoev79a80482003-05-14 17:13:13 +00002994};
2995
2996
Igor Sysoevaa828612005-02-09 14:31:07 +00002997static char *
Igor Sysoev24025022005-12-16 15:07:08 +00002998ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeve2a31542003-04-08 15:40:10 +00002999{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003000 ngx_http_core_loc_conf_t *prev = parent;
3001 ngx_http_core_loc_conf_t *conf = child;
Igor Sysoev79a80482003-05-14 17:13:13 +00003002
Igor Sysoevaa828612005-02-09 14:31:07 +00003003 ngx_uint_t i;
Igor Sysoev24025022005-12-16 15:07:08 +00003004 ngx_hash_key_t *type;
3005 ngx_hash_init_t types_hash;
Igor Sysoev79a80482003-05-14 17:13:13 +00003006
Igor Sysoev34303462006-01-24 16:08:27 +00003007 if (conf->root.data == NULL) {
Igor Sysoev79a80482003-05-14 17:13:13 +00003008
Igor Sysoev455a7fc2006-03-21 08:20:41 +00003009 conf->alias = prev->alias;
Igor Sysoev34303462006-01-24 16:08:27 +00003010 conf->root = prev->root;
3011 conf->root_lengths = prev->root_lengths;
3012 conf->root_values = prev->root_values;
3013
3014 if (prev->root.data == NULL) {
3015 conf->root.len = sizeof("html") - 1;
3016 conf->root.data = (u_char *) "html";
3017
Igor Sysoev1f4220e2009-02-24 10:42:23 +00003018 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
Igor Sysoev34303462006-01-24 16:08:27 +00003019 return NGX_CONF_ERROR;
3020 }
3021 }
Igor Sysoev6d2a14a2004-09-27 16:03:21 +00003022 }
3023
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003024 if (conf->post_action.data == NULL) {
3025 conf->post_action = prev->post_action;
3026 }
3027
Igor Sysoev1765f472006-07-07 16:33:19 +00003028 ngx_conf_merge_uint_value(conf->types_hash_max_size,
3029 prev->types_hash_max_size, 1024);
Igor Sysoev79a80482003-05-14 17:13:13 +00003030
Igor Sysoev1765f472006-07-07 16:33:19 +00003031 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
3032 prev->types_hash_bucket_size,
3033 ngx_cacheline_size);
Igor Sysoev24025022005-12-16 15:07:08 +00003034
3035 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
3036 ngx_cacheline_size);
3037
3038 /*
3039 * the special handling the "types" directive in the "http" section
3040 * to inherit the http's conf->types_hash to all servers
3041 */
3042
3043 if (prev->types && prev->types_hash.buckets == NULL) {
3044
3045 types_hash.hash = &prev->types_hash;
3046 types_hash.key = ngx_hash_key_lc;
3047 types_hash.max_size = conf->types_hash_max_size;
3048 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003049 types_hash.name = "types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00003050 types_hash.pool = cf->pool;
3051 types_hash.temp_pool = NULL;
3052
3053 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
3054 != NGX_OK)
3055 {
3056 return NGX_CONF_ERROR;
3057 }
3058 }
3059
3060 if (conf->types == NULL) {
3061 conf->types = prev->types;
3062 conf->types_hash = prev->types_hash;
3063 }
3064
3065 if (conf->types == NULL) {
3066 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
3067 if (conf->types == NULL) {
3068 return NGX_CONF_ERROR;
3069 }
3070
3071 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
3072 type = ngx_array_push(conf->types);
3073 if (type == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00003074 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00003075 }
3076
Igor Sysoev24025022005-12-16 15:07:08 +00003077 type->key = ngx_http_core_default_types[i].key;
3078 type->key_hash =
3079 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
3080 ngx_http_core_default_types[i].key.len);
3081 type->value = ngx_http_core_default_types[i].value;
3082 }
3083 }
Igor Sysoev79a80482003-05-14 17:13:13 +00003084
Igor Sysoev24025022005-12-16 15:07:08 +00003085 if (conf->types_hash.buckets == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00003086
Igor Sysoev24025022005-12-16 15:07:08 +00003087 types_hash.hash = &conf->types_hash;
3088 types_hash.key = ngx_hash_key_lc;
3089 types_hash.max_size = conf->types_hash_max_size;
3090 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003091 types_hash.name = "mime_types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00003092 types_hash.pool = cf->pool;
3093 types_hash.temp_pool = NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00003094
Igor Sysoev24025022005-12-16 15:07:08 +00003095 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
3096 != NGX_OK)
3097 {
3098 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00003099 }
3100 }
3101
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00003102 if (conf->error_log == NULL) {
3103 if (prev->error_log) {
3104 conf->error_log = prev->error_log;
Igor Sysoev890fc962003-07-20 21:15:59 +00003105 } else {
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00003106 conf->error_log = &cf->cycle->new_log;
Igor Sysoev890fc962003-07-20 21:15:59 +00003107 }
3108 }
3109
Igor Sysoev74e95c22003-11-09 20:03:38 +00003110 if (conf->error_pages == NULL && prev->error_pages) {
3111 conf->error_pages = prev->error_pages;
3112 }
3113
Igor Sysoev6253ca12003-05-27 12:18:54 +00003114 ngx_conf_merge_str_value(conf->default_type,
Igor Sysoevaa828612005-02-09 14:31:07 +00003115 prev->default_type, "text/plain");
Igor Sysoev6253ca12003-05-27 12:18:54 +00003116
Igor Sysoev1765f472006-07-07 16:33:19 +00003117 ngx_conf_merge_off_value(conf->client_max_body_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00003118 prev->client_max_body_size, 1 * 1024 * 1024);
Igor Sysoevdbb27762004-04-01 16:20:53 +00003119 ngx_conf_merge_size_value(conf->client_body_buffer_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00003120 prev->client_body_buffer_size,
3121 (size_t) 2 * ngx_pagesize);
Igor Sysoev2b0c76c2003-10-27 21:01:00 +00003122 ngx_conf_merge_msec_value(conf->client_body_timeout,
Igor Sysoev7af6b162004-02-09 07:46:43 +00003123 prev->client_body_timeout, 60000);
Igor Sysoev899b44e2005-05-12 14:58:06 +00003124
Igor Sysoev2d028f82007-12-29 16:38:23 +00003125 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
3126 NGX_HTTP_SATISFY_ALL);
Igor Sysoev863325f2008-12-01 14:22:51 +00003127 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
Igor Sysoev2c336482009-02-10 15:05:05 +00003128 NGX_HTTP_IMS_EXACT);
Igor Sysoev7d9e3342009-05-14 11:31:50 +00003129 ngx_conf_merge_uint_value(conf->client_body_in_file_only,
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00003130 prev->client_body_in_file_only, 0);
Igor Sysoevbfbded72009-05-14 11:41:33 +00003131 ngx_conf_merge_value(conf->client_body_in_single_buffer,
3132 prev->client_body_in_single_buffer, 0);
Igor Sysoev7d9e3342009-05-14 11:31:50 +00003133 ngx_conf_merge_value(conf->internal, prev->internal, 0);
Igor Sysoev5bf3d252003-10-22 07:05:29 +00003134 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
Igor Sysoevc9b57dc2007-05-07 06:33:39 +00003135 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
3136 prev->sendfile_max_chunk, 0);
Igor Sysoeva9625062009-08-28 08:12:35 +00003137#if (NGX_HAVE_FILE_AIO)
3138 ngx_conf_merge_value(conf->aio, prev->aio, 0);
3139#endif
Igor Sysoev32661712009-09-30 13:21:52 +00003140 ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0);
Igor Sysoev385af282008-07-30 12:34:04 +00003141 ngx_conf_merge_off_value(conf->directio, prev->directio,
3142 NGX_MAX_OFF_T_VALUE);
Igor Sysoev6fb506a2009-08-28 08:15:55 +00003143 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
3144 512);
Igor Sysoev3c3ca172004-01-05 20:55:48 +00003145 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003146 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
Igor Sysoev899b44e2005-05-12 14:58:06 +00003147
Igor Sysoev7af6b162004-02-09 07:46:43 +00003148 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
Igor Sysoevb5faed22003-10-29 08:30:44 +00003149 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
Igor Sysoev7823cc32004-07-14 16:01:42 +00003150 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
3151 1460);
3152 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
Igor Sysoev80027fc2009-06-02 14:01:50 +00003153 ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after,
3154 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00003155 ngx_conf_merge_msec_value(conf->keepalive_timeout,
Igor Sysoev307c3ad2004-09-17 16:07:35 +00003156 prev->keepalive_timeout, 75000);
3157 ngx_conf_merge_sec_value(conf->keepalive_header,
3158 prev->keepalive_header, 0);
Igor Sysoeve9591282009-05-25 15:38:36 +00003159 ngx_conf_merge_uint_value(conf->keepalive_requests,
3160 prev->keepalive_requests, 100);
Igor Sysoev187fcd82003-05-23 11:53:01 +00003161 ngx_conf_merge_msec_value(conf->lingering_time,
3162 prev->lingering_time, 30000);
3163 ngx_conf_merge_msec_value(conf->lingering_timeout,
3164 prev->lingering_timeout, 5000);
Igor Sysoev13f5ff92007-11-27 11:33:52 +00003165 ngx_conf_merge_msec_value(conf->resolver_timeout,
3166 prev->resolver_timeout, 30000);
3167
3168 if (conf->resolver == NULL) {
Igor Sysoev6b2fce42007-12-03 10:05:19 +00003169
Igor Sysoevf39876c2008-03-06 08:48:55 +00003170 if (prev->resolver == NULL) {
3171
3172 /*
3173 * create dummy resolver in http {} context
3174 * to inherit it in all servers
3175 */
3176
3177 prev->resolver = ngx_resolver_create(cf, NULL);
3178 if (prev->resolver == NULL) {
Igor Sysoevd2d673a2008-02-07 08:57:07 +00003179 return NGX_CONF_ERROR;
Igor Sysoev6b2fce42007-12-03 10:05:19 +00003180 }
3181 }
Igor Sysoev433608c2008-05-14 07:54:52 +00003182
Igor Sysoevf39876c2008-03-06 08:48:55 +00003183 conf->resolver = prev->resolver;
Igor Sysoev13f5ff92007-11-27 11:33:52 +00003184 }
Igor Sysoev79a80482003-05-14 17:13:13 +00003185
Igor Sysoev52859f22009-03-23 13:14:51 +00003186 if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path,
Igor Sysoev02025fd2005-01-18 13:03:58 +00003187 prev->client_body_temp_path,
Igor Sysoev52859f22009-03-23 13:14:51 +00003188 &ngx_http_client_temp_path)
3189 != NGX_OK)
3190 {
3191 return NGX_CONF_ERROR;
3192 }
Igor Sysoev02025fd2005-01-18 13:03:58 +00003193
Igor Sysoev0ab91b92004-06-06 19:49:18 +00003194 ngx_conf_merge_value(conf->reset_timedout_connection,
Igor Sysoevaa828612005-02-09 14:31:07 +00003195 prev->reset_timedout_connection, 0);
Igor Sysoev3f24ae22007-12-29 15:30:39 +00003196 ngx_conf_merge_value(conf->server_name_in_redirect,
3197 prev->server_name_in_redirect, 1);
Igor Sysoev7b190b42005-06-07 15:56:31 +00003198 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00003199 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003200 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
Igor Sysoev5192b362005-07-08 14:34:20 +00003201 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
Igor Sysoev2eec1e12008-09-27 15:08:02 +00003202 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003203 ngx_conf_merge_value(conf->recursive_error_pages,
3204 prev->recursive_error_pages, 0);
Igor Sysoev070cf222007-10-22 10:17:34 +00003205 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00003206
Igor Sysoev140c7552007-09-01 12:12:48 +00003207 ngx_conf_merge_ptr_value(conf->open_file_cache,
Igor Sysoev513fec72007-12-27 08:40:14 +00003208 prev->open_file_cache, NULL);
Igor Sysoev140c7552007-09-01 12:12:48 +00003209
Igor Sysoev9b9616e2007-12-21 16:19:48 +00003210 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
Igor Sysoev513fec72007-12-27 08:40:14 +00003211 prev->open_file_cache_valid, 60);
Igor Sysoev140c7552007-09-01 12:12:48 +00003212
Igor Sysoevf3b0e492007-12-22 13:19:39 +00003213 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
Igor Sysoev513fec72007-12-27 08:40:14 +00003214 prev->open_file_cache_min_uses, 1);
Igor Sysoevf3b0e492007-12-22 13:19:39 +00003215
Igor Sysoev140c7552007-09-01 12:12:48 +00003216 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
Igor Sysoev513fec72007-12-27 08:40:14 +00003217 prev->open_file_cache_errors, 0);
Igor Sysoev865c1502003-11-30 20:03:18 +00003218
Igor Sysoev9afd58f2007-09-03 08:41:42 +00003219 ngx_conf_merge_sec_value(conf->open_file_cache_events,
Igor Sysoev513fec72007-12-27 08:40:14 +00003220 prev->open_file_cache_events, 0);
Igor Sysoevc16b0052007-12-27 14:21:59 +00003221#if (NGX_HTTP_GZIP)
3222
3223 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
3224 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
3225 NGX_HTTP_VERSION_11);
3226 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
3227 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
3228
Igor Sysoev8eac7262007-12-28 13:15:11 +00003229#if (NGX_PCRE)
Igor Sysoevc16b0052007-12-27 14:21:59 +00003230 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
Igor Sysoev8eac7262007-12-28 13:15:11 +00003231#endif
Igor Sysoevc16b0052007-12-27 14:21:59 +00003232
Igor Sysoev54477e42008-08-26 15:09:28 +00003233 if (conf->gzip_disable_msie6 == 3) {
3234 conf->gzip_disable_msie6 =
3235 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
3236 }
3237
Igor Sysoevc16b0052007-12-27 14:21:59 +00003238#endif
Igor Sysoev9afd58f2007-09-03 08:41:42 +00003239
Igor Sysoeve2a31542003-04-08 15:40:10 +00003240 return NGX_CONF_OK;
3241}
3242
Igor Sysoev79a80482003-05-14 17:13:13 +00003243
Igor Sysoevaa828612005-02-09 14:31:07 +00003244static char *
3245ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003246{
Igor Sysoev79d630a2009-10-21 08:19:46 +00003247 ngx_http_core_srv_conf_t *cscf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00003248
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003249 ngx_str_t *value, size;
3250 ngx_url_t u;
3251 ngx_uint_t n;
3252 ngx_http_listen_opt_t lsopt;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003253
Igor Sysoev79d630a2009-10-21 08:19:46 +00003254 cscf->listen = 1;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +00003255
Igor Sysoevb145b062005-06-15 18:33:41 +00003256 value = cf->args->elts;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003257
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003258 ngx_memzero(&u, sizeof(ngx_url_t));
Igor Sysoevb145b062005-06-15 18:33:41 +00003259
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003260 u.url = value[1];
3261 u.listen = 1;
Igor Sysoevbf3aaac2006-12-12 16:46:16 +00003262 u.default_port = 80;
Igor Sysoevb145b062005-06-15 18:33:41 +00003263
Igor Sysoev7ed63ee2007-10-08 08:55:12 +00003264 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003265 if (u.err) {
3266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3267 "%s in \"%V\" of the \"listen\" directive",
3268 u.err, &u.url);
3269 }
Igor Sysoevb145b062005-06-15 18:33:41 +00003270
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003271 return NGX_CONF_ERROR;
Igor Sysoevb145b062005-06-15 18:33:41 +00003272 }
3273
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003274 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003275
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003276 ngx_memcpy(lsopt.sockaddr, u.sockaddr, u.socklen);
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003277
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003278 lsopt.socklen = u.socklen;
3279 lsopt.backlog = NGX_LISTEN_BACKLOG;
3280 lsopt.rcvbuf = -1;
3281 lsopt.sndbuf = -1;
3282 lsopt.wildcard = u.wildcard;
Igor Sysoeva35eacc2009-02-21 07:02:02 +00003283
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003284 (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
Igor Sysoeva35eacc2009-02-21 07:02:02 +00003285 NGX_SOCKADDR_STRLEN, 1);
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003286
Igor Sysoev5a950802009-10-21 19:16:38 +00003287 for (n = 2; n < cf->args->nelts; n++) {
Igor Sysoev24025022005-12-16 15:07:08 +00003288
Igor Sysoev98269612009-10-21 19:18:50 +00003289 if (ngx_strcmp(value[n].data, "default_server") == 0
3290 || ngx_strcmp(value[n].data, "default") == 0)
3291 {
Igor Sysoev5a950802009-10-21 19:16:38 +00003292 lsopt.default_server = 1;
3293 continue;
Igor Sysoev13933252003-05-29 13:02:09 +00003294 }
3295
Igor Sysoevb145b062005-06-15 18:33:41 +00003296 if (ngx_strcmp(value[n].data, "bind") == 0) {
Igor Sysoev5a950802009-10-21 19:16:38 +00003297 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003298 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003299 continue;
3300 }
3301
Igor Sysoevc2068d02005-10-19 12:33:58 +00003302 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003303 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
Igor Sysoev5a950802009-10-21 19:16:38 +00003304 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003305 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003306
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003307 if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
Igor Sysoevb145b062005-06-15 18:33:41 +00003308 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3309 "invalid backlog \"%V\"", &value[n]);
3310 return NGX_CONF_ERROR;
3311 }
3312
3313 continue;
3314 }
3315
Igor Sysoevc2068d02005-10-19 12:33:58 +00003316 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
3317 size.len = value[n].len - 7;
3318 size.data = value[n].data + 7;
3319
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003320 lsopt.rcvbuf = ngx_parse_size(&size);
Igor Sysoev5a950802009-10-21 19:16:38 +00003321 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003322 lsopt.bind = 1;
Igor Sysoevc2068d02005-10-19 12:33:58 +00003323
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003324 if (lsopt.rcvbuf == NGX_ERROR) {
Igor Sysoevc2068d02005-10-19 12:33:58 +00003325 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3326 "invalid rcvbuf \"%V\"", &value[n]);
3327 return NGX_CONF_ERROR;
3328 }
3329
3330 continue;
3331 }
3332
3333 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
3334 size.len = value[n].len - 7;
3335 size.data = value[n].data + 7;
3336
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003337 lsopt.sndbuf = ngx_parse_size(&size);
Igor Sysoev5a950802009-10-21 19:16:38 +00003338 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003339 lsopt.bind = 1;
Igor Sysoevc2068d02005-10-19 12:33:58 +00003340
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003341 if (lsopt.sndbuf == NGX_ERROR) {
Igor Sysoevc2068d02005-10-19 12:33:58 +00003342 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3343 "invalid sndbuf \"%V\"", &value[n]);
3344 return NGX_CONF_ERROR;
3345 }
3346
3347 continue;
3348 }
3349
3350 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
Igor Sysoevb145b062005-06-15 18:33:41 +00003351#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003352 lsopt.accept_filter = (char *) &value[n].data[14];
Igor Sysoev5a950802009-10-21 19:16:38 +00003353 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003354 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003355#else
3356 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3357 "accept filters \"%V\" are not supported "
3358 "on this platform, ignored",
3359 &value[n]);
3360#endif
3361 continue;
3362 }
3363
3364 if (ngx_strcmp(value[n].data, "deferred") == 0) {
3365#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003366 lsopt.deferred_accept = 1;
Igor Sysoev5a950802009-10-21 19:16:38 +00003367 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003368 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003369#else
3370 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3371 "the deferred accept is not supported "
3372 "on this platform, ignored");
3373#endif
3374 continue;
3375 }
3376
Igor Sysoev6d94b512009-03-13 14:20:34 +00003377 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
3378#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3379 struct sockaddr *sa;
3380
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003381 sa = (struct sockaddr *) lsopt.sockaddr;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003382
3383 if (sa->sa_family == AF_INET6) {
3384
3385 if (ngx_strcmp(&value[n].data[10], "n") == 0) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003386 lsopt.ipv6only = 1;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003387
3388 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003389 lsopt.ipv6only = 2;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003390
3391 } else {
3392 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3393 "invalid ipv6only flags \"%s\"",
3394 &value[n].data[9]);
3395 return NGX_CONF_ERROR;
3396 }
3397
Igor Sysoev5a950802009-10-21 19:16:38 +00003398 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003399 lsopt.bind = 1;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003400
3401 } else {
3402 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3403 "ipv6only is not supported "
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003404 "on addr \"%s\", ignored", lsopt.addr);
Igor Sysoev6d94b512009-03-13 14:20:34 +00003405 }
3406
3407 continue;
3408#else
3409 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3410 "bind ipv6only is not supported "
3411 "on this platform");
3412 return NGX_CONF_ERROR;
3413#endif
3414 }
3415
Igor Sysoevf100c782008-09-01 14:19:01 +00003416 if (ngx_strcmp(value[n].data, "ssl") == 0) {
3417#if (NGX_HTTP_SSL)
Igor Sysoev5a950802009-10-21 19:16:38 +00003418 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003419 lsopt.ssl = 1;
Igor Sysoevf100c782008-09-01 14:19:01 +00003420 continue;
3421#else
3422 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3423 "the \"ssl\" parameter requires "
3424 "ngx_http_ssl_module");
3425 return NGX_CONF_ERROR;
3426#endif
3427 }
3428
Igor Sysoevb145b062005-06-15 18:33:41 +00003429 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3430 "the invalid \"%V\" parameter", &value[n]);
3431 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00003432 }
3433
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003434 if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
Igor Sysoev79d630a2009-10-21 08:19:46 +00003435 return NGX_CONF_OK;
3436 }
3437
3438 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00003439}
3440
3441
Igor Sysoevaa828612005-02-09 14:31:07 +00003442static char *
3443ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev13933252003-05-29 13:02:09 +00003444{
Igor Sysoev305a9d82005-12-26 17:07:48 +00003445 ngx_http_core_srv_conf_t *cscf = conf;
Igor Sysoev13933252003-05-29 13:02:09 +00003446
Igor Sysoev305a9d82005-12-26 17:07:48 +00003447 u_char ch;
3448 ngx_str_t *value, name;
3449 ngx_uint_t i;
3450 ngx_http_server_name_t *sn;
Igor Sysoevb1af9bb2004-06-25 14:42:03 +00003451
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003452 value = cf->args->elts;
Igor Sysoev13933252003-05-29 13:02:09 +00003453
Igor Sysoev305a9d82005-12-26 17:07:48 +00003454 ch = value[1].data[0];
3455
Igor Sysoevb29426d2008-08-21 12:56:10 +00003456 if (cscf->server_name.data == NULL) {
3457 if (value[1].len) {
3458 name = value[1];
Igor Sysoev305a9d82005-12-26 17:07:48 +00003459
Igor Sysoevb29426d2008-08-21 12:56:10 +00003460 if (ch == '.') {
3461 name.len--;
3462 name.data++;
3463 }
Igor Sysoev305a9d82005-12-26 17:07:48 +00003464
Igor Sysoevb29426d2008-08-21 12:56:10 +00003465 cscf->server_name.len = name.len;
3466 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
3467 if (cscf->server_name.data == NULL) {
3468 return NGX_CONF_ERROR;
3469 }
3470
3471 } else {
3472 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3473 "the first server name must not be empty");
Igor Sysoev305a9d82005-12-26 17:07:48 +00003474 return NGX_CONF_ERROR;
3475 }
3476 }
3477
3478 for (i = 1; i < cf->args->nelts; i++) {
3479
3480 ch = value[i].data[0];
3481
Igor Sysoevb29426d2008-08-21 12:56:10 +00003482 if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
Igor Sysoev305a9d82005-12-26 17:07:48 +00003483 || (ch == '.' && value[i].len < 2))
3484 {
3485 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3486 "server name \"%V\" is invalid", &value[i]);
3487 return NGX_CONF_ERROR;
3488 }
3489
Igor Sysoev7a588602007-04-02 06:27:30 +00003490 if (ngx_strchr(value[i].data, '/')) {
3491 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
3492 "server name \"%V\" has strange symbols",
3493 &value[i]);
3494 }
3495
Igor Sysoevc24de1e2007-12-29 19:05:21 +00003496 if (value[i].len == 1 && ch == '*') {
3497 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3498 "\"server_name *\" is unsupported, use "
3499 "\"server_name_in_redirect off\" instead");
3500 return NGX_CONF_ERROR;
3501 }
3502
Igor Sysoev305a9d82005-12-26 17:07:48 +00003503 sn = ngx_array_push(&cscf->server_names);
Igor Sysoevc1571722005-03-19 12:38:37 +00003504 if (sn == NULL) {
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00003505 return NGX_CONF_ERROR;
3506 }
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003507
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003508#if (NGX_PCRE)
3509 sn->regex = NULL;
3510#endif
Igor Sysoevcd8b43c2009-10-21 16:52:10 +00003511 sn->server = cscf;
Igor Sysoev99c3ab92007-12-27 09:17:20 +00003512 sn->name = value[i];
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003513
3514 if (value[i].data[0] != '~') {
Igor Sysoeva1b92a92009-11-29 20:39:32 +00003515 ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003516 continue;
3517 }
3518
3519#if (NGX_PCRE)
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00003520 {
Igor Sysoeva1b92a92009-11-29 20:39:32 +00003521 u_char *p;
3522 ngx_regex_compile_t rc;
3523 u_char errstr[NGX_MAX_CONF_ERRSTR];
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00003524
Igor Sysoevbe9d1652009-09-14 09:48:48 +00003525 if (value[i].len == 1) {
3526 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3527 "empty regex in server name \"%V\"", &value[i]);
3528 return NGX_CONF_ERROR;
3529 }
3530
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003531 value[i].len--;
3532 value[i].data++;
3533
Igor Sysoevc05f20e2009-11-16 12:19:02 +00003534 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003535
Igor Sysoevc05f20e2009-11-16 12:19:02 +00003536 rc.pattern = value[i];
3537 rc.err.len = NGX_MAX_CONF_ERRSTR;
3538 rc.err.data = errstr;
3539
Igor Sysoeva1b92a92009-11-29 20:39:32 +00003540 for (p = value[i].data; p < value[i].data + value[i].len; p++) {
3541 if (*p >= 'A' && *p <= 'Z') {
3542 rc.options = NGX_REGEX_CASELESS;
3543 break;
3544 }
3545 }
3546
Igor Sysoevc05f20e2009-11-16 12:19:02 +00003547 sn->regex = ngx_http_regex_compile(cf, &rc);
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003548 if (sn->regex == NULL) {
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003549 return NGX_CONF_ERROR;
3550 }
3551
Igor Sysoev99c3ab92007-12-27 09:17:20 +00003552 sn->name = value[i];
Igor Sysoevc05f20e2009-11-16 12:19:02 +00003553 cscf->captures = (rc.captures > 0);
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00003554 }
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003555#else
3556 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3557 "the using of the regex \"%V\" "
3558 "requires PCRE library", &value[i]);
3559
3560 return NGX_CONF_ERROR;
3561#endif
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003562 }
Igor Sysoev13933252003-05-29 13:02:09 +00003563
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003564 return NGX_CONF_OK;
3565}
Igor Sysoev9d639522003-07-07 06:11:50 +00003566
3567
Igor Sysoevaa828612005-02-09 14:31:07 +00003568static char *
3569ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev10a543a2004-03-16 07:10:12 +00003570{
Igor Sysoev30870b42009-11-13 19:59:54 +00003571 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev10a543a2004-03-16 07:10:12 +00003572
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003573 ngx_str_t *value;
3574 ngx_uint_t alias, n;
3575 ngx_http_script_compile_t sc;
Igor Sysoev10a543a2004-03-16 07:10:12 +00003576
3577 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
3578
Igor Sysoev30870b42009-11-13 19:59:54 +00003579 if (clcf->root.data) {
Igor Sysoeva741f8d2004-03-30 20:31:58 +00003580
3581 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
3582
Igor Sysoev30870b42009-11-13 19:59:54 +00003583 if ((ngx_uint_t) clcf->alias == alias) {
Igor Sysoev10a543a2004-03-16 07:10:12 +00003584 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003585 "\"%V\" directive is duplicate",
3586 &cmd->name);
Igor Sysoev10a543a2004-03-16 07:10:12 +00003587 } else {
3588 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003589 "\"%V\" directive is duplicate, "
Igor Sysoev10a543a2004-03-16 07:10:12 +00003590 "\"%s\" directive is specified before",
Igor Sysoev30870b42009-11-13 19:59:54 +00003591 &cmd->name, clcf->alias ? "alias" : "root");
Igor Sysoev10a543a2004-03-16 07:10:12 +00003592 }
3593
3594 return NGX_CONF_ERROR;
3595 }
3596
Igor Sysoev30870b42009-11-13 19:59:54 +00003597 if (clcf->named && alias) {
Igor Sysoev8889b652007-07-29 18:11:39 +00003598 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3599 "the \"alias\" directive may not be used "
3600 "inside named location");
3601
3602 return NGX_CONF_ERROR;
3603 }
3604
Igor Sysoev10a543a2004-03-16 07:10:12 +00003605 value = cf->args->elts;
3606
Igor Sysoev10b98942007-04-02 05:43:21 +00003607 if (ngx_strstr(value[1].data, "$document_root")
3608 || ngx_strstr(value[1].data, "${document_root}"))
Igor Sysoevceab3692007-04-01 09:03:14 +00003609 {
3610 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3611 "the $document_root variable may not be used "
3612 "in the \"%V\" directive",
3613 &cmd->name);
3614
3615 return NGX_CONF_ERROR;
3616 }
3617
Igor Sysoev4ca2acf2008-09-29 04:47:22 +00003618 if (ngx_strstr(value[1].data, "$realpath_root")
3619 || ngx_strstr(value[1].data, "${realpath_root}"))
3620 {
3621 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3622 "the $realpath_root variable may not be used "
3623 "in the \"%V\" directive",
3624 &cmd->name);
3625
3626 return NGX_CONF_ERROR;
3627 }
3628
Igor Sysoev30870b42009-11-13 19:59:54 +00003629 clcf->alias = alias;
3630 clcf->root = value[1];
Igor Sysoev10a543a2004-03-16 07:10:12 +00003631
Igor Sysoev30870b42009-11-13 19:59:54 +00003632 if (!alias && clcf->root.data[clcf->root.len - 1] == '/') {
3633 clcf->root.len--;
Igor Sysoev71057632004-08-30 19:24:51 +00003634 }
3635
Igor Sysoev30870b42009-11-13 19:59:54 +00003636 if (clcf->root.data[0] != '$') {
3637 if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) {
Igor Sysoev8f125582006-07-28 15:16:17 +00003638 return NGX_CONF_ERROR;
3639 }
Igor Sysoev34303462006-01-24 16:08:27 +00003640 }
3641
Igor Sysoev30870b42009-11-13 19:59:54 +00003642 n = ngx_http_script_variables_count(&clcf->root);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003643
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003644 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3645
Igor Sysoev925baa02009-03-06 12:49:22 +00003646 if (n) {
3647 sc.cf = cf;
Igor Sysoev30870b42009-11-13 19:59:54 +00003648 sc.source = &clcf->root;
3649 sc.lengths = &clcf->root_lengths;
3650 sc.values = &clcf->root_values;
Igor Sysoev925baa02009-03-06 12:49:22 +00003651 sc.variables = n;
3652 sc.complete_lengths = 1;
3653 sc.complete_values = 1;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003654
Igor Sysoev925baa02009-03-06 12:49:22 +00003655 if (ngx_http_script_compile(&sc) != NGX_OK) {
3656 return NGX_CONF_ERROR;
3657 }
3658 }
3659
Igor Sysoev10a543a2004-03-16 07:10:12 +00003660 return NGX_CONF_OK;
3661}
3662
3663
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003664static ngx_http_method_name_t ngx_methods_names[] = {
Igor Sysoev722231f2007-02-14 18:51:19 +00003665 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
3666 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
3667 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
3668 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
3669 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
3670 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
3671 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
3672 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
3673 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
3674 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
3675 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
3676 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
3677 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003678 { NULL, 0 }
3679};
3680
3681
3682static char *
3683ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3684{
Igor Sysoeve55988c2008-05-24 14:14:13 +00003685 ngx_http_core_loc_conf_t *pclcf = conf;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003686
3687 char *rv;
3688 void *mconf;
3689 ngx_str_t *value;
3690 ngx_uint_t i;
3691 ngx_conf_t save;
3692 ngx_http_module_t *module;
3693 ngx_http_conf_ctx_t *ctx, *pctx;
3694 ngx_http_method_name_t *name;
Igor Sysoeve55988c2008-05-24 14:14:13 +00003695 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003696
Igor Sysoeve55988c2008-05-24 14:14:13 +00003697 if (pclcf->limit_except) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003698 return "duplicate";
3699 }
3700
Igor Sysoeve55988c2008-05-24 14:14:13 +00003701 pclcf->limit_except = 0xffffffff;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003702
3703 value = cf->args->elts;
3704
3705 for (i = 1; i < cf->args->nelts; i++) {
3706 for (name = ngx_methods_names; name->name; name++) {
3707
3708 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
Igor Sysoeve55988c2008-05-24 14:14:13 +00003709 pclcf->limit_except &= name->method;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003710 goto next;
3711 }
3712 }
3713
3714 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3715 "invalid method \"%V\"", &value[i]);
3716 return NGX_CONF_ERROR;
3717
3718 next:
3719 continue;
3720 }
3721
Igor Sysoeve55988c2008-05-24 14:14:13 +00003722 if (!(pclcf->limit_except & NGX_HTTP_GET)) {
3723 pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003724 }
3725
3726 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
3727 if (ctx == NULL) {
3728 return NGX_CONF_ERROR;
3729 }
3730
3731 pctx = cf->ctx;
3732 ctx->main_conf = pctx->main_conf;
3733 ctx->srv_conf = pctx->srv_conf;
3734
3735 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
3736 if (ctx->loc_conf == NULL) {
3737 return NGX_CONF_ERROR;
3738 }
3739
3740 for (i = 0; ngx_modules[i]; i++) {
3741 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
3742 continue;
3743 }
3744
3745 module = ngx_modules[i]->ctx;
3746
3747 if (module->create_loc_conf) {
3748
3749 mconf = module->create_loc_conf(cf);
3750 if (mconf == NULL) {
3751 return NGX_CONF_ERROR;
3752 }
3753
3754 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
3755 }
3756 }
3757
3758
Igor Sysoeve55988c2008-05-24 14:14:13 +00003759 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
3760 pclcf->limit_except_loc_conf = ctx->loc_conf;
3761 clcf->loc_conf = ctx->loc_conf;
3762 clcf->name = pclcf->name;
3763 clcf->noname = 1;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003764
Igor Sysoeve55988c2008-05-24 14:14:13 +00003765 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003766 return NGX_CONF_ERROR;
3767 }
3768
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003769 save = *cf;
3770 cf->ctx = ctx;
3771 cf->cmd_type = NGX_HTTP_LMT_CONF;
3772
3773 rv = ngx_conf_parse(cf, NULL);
3774
3775 *cf = save;
3776
3777 return rv;
3778}
3779
3780
Igor Sysoevaa828612005-02-09 14:31:07 +00003781static char *
Igor Sysoev385af282008-07-30 12:34:04 +00003782ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3783{
3784 ngx_http_core_loc_conf_t *clcf = conf;
3785
3786 ngx_str_t *value;
3787
3788 if (clcf->directio != NGX_CONF_UNSET) {
3789 return "is duplicate";
3790 }
3791
3792 value = cf->args->elts;
3793
3794 if (ngx_strcmp(value[1].data, "off") == 0) {
Igor Sysoevad1e1232008-10-16 13:31:00 +00003795 clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
Igor Sysoev385af282008-07-30 12:34:04 +00003796 return NGX_CONF_OK;
3797 }
3798
3799 clcf->directio = ngx_parse_offset(&value[1]);
3800 if (clcf->directio == (off_t) NGX_ERROR) {
3801 return "invalid value";
3802 }
3803
3804 return NGX_CONF_OK;
3805}
3806
3807
3808static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00003809ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev74e95c22003-11-09 20:03:38 +00003810{
Igor Sysoev30870b42009-11-13 19:59:54 +00003811 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003812
Igor Sysoev17f0e662009-03-22 09:40:04 +00003813 u_char *p;
3814 ngx_int_t overwrite;
3815 ngx_str_t *value, uri, args;
3816 ngx_uint_t i, n;
3817 ngx_http_err_page_t *err;
3818 ngx_http_complex_value_t cv;
3819 ngx_http_compile_complex_value_t ccv;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003820
Igor Sysoev30870b42009-11-13 19:59:54 +00003821 if (clcf->error_pages == NULL) {
3822 clcf->error_pages = ngx_array_create(cf->pool, 4,
3823 sizeof(ngx_http_err_page_t));
3824 if (clcf->error_pages == NULL) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003825 return NGX_CONF_ERROR;
3826 }
3827 }
3828
3829 value = cf->args->elts;
3830
Igor Sysoev732a2712004-04-21 18:54:33 +00003831 i = cf->args->nelts - 2;
3832
3833 if (value[i].data[0] == '=') {
3834 if (i == 1) {
3835 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003836 "invalid value \"%V\"", &value[i]);
Igor Sysoev732a2712004-04-21 18:54:33 +00003837 return NGX_CONF_ERROR;
3838 }
3839
Igor Sysoeva2573672005-10-05 14:46:21 +00003840 if (value[i].len > 1) {
3841 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
Igor Sysoev732a2712004-04-21 18:54:33 +00003842
Igor Sysoeva2573672005-10-05 14:46:21 +00003843 if (overwrite == NGX_ERROR) {
3844 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3845 "invalid value \"%V\"", &value[i]);
3846 return NGX_CONF_ERROR;
3847 }
3848
3849 } else {
3850 overwrite = 0;
Igor Sysoev732a2712004-04-21 18:54:33 +00003851 }
3852
3853 n = 2;
3854
3855 } else {
Igor Sysoeva2573672005-10-05 14:46:21 +00003856 overwrite = -1;
Igor Sysoev732a2712004-04-21 18:54:33 +00003857 n = 1;
3858 }
3859
Igor Sysoev08e63d42006-08-14 15:09:38 +00003860 uri = value[cf->args->nelts - 1];
Igor Sysoev08e63d42006-08-14 15:09:38 +00003861
Igor Sysoev17f0e662009-03-22 09:40:04 +00003862 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
Igor Sysoev08e63d42006-08-14 15:09:38 +00003863
Igor Sysoev17f0e662009-03-22 09:40:04 +00003864 ccv.cf = cf;
3865 ccv.value = &uri;
3866 ccv.complex_value = &cv;
Igor Sysoev08e63d42006-08-14 15:09:38 +00003867
Igor Sysoev17f0e662009-03-22 09:40:04 +00003868 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
3869 return NGX_CONF_ERROR;
Igor Sysoev08e63d42006-08-14 15:09:38 +00003870 }
3871
Igor Sysoev17f0e662009-03-22 09:40:04 +00003872 args.len = 0;
3873 args.data = NULL;
3874
Igor Sysoev64851bb2009-04-07 15:50:08 +00003875 if (cv.lengths == NULL && uri.data[0] == '/') {
Igor Sysoev17f0e662009-03-22 09:40:04 +00003876 p = (u_char *) ngx_strchr(uri.data, '?');
3877
3878 if (p) {
3879 cv.value.len = p - uri.data;
3880 cv.value.data = uri.data;
3881 p++;
3882 args.len = (uri.data + uri.len) - p;
3883 args.data = p;
3884 }
3885 }
Igor Sysoev615fe7f2008-04-29 10:06:43 +00003886
Igor Sysoev732a2712004-04-21 18:54:33 +00003887 for (i = 1; i < cf->args->nelts - n; i++) {
Igor Sysoev30870b42009-11-13 19:59:54 +00003888 err = ngx_array_push(clcf->error_pages);
Igor Sysoevc1571722005-03-19 12:38:37 +00003889 if (err == NULL) {
Igor Sysoev732a2712004-04-21 18:54:33 +00003890 return NGX_CONF_ERROR;
3891 }
3892
Igor Sysoev3f4685f2004-04-25 20:13:21 +00003893 err->status = ngx_atoi(value[i].data, value[i].len);
Igor Sysoevaa828612005-02-09 14:31:07 +00003894
Igor Sysoev586f7a52006-09-25 17:48:34 +00003895 if (err->status == NGX_ERROR || err->status == 499) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003896 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003897 "invalid value \"%V\"", &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00003898 return NGX_CONF_ERROR;
3899 }
3900
Igor Sysoev3f4685f2004-04-25 20:13:21 +00003901 if (err->status < 400 || err->status > 599) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003902 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003903 "value \"%V\" must be between 400 and 599",
3904 &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00003905 return NGX_CONF_ERROR;
3906 }
3907
Igor Sysoevfb140922008-03-10 14:45:41 +00003908 if (overwrite >= 0) {
3909 err->overwrite = overwrite;
3910
3911 } else {
3912 switch (err->status) {
3913 case NGX_HTTP_TO_HTTPS:
3914 case NGX_HTTPS_CERT_ERROR:
3915 case NGX_HTTPS_NO_CERT:
3916 err->overwrite = NGX_HTTP_BAD_REQUEST;
3917 break;
3918
3919 default:
3920 err->overwrite = err->status;
3921 break;
3922 }
3923 }
Igor Sysoeva2573672005-10-05 14:46:21 +00003924
Igor Sysoev17f0e662009-03-22 09:40:04 +00003925 err->value = cv;
Igor Sysoev1af70902009-03-22 15:52:52 +00003926 err->args = args;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003927 }
3928
3929 return NGX_CONF_OK;
3930}
3931
3932
Igor Sysoevaa828612005-02-09 14:31:07 +00003933static char *
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003934ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3935{
3936 ngx_http_core_loc_conf_t *clcf = conf;
3937
3938 ngx_str_t *value;
Igor Sysoevecd82282009-04-11 11:02:36 +00003939 ngx_int_t code;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003940 ngx_uint_t i, n;
3941 ngx_http_try_file_t *tf;
3942 ngx_http_script_compile_t sc;
3943 ngx_http_core_main_conf_t *cmcf;
3944
3945 if (clcf->try_files) {
3946 return "is duplicate";
3947 }
3948
3949 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
3950
3951 cmcf->try_files = 1;
3952
3953 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
3954 if (tf == NULL) {
3955 return NGX_CONF_ERROR;
3956 }
3957
3958 clcf->try_files = tf;
3959
3960 value = cf->args->elts;
3961
3962 for (i = 0; i < cf->args->nelts - 1; i++) {
3963
3964 tf[i].name = value[i + 1];
3965
Igor Sysoev319dc272009-01-21 12:11:22 +00003966 if (tf[i].name.data[tf[i].name.len - 1] == '/') {
3967 tf[i].test_dir = 1;
3968 tf[i].name.len--;
Igor Sysoevcd70a522009-03-20 16:47:23 +00003969 tf[i].name.data[tf[i].name.len] = '\0';
Igor Sysoev319dc272009-01-21 12:11:22 +00003970 }
3971
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003972 n = ngx_http_script_variables_count(&tf[i].name);
3973
3974 if (n) {
3975 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3976
3977 sc.cf = cf;
3978 sc.source = &tf[i].name;
3979 sc.lengths = &tf[i].lengths;
3980 sc.values = &tf[i].values;
3981 sc.variables = n;
3982 sc.complete_lengths = 1;
3983 sc.complete_values = 1;
3984
3985 if (ngx_http_script_compile(&sc) != NGX_OK) {
3986 return NGX_CONF_ERROR;
3987 }
3988
3989 } else {
3990 /* add trailing '\0' to length */
3991 tf[i].name.len++;
3992 }
3993 }
3994
Igor Sysoevecd82282009-04-11 11:02:36 +00003995 if (tf[i - 1].name.data[0] == '=') {
3996
3997 code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
3998
3999 if (code == NGX_ERROR) {
4000 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4001 "invalid code \"%*s\"",
4002 tf[i - 1].name.len - 1, tf[i - 1].name.data);
4003 return NGX_CONF_ERROR;
4004 }
4005
4006 tf[i].code = code;
4007 }
4008
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00004009 return NGX_CONF_OK;
4010}
4011
4012
4013static char *
Igor Sysoev140c7552007-09-01 12:12:48 +00004014ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4015{
Igor Sysoev30870b42009-11-13 19:59:54 +00004016 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev140c7552007-09-01 12:12:48 +00004017
4018 time_t inactive;
4019 ngx_str_t *value, s;
4020 ngx_int_t max;
4021 ngx_uint_t i;
4022
Igor Sysoev30870b42009-11-13 19:59:54 +00004023 if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) {
Igor Sysoev140c7552007-09-01 12:12:48 +00004024 return "is duplicate";
4025 }
4026
4027 value = cf->args->elts;
4028
4029 max = 0;
4030 inactive = 60;
4031
4032 for (i = 1; i < cf->args->nelts; i++) {
4033
4034 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
4035
4036 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
4037 if (max == NGX_ERROR) {
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004038 goto failed;
Igor Sysoev140c7552007-09-01 12:12:48 +00004039 }
4040
4041 continue;
4042 }
4043
4044 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
4045
4046 s.len = value[i].len - 9;
4047 s.data = value[i].data + 9;
4048
4049 inactive = ngx_parse_time(&s, 1);
4050 if (inactive < 0) {
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004051 goto failed;
Igor Sysoev140c7552007-09-01 12:12:48 +00004052 }
4053
4054 continue;
4055 }
4056
4057 if (ngx_strcmp(value[i].data, "off") == 0) {
4058
Igor Sysoev30870b42009-11-13 19:59:54 +00004059 clcf->open_file_cache = NULL;
Igor Sysoev140c7552007-09-01 12:12:48 +00004060
4061 continue;
4062 }
4063
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004064 failed:
4065
Igor Sysoev140c7552007-09-01 12:12:48 +00004066 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4067 "invalid \"open_file_cache\" parameter \"%V\"",
4068 &value[i]);
4069 return NGX_CONF_ERROR;
4070 }
4071
Igor Sysoev30870b42009-11-13 19:59:54 +00004072 if (clcf->open_file_cache == NULL) {
Igor Sysoev140c7552007-09-01 12:12:48 +00004073 return NGX_CONF_OK;
4074 }
4075
4076 if (max == 0) {
4077 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4078 "\"open_file_cache\" must have \"max\" parameter");
4079 return NGX_CONF_ERROR;
4080 }
4081
Igor Sysoev30870b42009-11-13 19:59:54 +00004082 clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
4083 if (clcf->open_file_cache) {
Igor Sysoev140c7552007-09-01 12:12:48 +00004084 return NGX_CONF_OK;
4085 }
4086
4087 return NGX_CONF_ERROR;
4088}
4089
4090
4091static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00004092ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4093{
Igor Sysoev30870b42009-11-13 19:59:54 +00004094 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev899b44e2005-05-12 14:58:06 +00004095
Igor Sysoevc134eb02009-04-24 14:27:36 +00004096 ngx_str_t *value;
4097
Igor Sysoev30870b42009-11-13 19:59:54 +00004098 if (clcf->error_log) {
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00004099 return "is duplicate";
4100 }
4101
Igor Sysoevc134eb02009-04-24 14:27:36 +00004102 value = cf->args->elts;
4103
Igor Sysoev30870b42009-11-13 19:59:54 +00004104 clcf->error_log = ngx_log_create(cf->cycle, &value[1]);
4105 if (clcf->error_log == NULL) {
Igor Sysoev899b44e2005-05-12 14:58:06 +00004106 return NGX_CONF_ERROR;
4107 }
4108
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00004109 if (cf->args->nelts == 2) {
Igor Sysoev30870b42009-11-13 19:59:54 +00004110 clcf->error_log->log_level = NGX_LOG_ERR;
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00004111 return NGX_CONF_OK;
4112 }
4113
Igor Sysoev30870b42009-11-13 19:59:54 +00004114 return ngx_log_set_levels(cf, clcf->error_log);
Igor Sysoev899b44e2005-05-12 14:58:06 +00004115}
4116
4117
4118static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00004119ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004120{
Igor Sysoev30870b42009-11-13 19:59:54 +00004121 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004122
4123 ngx_str_t *value;
4124
Igor Sysoev30870b42009-11-13 19:59:54 +00004125 if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004126 return "is duplicate";
4127 }
4128
4129 value = cf->args->elts;
4130
Igor Sysoev30870b42009-11-13 19:59:54 +00004131 clcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
Igor Sysoevaa828612005-02-09 14:31:07 +00004132
Igor Sysoev30870b42009-11-13 19:59:54 +00004133 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004134 return "invalid value";
4135 }
4136
Igor Sysoev30870b42009-11-13 19:59:54 +00004137 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004138 return "value must be less than 597 hours";
4139 }
4140
4141 if (cf->args->nelts == 2) {
4142 return NGX_CONF_OK;
4143 }
4144
Igor Sysoev30870b42009-11-13 19:59:54 +00004145 clcf->keepalive_header = ngx_parse_time(&value[2], 1);
Igor Sysoevaa828612005-02-09 14:31:07 +00004146
Igor Sysoev30870b42009-11-13 19:59:54 +00004147 if (clcf->keepalive_header == NGX_ERROR) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004148 return "invalid value";
4149 }
4150
Igor Sysoev30870b42009-11-13 19:59:54 +00004151 if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004152 return "value must be less than 68 years";
4153 }
4154
4155 return NGX_CONF_OK;
4156}
4157
4158
Igor Sysoevaa828612005-02-09 14:31:07 +00004159static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00004160ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev9d639522003-07-07 06:11:50 +00004161{
Igor Sysoev30870b42009-11-13 19:59:54 +00004162 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev9d639522003-07-07 06:11:50 +00004163
Igor Sysoev30870b42009-11-13 19:59:54 +00004164 if (clcf->internal != NGX_CONF_UNSET) {
Igor Sysoev899b44e2005-05-12 14:58:06 +00004165 return "is duplicate";
Igor Sysoev03420a62004-01-20 20:40:08 +00004166 }
Igor Sysoev9d639522003-07-07 06:11:50 +00004167
Igor Sysoev30870b42009-11-13 19:59:54 +00004168 clcf->internal = 1;
Igor Sysoev899b44e2005-05-12 14:58:06 +00004169
4170 return NGX_CONF_OK;
Igor Sysoev9d639522003-07-07 06:11:50 +00004171}
Igor Sysoevb5faed22003-10-29 08:30:44 +00004172
4173
Igor Sysoevaa828612005-02-09 14:31:07 +00004174static char *
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004175ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4176{
4177 ngx_http_core_loc_conf_t *clcf = conf;
4178
4179 ngx_url_t u;
4180 ngx_str_t *value;
4181
Igor Sysoevf39876c2008-03-06 08:48:55 +00004182 if (clcf->resolver) {
4183 return "is duplicate";
4184 }
4185
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004186 value = cf->args->elts;
4187
Igor Sysoev4d65f652007-11-30 22:08:59 +00004188 ngx_memzero(&u, sizeof(ngx_url_t));
4189
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004190 u.host = value[1];
4191 u.port = 53;
4192
4193 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
4194 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
4195 return NGX_CONF_ERROR;
4196 }
4197
Igor Sysoevdfd55112008-03-04 10:42:05 +00004198 clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004199 if (clcf->resolver == NULL) {
4200 return NGX_OK;
4201 }
4202
4203 return NGX_CONF_OK;
4204}
4205
4206
Igor Sysoevc16b0052007-12-27 14:21:59 +00004207#if (NGX_HTTP_GZIP)
4208
4209static char *
4210ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4211{
Igor Sysoevc16b0052007-12-27 14:21:59 +00004212 ngx_http_core_loc_conf_t *clcf = conf;
4213
Igor Sysoev54477e42008-08-26 15:09:28 +00004214#if (NGX_PCRE)
4215
Igor Sysoevc05f20e2009-11-16 12:19:02 +00004216 ngx_str_t *value;
4217 ngx_uint_t i;
4218 ngx_regex_elt_t *re;
4219 ngx_regex_compile_t rc;
4220 u_char errstr[NGX_MAX_CONF_ERRSTR];
Igor Sysoevc16b0052007-12-27 14:21:59 +00004221
4222 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
4223 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
4224 sizeof(ngx_regex_elt_t));
4225 if (clcf->gzip_disable == NULL) {
4226 return NGX_CONF_ERROR;
4227 }
4228 }
4229
4230 value = cf->args->elts;
4231
Igor Sysoevc05f20e2009-11-16 12:19:02 +00004232 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
4233
4234 rc.pool = cf->pool;
4235 rc.err.len = NGX_MAX_CONF_ERRSTR;
4236 rc.err.data = errstr;
Igor Sysoevc16b0052007-12-27 14:21:59 +00004237
4238 for (i = 1; i < cf->args->nelts; i++) {
4239
Igor Sysoev54477e42008-08-26 15:09:28 +00004240 if (ngx_strcmp(value[1].data, "msie6") == 0) {
4241 clcf->gzip_disable_msie6 = 1;
4242 continue;
4243 }
4244
Igor Sysoevc16b0052007-12-27 14:21:59 +00004245 re = ngx_array_push(clcf->gzip_disable);
4246 if (re == NULL) {
4247 return NGX_CONF_ERROR;
4248 }
4249
Igor Sysoevc05f20e2009-11-16 12:19:02 +00004250 rc.pattern = value[1];
4251 rc.options = NGX_REGEX_CASELESS;
Igor Sysoevc16b0052007-12-27 14:21:59 +00004252
Igor Sysoevc05f20e2009-11-16 12:19:02 +00004253 if (ngx_regex_compile(&rc) != NGX_OK) {
4254 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
Igor Sysoevc16b0052007-12-27 14:21:59 +00004255 return NGX_CONF_ERROR;
4256 }
4257
Igor Sysoevc05f20e2009-11-16 12:19:02 +00004258 re->regex = rc.regex;
Igor Sysoevc16b0052007-12-27 14:21:59 +00004259 re->name = value[i].data;
4260 }
4261
4262 return NGX_CONF_OK;
4263
4264#else
Igor Sysoev54477e42008-08-26 15:09:28 +00004265 ngx_str_t *value;
4266
4267 value = cf->args->elts;
4268
4269 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "msie6") == 0) {
4270 clcf->gzip_disable_msie6 = 1;
4271 return NGX_CONF_OK;
4272 }
4273
Igor Sysoevc16b0052007-12-27 14:21:59 +00004274 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev54477e42008-08-26 15:09:28 +00004275 "without PCRE library \"gzip_disable\" supports "
4276 "builtin \"msie6\" mask only");
Igor Sysoevc16b0052007-12-27 14:21:59 +00004277
4278 return NGX_CONF_ERROR;
4279#endif
4280}
4281
4282#endif
4283
4284
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004285static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00004286ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
Igor Sysoevb5faed22003-10-29 08:30:44 +00004287{
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00004288#if (NGX_FREEBSD)
Igor Sysoev42b12b32004-12-02 18:40:46 +00004289 ssize_t *np = data;
Igor Sysoev924bd792004-10-11 15:07:03 +00004290
Igor Sysoev08e63d42006-08-14 15:09:38 +00004291 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
Igor Sysoevb5faed22003-10-29 08:30:44 +00004292 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4293 "\"send_lowat\" must be less than %d "
4294 "(sysctl net.inet.tcp.sendspace)",
4295 ngx_freebsd_net_inet_tcp_sendspace);
4296
4297 return NGX_CONF_ERROR;
4298 }
4299
Igor Sysoevf6906042004-11-25 16:17:31 +00004300#elif !(NGX_HAVE_SO_SNDLOWAT)
Igor Sysoev42b12b32004-12-02 18:40:46 +00004301 ssize_t *np = data;
Igor Sysoevb5faed22003-10-29 08:30:44 +00004302
4303 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4304 "\"send_lowat\" is not supported, ignored");
4305
Igor Sysoev924bd792004-10-11 15:07:03 +00004306 *np = 0;
4307
Igor Sysoevb5faed22003-10-29 08:30:44 +00004308#endif
4309
4310 return NGX_CONF_OK;
4311}
Igor Sysoev08d068f2007-05-07 09:20:42 +00004312
4313
4314static char *
4315ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
4316{
4317 size_t *sp = data;
4318
4319 if (*sp < NGX_MIN_POOL_SIZE) {
4320 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4321 "pool must be no less than %uz", NGX_MIN_POOL_SIZE);
4322
4323 return NGX_CONF_ERROR;
4324 }
4325
4326 return NGX_CONF_OK;
4327}