blob: be4f1958d22a4bd574e1c620c82ef10d655ec077 [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 Sysoev925baa02009-03-06 12:49:22 +00001423 ngx_int_t n, len;
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
Igor Sysoev925baa02009-03-06 12:49:22 +00001457 len = 0;
1458
Igor Sysoeve55988c2008-05-24 14:14:13 +00001459 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
1460
1461 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1462 "test location: ~ \"%V\"", &(*clcfp)->name);
1463
Igor Sysoevc7e87af2009-03-14 19:24:17 +00001464 if ((*clcfp)->captures) {
Igor Sysoev925baa02009-03-06 12:49:22 +00001465
Igor Sysoev000609a2009-03-11 13:04:02 +00001466 len = (NGX_HTTP_MAX_CAPTURES + 1) * 3;
Igor Sysoev925baa02009-03-06 12:49:22 +00001467
Igor Sysoev925baa02009-03-06 12:49:22 +00001468 if (r->captures == NULL) {
Igor Sysoevc7e87af2009-03-14 19:24:17 +00001469 r->captures = ngx_palloc(r->pool, len * sizeof(int));
1470 if (r->captures == NULL) {
1471 return NGX_ERROR;
1472 }
Igor Sysoev925baa02009-03-06 12:49:22 +00001473 }
1474 }
1475
1476 n = ngx_regex_exec((*clcfp)->regex, &r->uri, r->captures, len);
Igor Sysoeve55988c2008-05-24 14:14:13 +00001477
1478 if (n == NGX_REGEX_NO_MATCHED) {
1479 continue;
1480 }
1481
1482 if (n < 0) {
1483 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1484 ngx_regex_exec_n
1485 " failed: %d on \"%V\" using \"%V\"",
1486 n, &r->uri, &(*clcfp)->name);
Igor Sysoevdc911282008-08-17 18:02:55 +00001487 return NGX_ERROR;
Igor Sysoeve55988c2008-05-24 14:14:13 +00001488 }
1489
1490 /* match */
1491
1492 r->loc_conf = (*clcfp)->loc_conf;
1493
Igor Sysoev925baa02009-03-06 12:49:22 +00001494 r->ncaptures = len;
1495 r->captures_data = r->uri.data;
1496
Igor Sysoeve55988c2008-05-24 14:14:13 +00001497 /* look up nested locations */
1498
Igor Sysoevdc911282008-08-17 18:02:55 +00001499 rc = ngx_http_core_find_location(r);
1500
1501 return (rc == NGX_ERROR) ? rc : NGX_OK;
Igor Sysoeve55988c2008-05-24 14:14:13 +00001502 }
1503 }
Igor Sysoev307ab0d2007-08-12 15:25:09 +00001504#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001505
Igor Sysoeve55988c2008-05-24 14:14:13 +00001506 return rc;
1507}
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001508
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001509
Igor Sysoeve55988c2008-05-24 14:14:13 +00001510/*
1511 * NGX_OK - exact match
1512 * NGX_DONE - auto redirect
1513 * NGX_AGAIN - inclusive match
1514 * NGX_DECLINED - no match
1515 */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001516
Igor Sysoeve55988c2008-05-24 14:14:13 +00001517static ngx_int_t
1518ngx_http_core_find_static_location(ngx_http_request_t *r,
1519 ngx_http_location_tree_node_t *node)
1520{
1521 u_char *uri;
1522 size_t len, n;
1523 ngx_int_t rc, rv;
1524
1525 len = r->uri.len;
1526 uri = r->uri.data;
1527
1528 rv = NGX_DECLINED;
1529
1530 for ( ;; ) {
1531
1532 if (node == NULL) {
1533 return rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001534 }
1535
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001536 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoeve55988c2008-05-24 14:14:13 +00001537 "test location: \"%*s\"", node->len, node->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001538
Igor Sysoeve55988c2008-05-24 14:14:13 +00001539 n = (len <= (size_t) node->len) ? len : node->len;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001540
Igor Sysoev0f17f6c2008-07-29 16:55:11 +00001541 rc = ngx_filename_cmp(uri, node->name, n);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001542
Igor Sysoeve55988c2008-05-24 14:14:13 +00001543 if (rc != 0) {
1544 node = (rc < 0) ? node->left : node->right;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001545
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001546 continue;
1547 }
1548
Igor Sysoeve55988c2008-05-24 14:14:13 +00001549 if (len > (size_t) node->len) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001550
Igor Sysoeve55988c2008-05-24 14:14:13 +00001551 if (node->inclusive) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001552
Igor Sysoeve55988c2008-05-24 14:14:13 +00001553 r->loc_conf = node->inclusive->loc_conf;
1554 rv = NGX_AGAIN;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001555
Igor Sysoeve55988c2008-05-24 14:14:13 +00001556 node = node->tree;
1557 uri += n;
1558 len -= n;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001559
1560 continue;
Igor Sysoevea521232004-07-26 16:21:18 +00001561 }
1562
Igor Sysoeve55988c2008-05-24 14:14:13 +00001563 /* exact only */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001564
Igor Sysoeve55988c2008-05-24 14:14:13 +00001565 node = node->right;
Igor Sysoev307ab0d2007-08-12 15:25:09 +00001566
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001567 continue;
1568 }
1569
Igor Sysoeve55988c2008-05-24 14:14:13 +00001570 if (len == (size_t) node->len) {
1571
1572 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1573 node->inclusive->loc_conf;
1574 return NGX_OK;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001575 }
1576
Igor Sysoeve55988c2008-05-24 14:14:13 +00001577 /* len < node->len */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001578
Igor Sysoeve55988c2008-05-24 14:14:13 +00001579 if (len + 1 == (size_t) node->len && node->auto_redirect) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001580
Igor Sysoeve55988c2008-05-24 14:14:13 +00001581 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1582 node->inclusive->loc_conf;
1583 rv = NGX_DONE;
1584 }
1585
1586 node = node->left;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001587 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001588}
1589
1590
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001591void *
1592ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1593{
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001594 u_char c, *lowcase;
1595 size_t len;
1596 ngx_uint_t i, hash;
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001597
1598 if (r->headers_out.content_type.len == 0) {
1599 return NULL;
1600 }
1601
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001602 len = r->headers_out.content_type_len;
1603
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001604 if (r->headers_out.content_type_lowcase == NULL) {
1605
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001606 lowcase = ngx_pnalloc(r->pool, len);
1607 if (lowcase == NULL) {
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001608 return NULL;
1609 }
1610
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001611 r->headers_out.content_type_lowcase = lowcase;
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001612
1613 hash = 0;
1614
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001615 for (i = 0; i < len; i++) {
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001616 c = ngx_tolower(r->headers_out.content_type.data[i]);
1617 hash = ngx_hash(hash, c);
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001618 lowcase[i] = c;
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001619 }
1620
1621 r->headers_out.content_type_hash = hash;
1622 }
1623
Igor Sysoev77fd67c2009-05-25 09:00:35 +00001624 return ngx_hash_find(types_hash, r->headers_out.content_type_hash,
1625 r->headers_out.content_type_lowcase, len);
Igor Sysoevb5bc3f92008-08-04 11:29:09 +00001626}
1627
1628
Igor Sysoevaa828612005-02-09 14:31:07 +00001629ngx_int_t
1630ngx_http_set_content_type(ngx_http_request_t *r)
Igor Sysoev865c1502003-11-30 20:03:18 +00001631{
Igor Sysoev6a078332008-08-04 10:18:36 +00001632 u_char c, *exten;
Igor Sysoev24025022005-12-16 15:07:08 +00001633 ngx_str_t *type;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001634 ngx_uint_t i, hash;
Igor Sysoev865c1502003-11-30 20:03:18 +00001635 ngx_http_core_loc_conf_t *clcf;
1636
Igor Sysoev08e63d42006-08-14 15:09:38 +00001637 if (r->headers_out.content_type.len) {
1638 return NGX_OK;
1639 }
1640
Igor Sysoev865c1502003-11-30 20:03:18 +00001641 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1642
1643 if (r->exten.len) {
Igor Sysoev805d9db2005-02-03 19:33:37 +00001644
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001645 hash = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001646
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001647 for (i = 0; i < r->exten.len; i++) {
1648 c = r->exten.data[i];
1649
1650 if (c >= 'A' && c <= 'Z') {
1651
Igor Sysoev6a078332008-08-04 10:18:36 +00001652 exten = ngx_pnalloc(r->pool, r->exten.len);
1653 if (exten == NULL) {
Igor Sysoev1f4220e2009-02-24 10:42:23 +00001654 return NGX_ERROR;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001655 }
1656
Igor Sysoev6a078332008-08-04 10:18:36 +00001657 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001658
1659 r->exten.data = exten;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001660
1661 break;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001662 }
1663
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001664 hash = ngx_hash(hash, c);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001665 }
1666
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001667 type = ngx_hash_find(&clcf->types_hash, hash,
Igor Sysoev24025022005-12-16 15:07:08 +00001668 r->exten.data, r->exten.len);
Igor Sysoev865c1502003-11-30 20:03:18 +00001669
Igor Sysoev24025022005-12-16 15:07:08 +00001670 if (type) {
Igor Sysoevef809b82006-06-28 16:00:26 +00001671 r->headers_out.content_type_len = type->len;
Igor Sysoev24025022005-12-16 15:07:08 +00001672 r->headers_out.content_type = *type;
Igor Sysoevef809b82006-06-28 16:00:26 +00001673
Igor Sysoev24025022005-12-16 15:07:08 +00001674 return NGX_OK;
Igor Sysoev865c1502003-11-30 20:03:18 +00001675 }
1676 }
1677
Igor Sysoevef809b82006-06-28 16:00:26 +00001678 r->headers_out.content_type_len = clcf->default_type.len;
Igor Sysoev24025022005-12-16 15:07:08 +00001679 r->headers_out.content_type = clcf->default_type;
Igor Sysoev865c1502003-11-30 20:03:18 +00001680
1681 return NGX_OK;
1682}
1683
1684
Igor Sysoevc28d6322009-07-14 08:38:28 +00001685void
Igor Sysoevaa828612005-02-09 14:31:07 +00001686ngx_http_set_exten(ngx_http_request_t *r)
Igor Sysoev3b30a902003-12-25 20:26:58 +00001687{
1688 ngx_int_t i;
1689
1690 r->exten.len = 0;
1691 r->exten.data = NULL;
1692
1693 for (i = r->uri.len - 1; i > 1; i--) {
1694 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001695
Igor Sysoev3b30a902003-12-25 20:26:58 +00001696 r->exten.len = r->uri.len - i - 1;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001697 r->exten.data = &r->uri.data[i + 1];
Igor Sysoev3b30a902003-12-25 20:26:58 +00001698
Igor Sysoevc28d6322009-07-14 08:38:28 +00001699 return;
Igor Sysoev3b30a902003-12-25 20:26:58 +00001700
1701 } else if (r->uri.data[i] == '/') {
Igor Sysoevc28d6322009-07-14 08:38:28 +00001702 return;
Igor Sysoev3b30a902003-12-25 20:26:58 +00001703 }
1704 }
1705
Igor Sysoevc28d6322009-07-14 08:38:28 +00001706 return;
Igor Sysoev3b30a902003-12-25 20:26:58 +00001707}
1708
1709
Igor Sysoevaa828612005-02-09 14:31:07 +00001710ngx_int_t
Igor Sysoev208eed22005-10-07 13:30:52 +00001711ngx_http_send_header(ngx_http_request_t *r)
1712{
1713 if (r->err_status) {
1714 r->headers_out.status = r->err_status;
1715 r->headers_out.status_line.len = 0;
1716 }
1717
1718 return ngx_http_top_header_filter(r);
1719}
1720
1721
1722ngx_int_t
1723ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1724{
Igor Sysoev8bb39122009-05-08 14:31:59 +00001725 ngx_int_t rc;
1726 ngx_connection_t *c;
Igor Sysoev208eed22005-10-07 13:30:52 +00001727
Igor Sysoev8bb39122009-05-08 14:31:59 +00001728 c = r->connection;
1729
1730 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001731 "http output filter \"%V?%V\"", &r->uri, &r->args);
Igor Sysoev208eed22005-10-07 13:30:52 +00001732
1733 rc = ngx_http_top_body_filter(r, in);
1734
1735 if (rc == NGX_ERROR) {
1736 /* NGX_ERROR may be returned by any filter */
Igor Sysoev8bb39122009-05-08 14:31:59 +00001737 c->error = 1;
Igor Sysoev208eed22005-10-07 13:30:52 +00001738 }
1739
1740 return rc;
1741}
1742
1743
1744u_char *
1745ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001746 size_t *root_length, size_t reserved)
Igor Sysoev208eed22005-10-07 13:30:52 +00001747{
Igor Sysoev8fea8852006-03-15 09:53:04 +00001748 u_char *last;
1749 size_t alias;
1750 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev208eed22005-10-07 13:30:52 +00001751
1752 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1753
1754 alias = clcf->alias ? clcf->name.len : 0;
1755
Igor Sysoev34303462006-01-24 16:08:27 +00001756 if (alias && !r->valid_location) {
1757 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1758 "\"alias\" could not be used in location \"%V\" "
1759 "where URI was rewritten", &clcf->name);
1760 return NULL;
1761 }
1762
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001763 if (clcf->root_lengths == NULL) {
Igor Sysoev208eed22005-10-07 13:30:52 +00001764
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001765 *root_length = clcf->root.len;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001766
Igor Sysoevbb7d6152009-03-14 19:20:34 +00001767 path->len = clcf->root.len + reserved + r->uri.len - alias + 1;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001768
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +00001769 path->data = ngx_pnalloc(r->pool, path->len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001770 if (path->data == NULL) {
1771 return NULL;
1772 }
1773
1774 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001775
Igor Sysoev8fea8852006-03-15 09:53:04 +00001776 } else {
Igor Sysoev1e5ef6b2009-03-26 15:24:19 +00001777
1778#if (NGX_PCRE)
1779 ngx_uint_t captures;
1780
1781 captures = alias && clcf->captures;
1782 reserved += captures ? 1 : r->uri.len - alias + 1;
1783#else
1784 reserved += r->uri.len - alias + 1;
1785#endif
Igor Sysoevf76a6c22009-03-18 12:21:19 +00001786
1787 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
Igor Sysoevc55a1042006-08-09 19:59:45 +00001788 clcf->root_values->elts)
Igor Sysoev8f125582006-07-28 15:16:17 +00001789 == NULL)
1790 {
1791 return NULL;
1792 }
1793
Igor Sysoev1f4220e2009-02-24 10:42:23 +00001794 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) {
Igor Sysoev8fea8852006-03-15 09:53:04 +00001795 return NULL;
1796 }
1797
Igor Sysoev0e5f86d2006-10-12 13:36:54 +00001798 *root_length = path->len - reserved;
1799 last = path->data + *root_length;
Igor Sysoev925baa02009-03-06 12:49:22 +00001800
Igor Sysoev1e5ef6b2009-03-26 15:24:19 +00001801#if (NGX_PCRE)
1802 if (captures) {
Igor Sysoev925baa02009-03-06 12:49:22 +00001803 *last = '\0';
1804 return last;
1805 }
Igor Sysoev1e5ef6b2009-03-26 15:24:19 +00001806#endif
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001807 }
1808
Igor Sysoev8fea8852006-03-15 09:53:04 +00001809 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
Igor Sysoev208eed22005-10-07 13:30:52 +00001810
1811 return last;
1812}
1813
1814
1815ngx_int_t
Igor Sysoevceb99292005-09-06 16:09:32 +00001816ngx_http_auth_basic_user(ngx_http_request_t *r)
1817{
1818 ngx_str_t auth, encoded;
1819 ngx_uint_t len;
1820
1821 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1822 return NGX_DECLINED;
1823 }
1824
1825 if (r->headers_in.authorization == NULL) {
1826 r->headers_in.user.data = (u_char *) "";
1827 return NGX_DECLINED;
1828 }
1829
1830 encoded = r->headers_in.authorization->value;
1831
1832 if (encoded.len < sizeof("Basic ") - 1
Igor Sysoev722231f2007-02-14 18:51:19 +00001833 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
1834 sizeof("Basic ") - 1)
1835 != 0)
Igor Sysoevceb99292005-09-06 16:09:32 +00001836 {
1837 r->headers_in.user.data = (u_char *) "";
1838 return NGX_DECLINED;
1839 }
1840
1841 encoded.len -= sizeof("Basic ") - 1;
1842 encoded.data += sizeof("Basic ") - 1;
1843
1844 while (encoded.len && encoded.data[0] == ' ') {
1845 encoded.len--;
1846 encoded.data++;
1847 }
1848
1849 if (encoded.len == 0) {
1850 r->headers_in.user.data = (u_char *) "";
1851 return NGX_DECLINED;
1852 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001853
Igor Sysoevceb99292005-09-06 16:09:32 +00001854 auth.len = ngx_base64_decoded_length(encoded.len);
Igor Sysoev7f6b2ff2008-06-17 15:00:30 +00001855 auth.data = ngx_pnalloc(r->pool, auth.len + 1);
Igor Sysoevceb99292005-09-06 16:09:32 +00001856 if (auth.data == NULL) {
1857 return NGX_ERROR;
1858 }
1859
1860 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
1861 r->headers_in.user.data = (u_char *) "";
1862 return NGX_DECLINED;
1863 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001864
Igor Sysoevceb99292005-09-06 16:09:32 +00001865 auth.data[auth.len] = '\0';
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001866
1867 for (len = 0; len < auth.len; len++) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001868 if (auth.data[len] == ':') {
1869 break;
1870 }
1871 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001872
Igor Sysoev09c684b2005-11-09 17:25:55 +00001873 if (len == 0 || len == auth.len) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001874 r->headers_in.user.data = (u_char *) "";
1875 return NGX_DECLINED;
1876 }
1877
1878 r->headers_in.user.len = len;
1879 r->headers_in.user.data = auth.data;
1880 r->headers_in.passwd.len = auth.len - len - 1;
1881 r->headers_in.passwd.data = &auth.data[len + 1];
1882
1883 return NGX_OK;
1884}
1885
1886
Igor Sysoevc16b0052007-12-27 14:21:59 +00001887#if (NGX_HTTP_GZIP)
1888
1889ngx_int_t
1890ngx_http_gzip_ok(ngx_http_request_t *r)
1891{
1892 time_t date, expires;
1893 ngx_uint_t p;
1894 ngx_array_t *cc;
1895 ngx_table_elt_t *e, *d;
1896 ngx_http_core_loc_conf_t *clcf;
1897
Igor Sysoev6c49a5a2009-11-12 13:41:56 +00001898 r->gzip_tested = 1;
Igor Sysoevc16b0052007-12-27 14:21:59 +00001899
1900 if (r != r->main
1901 || r->headers_in.accept_encoding == NULL
1902 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
1903 "gzip", 4 - 1)
1904 == NULL
1905
1906 /*
1907 * if the URL (without the "http://" prefix) is longer than 253 bytes,
1908 * then MSIE 4.x can not handle the compressed stream - it waits
1909 * too long, hangs up or crashes
1910 */
1911
1912 || (r->headers_in.msie4 && r->unparsed_uri.len > 200))
1913 {
1914 return NGX_DECLINED;
1915 }
1916
1917 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1918
Igor Sysoev54477e42008-08-26 15:09:28 +00001919 if (r->headers_in.msie6 && clcf->gzip_disable_msie6) {
1920 return NGX_DECLINED;
1921 }
1922
Igor Sysoevc16b0052007-12-27 14:21:59 +00001923 if (r->http_version < clcf->gzip_http_version) {
1924 return NGX_DECLINED;
1925 }
1926
1927 if (r->headers_in.via == NULL) {
1928 goto ok;
1929 }
1930
1931 p = clcf->gzip_proxied;
1932
1933 if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
1934 return NGX_DECLINED;
1935 }
1936
1937 if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
1938 goto ok;
1939 }
1940
1941 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
1942 goto ok;
1943 }
1944
1945 e = r->headers_out.expires;
1946
1947 if (e) {
1948
1949 if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
1950 return NGX_DECLINED;
1951 }
1952
1953 expires = ngx_http_parse_time(e->value.data, e->value.len);
1954 if (expires == NGX_ERROR) {
1955 return NGX_DECLINED;
1956 }
1957
1958 d = r->headers_out.date;
1959
1960 if (d) {
1961 date = ngx_http_parse_time(d->value.data, d->value.len);
1962 if (date == NGX_ERROR) {
1963 return NGX_DECLINED;
1964 }
1965
1966 } else {
1967 date = ngx_time();
1968 }
1969
1970 if (expires < date) {
1971 goto ok;
1972 }
1973
1974 return NGX_DECLINED;
1975 }
1976
1977 cc = &r->headers_out.cache_control;
1978
1979 if (cc->elts) {
1980
1981 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
1982 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
1983 NULL)
1984 >= 0)
1985 {
1986 goto ok;
1987 }
1988
1989 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
1990 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
1991 NULL)
1992 >= 0)
1993 {
1994 goto ok;
1995 }
1996
1997 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
1998 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
1999 NULL)
2000 >= 0)
2001 {
2002 goto ok;
2003 }
2004
2005 return NGX_DECLINED;
2006 }
2007
2008 if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
2009 return NGX_DECLINED;
2010 }
2011
2012 if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
2013 return NGX_DECLINED;
2014 }
2015
2016ok:
2017
2018#if (NGX_PCRE)
2019
2020 if (clcf->gzip_disable && r->headers_in.user_agent) {
2021
Igor Sysoevd5fe8182007-12-28 13:15:36 +00002022 if (ngx_regex_exec_array(clcf->gzip_disable,
Igor Sysoevc16b0052007-12-27 14:21:59 +00002023 &r->headers_in.user_agent->value,
2024 r->connection->log)
2025 != NGX_DECLINED)
2026 {
2027 return NGX_DECLINED;
2028 }
2029 }
2030
2031#endif
2032
Igor Sysoev6c49a5a2009-11-12 13:41:56 +00002033 r->gzip_ok = 1;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002034
2035 return NGX_OK;
2036}
2037
2038#endif
2039
2040
Igor Sysoevceb99292005-09-06 16:09:32 +00002041ngx_int_t
Igor Sysoev899b44e2005-05-12 14:58:06 +00002042ngx_http_subrequest(ngx_http_request_t *r,
Igor Sysoev9fcccaf2006-10-10 14:30:39 +00002043 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
Igor Sysoev960100e2006-10-13 15:20:10 +00002044 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
Igor Sysoev899b44e2005-05-12 14:58:06 +00002045{
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002046 ngx_connection_t *c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002047 ngx_http_request_t *sr;
2048 ngx_http_core_srv_conf_t *cscf;
2049 ngx_http_postponed_request_t *pr, *p;
2050
Igor Sysoevef809b82006-06-28 16:00:26 +00002051 r->main->subrequests--;
2052
2053 if (r->main->subrequests == 0) {
2054 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002055 "subrequests cycle while processing \"%V\"", uri);
Igor Sysoev5fd6d342006-11-02 13:48:28 +00002056 r->main->subrequests = 1;
Igor Sysoevef809b82006-06-28 16:00:26 +00002057 return NGX_ERROR;
2058 }
2059
Igor Sysoev899b44e2005-05-12 14:58:06 +00002060 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
2061 if (sr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002062 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002063 }
2064
2065 sr->signature = NGX_HTTP_MODULE;
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002066
2067 c = r->connection;
2068 sr->connection = c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002069
2070 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
2071 if (sr->ctx == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002072 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002073 }
2074
2075 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
Igor Sysoevc31a9bb2005-11-26 10:11:11 +00002076 sizeof(ngx_table_elt_t))
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002077 != NGX_OK)
Igor Sysoev899b44e2005-05-12 14:58:06 +00002078 {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002079 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002080 }
2081
2082 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2083 sr->main_conf = cscf->ctx->main_conf;
2084 sr->srv_conf = cscf->ctx->srv_conf;
2085 sr->loc_conf = cscf->ctx->loc_conf;
2086
2087 sr->pool = r->pool;
2088
2089 sr->headers_in = r->headers_in;
2090
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002091 ngx_http_clear_content_length(sr);
2092 ngx_http_clear_accept_ranges(sr);
2093 ngx_http_clear_last_modified(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002094
2095 sr->request_body = r->request_body;
2096
2097 sr->method = NGX_HTTP_GET;
2098 sr->http_version = r->http_version;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002099
2100 sr->request_line = r->request_line;
2101 sr->uri = *uri;
Igor Sysoev09c684b2005-11-09 17:25:55 +00002102
Igor Sysoev899b44e2005-05-12 14:58:06 +00002103 if (args) {
2104 sr->args = *args;
2105 }
Igor Sysoev09c684b2005-11-09 17:25:55 +00002106
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002107 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
2108 "http subrequest \"%V?%V\"", uri, &sr->args);
2109
Igor Sysoev960100e2006-10-13 15:20:10 +00002110 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;
2111 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
Igor Sysoev851cd732008-12-08 14:23:20 +00002112 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
Igor Sysoev09c684b2005-11-09 17:25:55 +00002113
Igor Sysoev899b44e2005-05-12 14:58:06 +00002114 sr->unparsed_uri = r->unparsed_uri;
Igor Sysoev5a45c682008-01-08 21:06:38 +00002115 sr->method_name = ngx_http_core_get_method;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002116 sr->http_protocol = r->http_protocol;
2117
Igor Sysoevc28d6322009-07-14 08:38:28 +00002118 ngx_http_set_exten(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002119
Igor Sysoevf6e1fe32005-10-04 10:38:53 +00002120 sr->main = r->main;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002121 sr->parent = r;
Igor Sysoev960100e2006-10-13 15:20:10 +00002122 sr->post_subrequest = ps;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002123 sr->read_event_handler = ngx_http_request_empty_handler;
Igor Sysoev851cd732008-12-08 14:23:20 +00002124 sr->write_event_handler = ngx_http_handler;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002125
Igor Sysoevd8e54ad2008-12-24 06:11:04 +00002126 if (c->data == r && r->postponed == NULL) {
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002127 c->data = sr;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002128 }
2129
Igor Sysoev899b44e2005-05-12 14:58:06 +00002130 sr->variables = r->variables;
2131
2132 sr->log_handler = r->log_handler;
2133
2134 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
2135 if (pr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00002136 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002137 }
2138
2139 pr->request = sr;
2140 pr->out = NULL;
2141 pr->next = NULL;
2142
2143 if (r->postponed) {
2144 for (p = r->postponed; p->next; p = p->next) { /* void */ }
2145 p->next = pr;
2146
2147 } else {
2148 r->postponed = pr;
2149 }
2150
2151 sr->internal = 1;
2152
Igor Sysoev31eb8c02005-09-23 11:02:22 +00002153 sr->discard_body = r->discard_body;
Igor Sysoev303df472008-12-26 13:43:42 +00002154 sr->expect_tested = 1;
Igor Sysoevd52477f2005-05-16 13:53:20 +00002155 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
2156
Igor Sysoev6f134cc2006-05-23 14:54:58 +00002157 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
2158
Igor Sysoev851cd732008-12-08 14:23:20 +00002159 r->main->subrequests++;
Igor Sysoevb603dd42009-08-26 16:04:05 +00002160 r->main->count++;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002161
Igor Sysoev851cd732008-12-08 14:23:20 +00002162 *psr = sr;
Igor Sysoevac72bd12006-05-04 15:32:46 +00002163
Igor Sysoevddda4112009-08-30 09:47:11 +00002164 return ngx_http_post_request(sr, NULL);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002165}
2166
2167
2168ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +00002169ngx_http_internal_redirect(ngx_http_request_t *r,
2170 ngx_str_t *uri, ngx_str_t *args)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002171{
Igor Sysoevaa828612005-02-09 14:31:07 +00002172 ngx_http_core_srv_conf_t *cscf;
2173
Igor Sysoev5fede1e2006-08-18 14:17:54 +00002174 r->uri_changes--;
2175
2176 if (r->uri_changes == 0) {
2177 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev3f8dc592006-08-28 16:57:48 +00002178 "rewrite or internal redirection cycle "
2179 "while internal redirect to \"%V\"", uri);
2180
Igor Sysoev526f36a2009-09-10 16:34:09 +00002181 r->main->count++;
Igor Sysoev5fede1e2006-08-18 14:17:54 +00002182 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2183 return NGX_DONE;
2184 }
2185
Igor Sysoev1b735832004-11-11 14:07:14 +00002186 r->uri = *uri;
Igor Sysoev13933252003-05-29 13:02:09 +00002187
2188 if (args) {
Igor Sysoev1b735832004-11-11 14:07:14 +00002189 r->args = *args;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002190
2191 } else {
2192 r->args.len = 0;
2193 r->args.data = NULL;
Igor Sysoev13933252003-05-29 13:02:09 +00002194 }
2195
Igor Sysoevd3283ff2005-12-05 13:18:09 +00002196 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2197 "internal redirect: \"%V?%V\"", uri, &r->args);
2198
Igor Sysoevc28d6322009-07-14 08:38:28 +00002199 ngx_http_set_exten(r);
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002200
Igor Sysoevef316432006-08-16 13:09:33 +00002201 /* clear the modules contexts */
2202 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
Igor Sysoev0a280a32003-10-12 16:49:16 +00002203
Igor Sysoevaa828612005-02-09 14:31:07 +00002204 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2205 r->loc_conf = cscf->ctx->loc_conf;
2206
Igor Sysoevb85fd592005-08-23 15:36:54 +00002207 ngx_http_update_location_config(r);
2208
Igor Sysoev52859f22009-03-23 13:14:51 +00002209#if (NGX_HTTP_CACHE)
2210 r->cache = NULL;
2211#endif
2212
Igor Sysoev899b44e2005-05-12 14:58:06 +00002213 r->internal = 1;
Igor Sysoevb603dd42009-08-26 16:04:05 +00002214 r->main->count++;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002215
Igor Sysoev79a80482003-05-14 17:13:13 +00002216 ngx_http_handler(r);
Igor Sysoev13933252003-05-29 13:02:09 +00002217
Igor Sysoev9760a132003-10-21 07:47:21 +00002218 return NGX_DONE;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002219}
2220
2221
Igor Sysoev8889b652007-07-29 18:11:39 +00002222ngx_int_t
2223ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
2224{
Igor Sysoev8889b652007-07-29 18:11:39 +00002225 ngx_http_core_srv_conf_t *cscf;
2226 ngx_http_core_loc_conf_t **clcfp;
2227 ngx_http_core_main_conf_t *cmcf;
2228
Igor Sysoevb603dd42009-08-26 16:04:05 +00002229 r->main->count++;
2230
Igor Sysoev8889b652007-07-29 18:11:39 +00002231 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2232
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002233 if (cscf->named_locations) {
Igor Sysoev8889b652007-07-29 18:11:39 +00002234
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002235 for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
Igor Sysoev8889b652007-07-29 18:11:39 +00002236
Igor Sysoev3dde93b2008-12-11 17:32:52 +00002237 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2238 "test location: \"%V\"", &(*clcfp)->name);
2239
2240 if (name->len != (*clcfp)->name.len
2241 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
2242 {
2243 continue;
2244 }
2245
2246 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2247 "using location: %V \"%V?%V\"",
2248 name, &r->uri, &r->args);
2249
2250 r->internal = 1;
2251 r->content_handler = NULL;
2252 r->loc_conf = (*clcfp)->loc_conf;
2253
2254 ngx_http_update_location_config(r);
2255
2256 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2257
2258 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
2259
2260 ngx_http_core_run_phases(r);
2261
2262 return NGX_DONE;
Igor Sysoev8889b652007-07-29 18:11:39 +00002263 }
Igor Sysoev8889b652007-07-29 18:11:39 +00002264 }
2265
2266 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev9e039cf2007-10-22 10:15:48 +00002267 "could not find named location \"%V\"", name);
Igor Sysoev8889b652007-07-29 18:11:39 +00002268
2269 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
Igor Sysoeve55988c2008-05-24 14:14:13 +00002270
Igor Sysoev8889b652007-07-29 18:11:39 +00002271 return NGX_DONE;
2272}
2273
2274
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002275ngx_http_cleanup_t *
2276ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
Igor Sysoev0a280a32003-10-12 16:49:16 +00002277{
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002278 ngx_http_cleanup_t *cln;
Igor Sysoev0a280a32003-10-12 16:49:16 +00002279
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002280 r = r->main;
2281
2282 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
2283 if (cln == NULL) {
2284 return NULL;
Igor Sysoev0a280a32003-10-12 16:49:16 +00002285 }
2286
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002287 if (size) {
2288 cln->data = ngx_palloc(r->pool, size);
2289 if (cln->data == NULL) {
2290 return NULL;
2291 }
Igor Sysoev0a280a32003-10-12 16:49:16 +00002292
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002293 } else {
2294 cln->data = NULL;
2295 }
2296
2297 cln->handler = NULL;
2298 cln->next = r->cleanup;
2299
2300 r->cleanup = cln;
2301
2302 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2303 "http cleanup add: %p", cln);
2304
2305 return cln;
2306}
Igor Sysoev0a280a32003-10-12 16:49:16 +00002307
2308
Igor Sysoevaa828612005-02-09 14:31:07 +00002309static char *
2310ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002311{
Igor Sysoevc9151062007-06-05 06:44:08 +00002312 char *rv;
2313 void *mconf;
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002314 ngx_uint_t i;
Igor Sysoevc9151062007-06-05 06:44:08 +00002315 ngx_conf_t pcf;
2316 ngx_http_module_t *module;
2317 ngx_http_conf_ctx_t *ctx, *http_ctx;
2318 ngx_http_core_srv_conf_t *cscf, **cscfp;
Igor Sysoev8889b652007-07-29 18:11:39 +00002319 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002320
Igor Sysoevc1571722005-03-19 12:38:37 +00002321 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2322 if (ctx == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002323 return NGX_CONF_ERROR;
2324 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002325
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002326 http_ctx = cf->ctx;
2327 ctx->main_conf = http_ctx->main_conf;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002328
Igor Sysoeva9830112003-05-19 16:39:14 +00002329 /* the server{}'s srv_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002330
Igor Sysoevaa828612005-02-09 14:31:07 +00002331 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2332 if (ctx->srv_conf == NULL) {
2333 return NGX_CONF_ERROR;
2334 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002335
Igor Sysoeva9830112003-05-19 16:39:14 +00002336 /* the server{}'s loc_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00002337
Igor Sysoevaa828612005-02-09 14:31:07 +00002338 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2339 if (ctx->loc_conf == NULL) {
2340 return NGX_CONF_ERROR;
2341 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002342
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002343 for (i = 0; ngx_modules[i]; i++) {
2344 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002345 continue;
2346 }
2347
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002348 module = ngx_modules[i]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002349
2350 if (module->create_srv_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002351 mconf = module->create_srv_conf(cf);
2352 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002353 return NGX_CONF_ERROR;
2354 }
2355
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002356 ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002357 }
2358
2359 if (module->create_loc_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002360 mconf = module->create_loc_conf(cf);
2361 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002362 return NGX_CONF_ERROR;
2363 }
2364
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002365 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002366 }
2367 }
2368
Igor Sysoevaa828612005-02-09 14:31:07 +00002369
2370 /* the server configuration context */
Igor Sysoeva9830112003-05-19 16:39:14 +00002371
Igor Sysoev6253ca12003-05-27 12:18:54 +00002372 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00002373 cscf->ctx = ctx;
2374
Igor Sysoevaa828612005-02-09 14:31:07 +00002375
Igor Sysoev6253ca12003-05-27 12:18:54 +00002376 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
Igor Sysoevaa828612005-02-09 14:31:07 +00002377
Igor Sysoevc1571722005-03-19 12:38:37 +00002378 cscfp = ngx_array_push(&cmcf->servers);
2379 if (cscfp == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002380 return NGX_CONF_ERROR;
2381 }
2382
Igor Sysoeva9830112003-05-19 16:39:14 +00002383 *cscfp = cscf;
2384
Igor Sysoevaa828612005-02-09 14:31:07 +00002385
Igor Sysoeva9830112003-05-19 16:39:14 +00002386 /* parse inside server{} */
2387
Igor Sysoev7b190b42005-06-07 15:56:31 +00002388 pcf = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002389 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00002390 cf->cmd_type = NGX_HTTP_SRV_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002391
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002392 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002393
Igor Sysoev7b190b42005-06-07 15:56:31 +00002394 *cf = pcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002395
Igor Sysoeva9830112003-05-19 16:39:14 +00002396 return rv;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002397}
2398
2399
Igor Sysoevaa828612005-02-09 14:31:07 +00002400static char *
2401ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002402{
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002403 char *rv;
Igor Sysoev22f6d862008-12-11 10:21:08 +00002404 u_char *mod;
2405 size_t len;
2406 ngx_str_t *value, *name;
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002407 ngx_uint_t i;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002408 ngx_conf_t save;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002409 ngx_http_module_t *module;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002410 ngx_http_conf_ctx_t *ctx, *pctx;
Igor Sysoeve55988c2008-05-24 14:14:13 +00002411 ngx_http_core_loc_conf_t *clcf, *pclcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002412
Igor Sysoevc1571722005-03-19 12:38:37 +00002413 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2414 if (ctx == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002415 return NGX_CONF_ERROR;
2416 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002417
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002418 pctx = cf->ctx;
2419 ctx->main_conf = pctx->main_conf;
2420 ctx->srv_conf = pctx->srv_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002421
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002422 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2423 if (ctx->loc_conf == NULL) {
2424 return NGX_CONF_ERROR;
2425 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002426
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002427 for (i = 0; ngx_modules[i]; i++) {
2428 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002429 continue;
2430 }
2431
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002432 module = ngx_modules[i]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002433
2434 if (module->create_loc_conf) {
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002435 ctx->loc_conf[ngx_modules[i]->ctx_index] =
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002436 module->create_loc_conf(cf);
Igor Sysoev6d9a6602007-06-08 05:40:59 +00002437 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002438 return NGX_CONF_ERROR;
2439 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002440 }
2441 }
2442
Igor Sysoev6253ca12003-05-27 12:18:54 +00002443 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00002444 clcf->loc_conf = ctx->loc_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002445
Igor Sysoev3b30a902003-12-25 20:26:58 +00002446 value = cf->args->elts;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002447
2448 if (cf->args->nelts == 3) {
Igor Sysoev22f6d862008-12-11 10:21:08 +00002449
2450 len = value[1].len;
2451 mod = value[1].data;
2452 name = &value[2];
2453
2454 if (len == 1 && mod[0] == '=') {
2455
2456 clcf->name = *name;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002457 clcf->exact_match = 1;
2458
Igor Sysoev22f6d862008-12-11 10:21:08 +00002459 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
2460
2461 clcf->name = *name;
Igor Sysoevd43bee82004-11-20 19:52:20 +00002462 clcf->noregex = 1;
2463
Igor Sysoev22f6d862008-12-11 10:21:08 +00002464 } else if (len == 1 && mod[0] == '~') {
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00002465
Igor Sysoev22f6d862008-12-11 10:21:08 +00002466 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002467 return NGX_CONF_ERROR;
2468 }
2469
Igor Sysoev22f6d862008-12-11 10:21:08 +00002470 } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
2471
2472 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2473 return NGX_CONF_ERROR;
2474 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002475
2476 } else {
2477 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002478 "invalid location modifier \"%V\"", &value[1]);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002479 return NGX_CONF_ERROR;
2480 }
2481
2482 } else {
Igor Sysoev8889b652007-07-29 18:11:39 +00002483
Igor Sysoev22f6d862008-12-11 10:21:08 +00002484 name = &value[1];
Igor Sysoev8889b652007-07-29 18:11:39 +00002485
Igor Sysoev22f6d862008-12-11 10:21:08 +00002486 if (name->data[0] == '=') {
2487
2488 clcf->name.len = name->len - 1;
2489 clcf->name.data = name->data + 1;
2490 clcf->exact_match = 1;
2491
2492 } else if (name->data[0] == '^' && name->data[1] == '~') {
2493
2494 clcf->name.len = name->len - 2;
2495 clcf->name.data = name->data + 2;
2496 clcf->noregex = 1;
2497
2498 } else if (name->data[0] == '~') {
2499
2500 name->len--;
2501 name->data++;
2502
2503 if (name->data[0] == '*') {
2504
2505 name->len--;
2506 name->data++;
2507
2508 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2509 return NGX_CONF_ERROR;
2510 }
2511
2512 } else {
2513 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2514 return NGX_CONF_ERROR;
2515 }
2516 }
2517
2518 } else {
2519
2520 clcf->name = *name;
2521
2522 if (name->data[0] == '@') {
2523 clcf->named = 1;
2524 }
Igor Sysoev8889b652007-07-29 18:11:39 +00002525 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002526 }
2527
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002528 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
2529
Igor Sysoeve55988c2008-05-24 14:14:13 +00002530 if (pclcf->name.len) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002531
Igor Sysoeve55988c2008-05-24 14:14:13 +00002532 /* nested location */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002533
Igor Sysoev805d9db2005-02-03 19:33:37 +00002534#if 0
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002535 clcf->prev_location = pclcf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002536#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002537
2538 if (pclcf->exact_match) {
2539 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002540 "location \"%V\" could not be inside "
2541 "the exact location \"%V\"",
2542 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002543 return NGX_CONF_ERROR;
2544 }
2545
Igor Sysoev8889b652007-07-29 18:11:39 +00002546 if (pclcf->named) {
2547 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2548 "location \"%V\" could not be inside "
2549 "the named location \"%V\"",
2550 &clcf->name, &pclcf->name);
2551 return NGX_CONF_ERROR;
2552 }
2553
Igor Sysoeve55988c2008-05-24 14:14:13 +00002554 if (clcf->named) {
2555 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2556 "named location \"%V\" must be "
2557 "on server level only",
2558 &clcf->name);
2559 return NGX_CONF_ERROR;
2560 }
2561
Igor Sysoev22f6d862008-12-11 10:21:08 +00002562 len = pclcf->name.len;
2563
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00002564#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002565 if (clcf->regex == NULL
Igor Sysoev22f6d862008-12-11 10:21:08 +00002566 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00002567#else
Igor Sysoev22f6d862008-12-11 10:21:08 +00002568 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00002569#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002570 {
2571 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002572 "location \"%V\" is outside location \"%V\"",
2573 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002574 return NGX_CONF_ERROR;
2575 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00002576 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00002577
Igor Sysoeve55988c2008-05-24 14:14:13 +00002578 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
2579 return NGX_CONF_ERROR;
2580 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002581
Igor Sysoev805d9db2005-02-03 19:33:37 +00002582 save = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002583 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00002584 cf->cmd_type = NGX_HTTP_LOC_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002585
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002586 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002587
2588 *cf = save;
2589
Igor Sysoev79a80482003-05-14 17:13:13 +00002590 return rv;
2591}
2592
2593
Igor Sysoev22f6d862008-12-11 10:21:08 +00002594static ngx_int_t
2595ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
2596 ngx_str_t *regex, ngx_uint_t caseless)
2597{
2598#if (NGX_PCRE)
2599 ngx_str_t err;
2600 u_char errstr[NGX_MAX_CONF_ERRSTR];
2601
2602 err.len = NGX_MAX_CONF_ERRSTR;
2603 err.data = errstr;
2604
Igor Sysoev2642bf12009-07-14 08:53:37 +00002605#if (NGX_HAVE_CASELESS_FILESYSTEM)
2606 caseless = 1;
2607#endif
2608
Igor Sysoev22f6d862008-12-11 10:21:08 +00002609 clcf->regex = ngx_regex_compile(regex, caseless ? NGX_REGEX_CASELESS: 0,
2610 cf->pool, &err);
2611
2612 if (clcf->regex == NULL) {
2613 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
2614 return NGX_ERROR;
2615 }
2616
2617 clcf->name = *regex;
Igor Sysoev925baa02009-03-06 12:49:22 +00002618 clcf->captures = (ngx_regex_capture_count(clcf->regex) > 0);
Igor Sysoev22f6d862008-12-11 10:21:08 +00002619
2620 return NGX_OK;
2621
2622#else
2623
2624 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2625 "the using of the regex \"%V\" requires PCRE library",
2626 regex);
2627 return NGX_ERROR;
2628
2629#endif
2630}
2631
2632
Igor Sysoevaa828612005-02-09 14:31:07 +00002633static char *
2634ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev79a80482003-05-14 17:13:13 +00002635{
Igor Sysoev30870b42009-11-13 19:59:54 +00002636 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev7bdb7202006-04-19 15:30:56 +00002637
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002638 char *rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002639 ngx_conf_t save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002640
Igor Sysoev30870b42009-11-13 19:59:54 +00002641 if (clcf->types == NULL) {
2642 clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
2643 if (clcf->types == NULL) {
Igor Sysoev7bdb7202006-04-19 15:30:56 +00002644 return NGX_CONF_ERROR;
2645 }
2646 }
2647
Igor Sysoev805d9db2005-02-03 19:33:37 +00002648 save = *cf;
2649 cf->handler = ngx_http_core_type;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002650 cf->handler_conf = conf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002651
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002652 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00002653
2654 *cf = save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002655
2656 return rv;
2657}
2658
2659
Igor Sysoevaa828612005-02-09 14:31:07 +00002660static char *
2661ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002662{
Igor Sysoev30870b42009-11-13 19:59:54 +00002663 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev79a80482003-05-14 17:13:13 +00002664
Igor Sysoeveba03e62007-03-29 10:27:24 +00002665 ngx_str_t *value, *content_type, *old, file;
Igor Sysoev6a078332008-08-04 10:18:36 +00002666 ngx_uint_t i, n, hash;
Igor Sysoev24025022005-12-16 15:07:08 +00002667 ngx_hash_key_t *type;
Igor Sysoev79a80482003-05-14 17:13:13 +00002668
Igor Sysoeveba03e62007-03-29 10:27:24 +00002669 value = cf->args->elts;
2670
2671 if (ngx_strcmp(value[0].data, "include") == 0) {
2672 file = value[1];
2673
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002674 if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
Igor Sysoeveba03e62007-03-29 10:27:24 +00002675 return NGX_CONF_ERROR;
2676 }
2677
2678 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
2679
2680 return ngx_conf_parse(cf, &file);
2681 }
2682
Igor Sysoev24025022005-12-16 15:07:08 +00002683 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
2684 if (content_type == NULL) {
2685 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00002686 }
2687
Igor Sysoev24025022005-12-16 15:07:08 +00002688 *content_type = value[0];
Igor Sysoev79a80482003-05-14 17:13:13 +00002689
2690 for (i = 1; i < cf->args->nelts; i++) {
Igor Sysoev79a80482003-05-14 17:13:13 +00002691
Igor Sysoev6a078332008-08-04 10:18:36 +00002692 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
Igor Sysoev24025022005-12-16 15:07:08 +00002693
Igor Sysoev30870b42009-11-13 19:59:54 +00002694 type = clcf->types->elts;
2695 for (n = 0; n < clcf->types->nelts; n++) {
Igor Sysoev24025022005-12-16 15:07:08 +00002696 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
2697 old = type[n].value;
2698 type[n].value = content_type;
2699
2700 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2701 "duplicate extention \"%V\", "
2702 "content type: \"%V\", "
2703 "old content type: \"%V\"",
2704 &value[i], content_type, old);
2705 continue;
2706 }
2707 }
2708
2709
Igor Sysoev30870b42009-11-13 19:59:54 +00002710 type = ngx_array_push(clcf->types);
Igor Sysoevc1571722005-03-19 12:38:37 +00002711 if (type == NULL) {
Igor Sysoevdc3b2a72004-09-14 19:39:54 +00002712 return NGX_CONF_ERROR;
2713 }
2714
Igor Sysoev24025022005-12-16 15:07:08 +00002715 type->key = value[i];
Igor Sysoev6a078332008-08-04 10:18:36 +00002716 type->key_hash = hash;
Igor Sysoev24025022005-12-16 15:07:08 +00002717 type->value = content_type;
Igor Sysoev79a80482003-05-14 17:13:13 +00002718 }
2719
2720 return NGX_CONF_OK;
2721}
2722
2723
Igor Sysoev899b44e2005-05-12 14:58:06 +00002724static ngx_int_t
2725ngx_http_core_preconfiguration(ngx_conf_t *cf)
2726{
2727 return ngx_http_variables_add_core_vars(cf);
2728}
2729
2730
Igor Sysoevaa828612005-02-09 14:31:07 +00002731static void *
2732ngx_http_core_create_main_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002733{
Igor Sysoev805d9db2005-02-03 19:33:37 +00002734 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002735
Igor Sysoevc1571722005-03-19 12:38:37 +00002736 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
2737 if (cmcf == NULL) {
Igor Sysoev260c4322009-06-02 16:09:44 +00002738 return NULL;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002739 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002740
Igor Sysoev8184d1b2005-03-04 14:06:57 +00002741 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002742 sizeof(ngx_http_core_srv_conf_t *))
Igor Sysoev6f134cc2006-05-23 14:54:58 +00002743 != NGX_OK)
Igor Sysoev805d9db2005-02-03 19:33:37 +00002744 {
Igor Sysoev260c4322009-06-02 16:09:44 +00002745 return NULL;
Igor Sysoev805d9db2005-02-03 19:33:37 +00002746 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002747
Igor Sysoev305a9d82005-12-26 17:07:48 +00002748 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
2749 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002750
Igor Sysoevffe71442006-02-08 15:33:12 +00002751 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
2752 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
2753
Igor Sysoeva9830112003-05-19 16:39:14 +00002754 return cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002755}
2756
2757
Igor Sysoevaa828612005-02-09 14:31:07 +00002758static char *
2759ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002760{
Igor Sysoev6253ca12003-05-27 12:18:54 +00002761 ngx_http_core_main_conf_t *cmcf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00002762
Igor Sysoev305a9d82005-12-26 17:07:48 +00002763 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
2764 cmcf->server_names_hash_max_size = 512;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002765 }
2766
Igor Sysoev305a9d82005-12-26 17:07:48 +00002767 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2768 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00002769 }
Igor Sysoeva9830112003-05-19 16:39:14 +00002770
Igor Sysoev305a9d82005-12-26 17:07:48 +00002771 cmcf->server_names_hash_bucket_size =
2772 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
2773
Igor Sysoevffe71442006-02-08 15:33:12 +00002774
2775 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
2776 cmcf->variables_hash_max_size = 512;
2777 }
2778
2779 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2780 cmcf->variables_hash_bucket_size = 64;
2781 }
2782
2783 cmcf->variables_hash_bucket_size =
2784 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
2785
Igor Sysoeva9830112003-05-19 16:39:14 +00002786 return NGX_CONF_OK;
2787}
2788
2789
Igor Sysoevaa828612005-02-09 14:31:07 +00002790static void *
2791ngx_http_core_create_srv_conf(ngx_conf_t *cf)
Igor Sysoeva9830112003-05-19 16:39:14 +00002792{
2793 ngx_http_core_srv_conf_t *cscf;
2794
Igor Sysoevc1571722005-03-19 12:38:37 +00002795 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
2796 if (cscf == NULL) {
Igor Sysoev260c4322009-06-02 16:09:44 +00002797 return NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002798 }
2799
Igor Sysoev85080d02004-09-22 16:18:21 +00002800 /*
Igor Sysoev02025fd2005-01-18 13:03:58 +00002801 * set by ngx_pcalloc():
Igor Sysoevaa828612005-02-09 14:31:07 +00002802 *
Igor Sysoev02025fd2005-01-18 13:03:58 +00002803 * conf->client_large_buffers.num = 0;
2804 */
Igor Sysoev85080d02004-09-22 16:18:21 +00002805
Igor Sysoevda173ab2006-08-30 10:39:17 +00002806 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
Igor Sysoev305a9d82005-12-26 17:07:48 +00002807 sizeof(ngx_http_server_name_t))
Igor Sysoev1f4220e2009-02-24 10:42:23 +00002808 != NGX_OK)
Igor Sysoevaa828612005-02-09 14:31:07 +00002809 {
Igor Sysoev260c4322009-06-02 16:09:44 +00002810 return NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002811 }
Igor Sysoeva9830112003-05-19 16:39:14 +00002812
Igor Sysoev10a543a2004-03-16 07:10:12 +00002813 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002814 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
2815 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
2816 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev3362b8d2005-05-14 18:42:03 +00002817 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
Igor Sysoev8decab32007-10-18 11:36:58 +00002818 cscf->merge_slashes = NGX_CONF_UNSET;
Igor Sysoev753792e2008-09-24 14:02:50 +00002819 cscf->underscores_in_headers = NGX_CONF_UNSET;
Igor Sysoev187fcd82003-05-23 11:53:01 +00002820
Igor Sysoeva9830112003-05-19 16:39:14 +00002821 return cscf;
2822}
2823
2824
Igor Sysoevaa828612005-02-09 14:31:07 +00002825static char *
2826ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeva9830112003-05-19 16:39:14 +00002827{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002828 ngx_http_core_srv_conf_t *prev = parent;
2829 ngx_http_core_srv_conf_t *conf = child;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002830
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002831 struct sockaddr_in *sin;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002832 ngx_http_listen_opt_t lsopt;
Igor Sysoev305a9d82005-12-26 17:07:48 +00002833 ngx_http_server_name_t *sn;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002834
Igor Sysoev7578ec92003-06-02 15:24:30 +00002835 /* TODO: it does not merge, it inits only */
Igor Sysoeva9830112003-05-19 16:39:14 +00002836
Igor Sysoev44fa8872009-10-29 15:53:50 +00002837 ngx_conf_merge_size_value(conf->connection_pool_size,
2838 prev->connection_pool_size, 256);
2839 ngx_conf_merge_size_value(conf->request_pool_size,
2840 prev->request_pool_size, 4096);
2841 ngx_conf_merge_msec_value(conf->client_header_timeout,
2842 prev->client_header_timeout, 60000);
2843 ngx_conf_merge_size_value(conf->client_header_buffer_size,
2844 prev->client_header_buffer_size, 1024);
2845 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
2846 prev->large_client_header_buffers,
2847 4, ngx_pagesize);
2848
2849 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
2850 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2851 "the \"large_client_header_buffers\" size must be "
2852 "equal to or bigger than \"connection_pool_size\"");
2853 return NGX_CONF_ERROR;
2854 }
2855
2856 ngx_conf_merge_value(conf->ignore_invalid_headers,
2857 prev->ignore_invalid_headers, 1);
2858
2859 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
2860
2861 ngx_conf_merge_value(conf->underscores_in_headers,
2862 prev->underscores_in_headers, 0);
2863
Igor Sysoev79d630a2009-10-21 08:19:46 +00002864 if (!conf->listen) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002865 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
Igor Sysoevaa828612005-02-09 14:31:07 +00002866
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002867 sin = (struct sockaddr_in *) &lsopt.sockaddr;
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002868
2869 sin->sin_family = AF_INET;
Igor Sysoev1b735832004-11-11 14:07:14 +00002870#if (NGX_WIN32)
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002871 sin->sin_port = htons(80);
Igor Sysoev1c104622003-06-03 15:42:58 +00002872#else
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002873 sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
Igor Sysoev1c104622003-06-03 15:42:58 +00002874#endif
Igor Sysoeva35eacc2009-02-21 07:02:02 +00002875 sin->sin_addr.s_addr = INADDR_ANY;
Igor Sysoev9ac946b2005-10-24 15:09:41 +00002876
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002877 lsopt.socklen = sizeof(struct sockaddr_in);
Igor Sysoeve10385e2009-02-21 10:23:30 +00002878
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002879 lsopt.backlog = NGX_LISTEN_BACKLOG;
2880 lsopt.rcvbuf = -1;
2881 lsopt.sndbuf = -1;
2882 lsopt.wildcard = 1;
Igor Sysoeve10385e2009-02-21 10:23:30 +00002883
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002884 (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
Igor Sysoeve10385e2009-02-21 10:23:30 +00002885 NGX_SOCKADDR_STRLEN, 1);
Igor Sysoev79d630a2009-10-21 08:19:46 +00002886
Igor Sysoevf2694cb2009-10-21 16:47:44 +00002887 if (ngx_http_add_listen(cf, conf, &lsopt) == NGX_OK) {
Igor Sysoev79d630a2009-10-21 08:19:46 +00002888 return NGX_CONF_OK;
2889 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002890 }
2891
Igor Sysoev9e580192006-02-01 18:22:15 +00002892 if (conf->server_name.data == NULL) {
Igor Sysoev3be52572008-05-16 14:39:06 +00002893 conf->server_name = cf->cycle->hostname;
Igor Sysoev9e580192006-02-01 18:22:15 +00002894
2895 sn = ngx_array_push(&conf->server_names);
2896 if (sn == NULL) {
2897 return NGX_CONF_ERROR;
2898 }
2899
Igor Sysoev12446d82007-10-17 13:22:26 +00002900#if (NGX_PCRE)
2901 sn->regex = NULL;
2902#endif
Igor Sysoevcd8b43c2009-10-21 16:52:10 +00002903 sn->server = conf;
Igor Sysoev9e580192006-02-01 18:22:15 +00002904 sn->name.len = conf->server_name.len;
2905 sn->name.data = conf->server_name.data;
Igor Sysoevad22e012003-01-15 07:02:27 +00002906 }
2907
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002908 return NGX_CONF_OK;
2909}
2910
2911
Igor Sysoevaa828612005-02-09 14:31:07 +00002912static void *
2913ngx_http_core_create_loc_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002914{
Igor Sysoev30870b42009-11-13 19:59:54 +00002915 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002916
Igor Sysoev30870b42009-11-13 19:59:54 +00002917 clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
2918 if (clcf == NULL) {
Igor Sysoev260c4322009-06-02 16:09:44 +00002919 return NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002920 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002921
Igor Sysoev02025fd2005-01-18 13:03:58 +00002922 /*
2923 * set by ngx_pcalloc():
2924 *
Igor Sysoev30870b42009-11-13 19:59:54 +00002925 * clcf->root = { 0, NULL };
2926 * clcf->limit_except = 0;
2927 * clcf->post_action = { 0, NULL };
2928 * clcf->types = NULL;
2929 * clcf->default_type = { 0, NULL };
2930 * clcf->error_log = NULL;
2931 * clcf->error_pages = NULL;
2932 * clcf->try_files = NULL;
2933 * clcf->client_body_path = NULL;
2934 * clcf->regex = NULL;
2935 * clcf->exact_match = 0;
2936 * clcf->auto_redirect = 0;
2937 * clcf->alias = 0;
2938 * clcf->gzip_proxied = 0;
Igor Sysoev02025fd2005-01-18 13:03:58 +00002939 */
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002940
Igor Sysoev30870b42009-11-13 19:59:54 +00002941 clcf->client_max_body_size = NGX_CONF_UNSET;
2942 clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
2943 clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
2944 clcf->satisfy = NGX_CONF_UNSET_UINT;
2945 clcf->if_modified_since = NGX_CONF_UNSET_UINT;
2946 clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
2947 clcf->client_body_in_single_buffer = NGX_CONF_UNSET;
2948 clcf->internal = NGX_CONF_UNSET;
2949 clcf->sendfile = NGX_CONF_UNSET;
2950 clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
Igor Sysoeva9625062009-08-28 08:12:35 +00002951#if (NGX_HAVE_FILE_AIO)
Igor Sysoev30870b42009-11-13 19:59:54 +00002952 clcf->aio = NGX_CONF_UNSET;
Igor Sysoeva9625062009-08-28 08:12:35 +00002953#endif
Igor Sysoev30870b42009-11-13 19:59:54 +00002954 clcf->read_ahead = NGX_CONF_UNSET_SIZE;
2955 clcf->directio = NGX_CONF_UNSET;
2956 clcf->directio_alignment = NGX_CONF_UNSET;
2957 clcf->tcp_nopush = NGX_CONF_UNSET;
2958 clcf->tcp_nodelay = NGX_CONF_UNSET;
2959 clcf->send_timeout = NGX_CONF_UNSET_MSEC;
2960 clcf->send_lowat = NGX_CONF_UNSET_SIZE;
2961 clcf->postpone_output = NGX_CONF_UNSET_SIZE;
2962 clcf->limit_rate = NGX_CONF_UNSET_SIZE;
2963 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
2964 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
2965 clcf->keepalive_header = NGX_CONF_UNSET;
2966 clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
2967 clcf->lingering_time = NGX_CONF_UNSET_MSEC;
2968 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
2969 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
2970 clcf->reset_timedout_connection = NGX_CONF_UNSET;
2971 clcf->server_name_in_redirect = NGX_CONF_UNSET;
2972 clcf->port_in_redirect = NGX_CONF_UNSET;
2973 clcf->msie_padding = NGX_CONF_UNSET;
2974 clcf->msie_refresh = NGX_CONF_UNSET;
2975 clcf->log_not_found = NGX_CONF_UNSET;
2976 clcf->log_subrequest = NGX_CONF_UNSET;
2977 clcf->recursive_error_pages = NGX_CONF_UNSET;
2978 clcf->server_tokens = NGX_CONF_UNSET;
2979 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
2980 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002981
Igor Sysoev30870b42009-11-13 19:59:54 +00002982 clcf->open_file_cache = NGX_CONF_UNSET_PTR;
2983 clcf->open_file_cache_valid = NGX_CONF_UNSET;
2984 clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
2985 clcf->open_file_cache_errors = NGX_CONF_UNSET;
2986 clcf->open_file_cache_events = NGX_CONF_UNSET;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002987
Igor Sysoevc16b0052007-12-27 14:21:59 +00002988#if (NGX_HTTP_GZIP)
Igor Sysoev30870b42009-11-13 19:59:54 +00002989 clcf->gzip_vary = NGX_CONF_UNSET;
2990 clcf->gzip_http_version = NGX_CONF_UNSET_UINT;
Igor Sysoev8eac7262007-12-28 13:15:11 +00002991#if (NGX_PCRE)
Igor Sysoev30870b42009-11-13 19:59:54 +00002992 clcf->gzip_disable = NGX_CONF_UNSET_PTR;
2993 clcf->gzip_disable_msie6 = 3;
Igor Sysoevc16b0052007-12-27 14:21:59 +00002994#endif
Igor Sysoev8eac7262007-12-28 13:15:11 +00002995#endif
Igor Sysoevc16b0052007-12-27 14:21:59 +00002996
Igor Sysoev30870b42009-11-13 19:59:54 +00002997 return clcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002998}
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002999
Igor Sysoev79a80482003-05-14 17:13:13 +00003000
Igor Sysoev24025022005-12-16 15:07:08 +00003001static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
3002static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
3003static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
3004
3005static ngx_hash_key_t ngx_http_core_default_types[] = {
3006 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
3007 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
3008 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
3009 { ngx_null_string, 0, NULL }
Igor Sysoev79a80482003-05-14 17:13:13 +00003010};
3011
3012
Igor Sysoevaa828612005-02-09 14:31:07 +00003013static char *
Igor Sysoev24025022005-12-16 15:07:08 +00003014ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeve2a31542003-04-08 15:40:10 +00003015{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003016 ngx_http_core_loc_conf_t *prev = parent;
3017 ngx_http_core_loc_conf_t *conf = child;
Igor Sysoev79a80482003-05-14 17:13:13 +00003018
Igor Sysoevaa828612005-02-09 14:31:07 +00003019 ngx_uint_t i;
Igor Sysoev24025022005-12-16 15:07:08 +00003020 ngx_hash_key_t *type;
3021 ngx_hash_init_t types_hash;
Igor Sysoev79a80482003-05-14 17:13:13 +00003022
Igor Sysoev34303462006-01-24 16:08:27 +00003023 if (conf->root.data == NULL) {
Igor Sysoev79a80482003-05-14 17:13:13 +00003024
Igor Sysoev455a7fc2006-03-21 08:20:41 +00003025 conf->alias = prev->alias;
Igor Sysoev34303462006-01-24 16:08:27 +00003026 conf->root = prev->root;
3027 conf->root_lengths = prev->root_lengths;
3028 conf->root_values = prev->root_values;
3029
3030 if (prev->root.data == NULL) {
3031 conf->root.len = sizeof("html") - 1;
3032 conf->root.data = (u_char *) "html";
3033
Igor Sysoev1f4220e2009-02-24 10:42:23 +00003034 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
Igor Sysoev34303462006-01-24 16:08:27 +00003035 return NGX_CONF_ERROR;
3036 }
3037 }
Igor Sysoev6d2a14a2004-09-27 16:03:21 +00003038 }
3039
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003040 if (conf->post_action.data == NULL) {
3041 conf->post_action = prev->post_action;
3042 }
3043
Igor Sysoev1765f472006-07-07 16:33:19 +00003044 ngx_conf_merge_uint_value(conf->types_hash_max_size,
3045 prev->types_hash_max_size, 1024);
Igor Sysoev79a80482003-05-14 17:13:13 +00003046
Igor Sysoev1765f472006-07-07 16:33:19 +00003047 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
3048 prev->types_hash_bucket_size,
3049 ngx_cacheline_size);
Igor Sysoev24025022005-12-16 15:07:08 +00003050
3051 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
3052 ngx_cacheline_size);
3053
3054 /*
3055 * the special handling the "types" directive in the "http" section
3056 * to inherit the http's conf->types_hash to all servers
3057 */
3058
3059 if (prev->types && prev->types_hash.buckets == NULL) {
3060
3061 types_hash.hash = &prev->types_hash;
3062 types_hash.key = ngx_hash_key_lc;
3063 types_hash.max_size = conf->types_hash_max_size;
3064 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003065 types_hash.name = "types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00003066 types_hash.pool = cf->pool;
3067 types_hash.temp_pool = NULL;
3068
3069 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
3070 != NGX_OK)
3071 {
3072 return NGX_CONF_ERROR;
3073 }
3074 }
3075
3076 if (conf->types == NULL) {
3077 conf->types = prev->types;
3078 conf->types_hash = prev->types_hash;
3079 }
3080
3081 if (conf->types == NULL) {
3082 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
3083 if (conf->types == NULL) {
3084 return NGX_CONF_ERROR;
3085 }
3086
3087 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
3088 type = ngx_array_push(conf->types);
3089 if (type == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00003090 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00003091 }
3092
Igor Sysoev24025022005-12-16 15:07:08 +00003093 type->key = ngx_http_core_default_types[i].key;
3094 type->key_hash =
3095 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
3096 ngx_http_core_default_types[i].key.len);
3097 type->value = ngx_http_core_default_types[i].value;
3098 }
3099 }
Igor Sysoev79a80482003-05-14 17:13:13 +00003100
Igor Sysoev24025022005-12-16 15:07:08 +00003101 if (conf->types_hash.buckets == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00003102
Igor Sysoev24025022005-12-16 15:07:08 +00003103 types_hash.hash = &conf->types_hash;
3104 types_hash.key = ngx_hash_key_lc;
3105 types_hash.max_size = conf->types_hash_max_size;
3106 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003107 types_hash.name = "mime_types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00003108 types_hash.pool = cf->pool;
3109 types_hash.temp_pool = NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00003110
Igor Sysoev24025022005-12-16 15:07:08 +00003111 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
3112 != NGX_OK)
3113 {
3114 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00003115 }
3116 }
3117
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00003118 if (conf->error_log == NULL) {
3119 if (prev->error_log) {
3120 conf->error_log = prev->error_log;
Igor Sysoev890fc962003-07-20 21:15:59 +00003121 } else {
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00003122 conf->error_log = &cf->cycle->new_log;
Igor Sysoev890fc962003-07-20 21:15:59 +00003123 }
3124 }
3125
Igor Sysoev74e95c22003-11-09 20:03:38 +00003126 if (conf->error_pages == NULL && prev->error_pages) {
3127 conf->error_pages = prev->error_pages;
3128 }
3129
Igor Sysoev6253ca12003-05-27 12:18:54 +00003130 ngx_conf_merge_str_value(conf->default_type,
Igor Sysoevaa828612005-02-09 14:31:07 +00003131 prev->default_type, "text/plain");
Igor Sysoev6253ca12003-05-27 12:18:54 +00003132
Igor Sysoev1765f472006-07-07 16:33:19 +00003133 ngx_conf_merge_off_value(conf->client_max_body_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00003134 prev->client_max_body_size, 1 * 1024 * 1024);
Igor Sysoevdbb27762004-04-01 16:20:53 +00003135 ngx_conf_merge_size_value(conf->client_body_buffer_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00003136 prev->client_body_buffer_size,
3137 (size_t) 2 * ngx_pagesize);
Igor Sysoev2b0c76c2003-10-27 21:01:00 +00003138 ngx_conf_merge_msec_value(conf->client_body_timeout,
Igor Sysoev7af6b162004-02-09 07:46:43 +00003139 prev->client_body_timeout, 60000);
Igor Sysoev899b44e2005-05-12 14:58:06 +00003140
Igor Sysoev2d028f82007-12-29 16:38:23 +00003141 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
3142 NGX_HTTP_SATISFY_ALL);
Igor Sysoev863325f2008-12-01 14:22:51 +00003143 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
Igor Sysoev2c336482009-02-10 15:05:05 +00003144 NGX_HTTP_IMS_EXACT);
Igor Sysoev7d9e3342009-05-14 11:31:50 +00003145 ngx_conf_merge_uint_value(conf->client_body_in_file_only,
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00003146 prev->client_body_in_file_only, 0);
Igor Sysoevbfbded72009-05-14 11:41:33 +00003147 ngx_conf_merge_value(conf->client_body_in_single_buffer,
3148 prev->client_body_in_single_buffer, 0);
Igor Sysoev7d9e3342009-05-14 11:31:50 +00003149 ngx_conf_merge_value(conf->internal, prev->internal, 0);
Igor Sysoev5bf3d252003-10-22 07:05:29 +00003150 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
Igor Sysoevc9b57dc2007-05-07 06:33:39 +00003151 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
3152 prev->sendfile_max_chunk, 0);
Igor Sysoeva9625062009-08-28 08:12:35 +00003153#if (NGX_HAVE_FILE_AIO)
3154 ngx_conf_merge_value(conf->aio, prev->aio, 0);
3155#endif
Igor Sysoev32661712009-09-30 13:21:52 +00003156 ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0);
Igor Sysoev385af282008-07-30 12:34:04 +00003157 ngx_conf_merge_off_value(conf->directio, prev->directio,
3158 NGX_MAX_OFF_T_VALUE);
Igor Sysoev6fb506a2009-08-28 08:15:55 +00003159 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
3160 512);
Igor Sysoev3c3ca172004-01-05 20:55:48 +00003161 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003162 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
Igor Sysoev899b44e2005-05-12 14:58:06 +00003163
Igor Sysoev7af6b162004-02-09 07:46:43 +00003164 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
Igor Sysoevb5faed22003-10-29 08:30:44 +00003165 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
Igor Sysoev7823cc32004-07-14 16:01:42 +00003166 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
3167 1460);
3168 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
Igor Sysoev80027fc2009-06-02 14:01:50 +00003169 ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after,
3170 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00003171 ngx_conf_merge_msec_value(conf->keepalive_timeout,
Igor Sysoev307c3ad2004-09-17 16:07:35 +00003172 prev->keepalive_timeout, 75000);
3173 ngx_conf_merge_sec_value(conf->keepalive_header,
3174 prev->keepalive_header, 0);
Igor Sysoeve9591282009-05-25 15:38:36 +00003175 ngx_conf_merge_uint_value(conf->keepalive_requests,
3176 prev->keepalive_requests, 100);
Igor Sysoev187fcd82003-05-23 11:53:01 +00003177 ngx_conf_merge_msec_value(conf->lingering_time,
3178 prev->lingering_time, 30000);
3179 ngx_conf_merge_msec_value(conf->lingering_timeout,
3180 prev->lingering_timeout, 5000);
Igor Sysoev13f5ff92007-11-27 11:33:52 +00003181 ngx_conf_merge_msec_value(conf->resolver_timeout,
3182 prev->resolver_timeout, 30000);
3183
3184 if (conf->resolver == NULL) {
Igor Sysoev6b2fce42007-12-03 10:05:19 +00003185
Igor Sysoevf39876c2008-03-06 08:48:55 +00003186 if (prev->resolver == NULL) {
3187
3188 /*
3189 * create dummy resolver in http {} context
3190 * to inherit it in all servers
3191 */
3192
3193 prev->resolver = ngx_resolver_create(cf, NULL);
3194 if (prev->resolver == NULL) {
Igor Sysoevd2d673a2008-02-07 08:57:07 +00003195 return NGX_CONF_ERROR;
Igor Sysoev6b2fce42007-12-03 10:05:19 +00003196 }
3197 }
Igor Sysoev433608c2008-05-14 07:54:52 +00003198
Igor Sysoevf39876c2008-03-06 08:48:55 +00003199 conf->resolver = prev->resolver;
Igor Sysoev13f5ff92007-11-27 11:33:52 +00003200 }
Igor Sysoev79a80482003-05-14 17:13:13 +00003201
Igor Sysoev52859f22009-03-23 13:14:51 +00003202 if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path,
Igor Sysoev02025fd2005-01-18 13:03:58 +00003203 prev->client_body_temp_path,
Igor Sysoev52859f22009-03-23 13:14:51 +00003204 &ngx_http_client_temp_path)
3205 != NGX_OK)
3206 {
3207 return NGX_CONF_ERROR;
3208 }
Igor Sysoev02025fd2005-01-18 13:03:58 +00003209
Igor Sysoev0ab91b92004-06-06 19:49:18 +00003210 ngx_conf_merge_value(conf->reset_timedout_connection,
Igor Sysoevaa828612005-02-09 14:31:07 +00003211 prev->reset_timedout_connection, 0);
Igor Sysoev3f24ae22007-12-29 15:30:39 +00003212 ngx_conf_merge_value(conf->server_name_in_redirect,
3213 prev->server_name_in_redirect, 1);
Igor Sysoev7b190b42005-06-07 15:56:31 +00003214 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00003215 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003216 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
Igor Sysoev5192b362005-07-08 14:34:20 +00003217 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
Igor Sysoev2eec1e12008-09-27 15:08:02 +00003218 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
Igor Sysoev3f8dc592006-08-28 16:57:48 +00003219 ngx_conf_merge_value(conf->recursive_error_pages,
3220 prev->recursive_error_pages, 0);
Igor Sysoev070cf222007-10-22 10:17:34 +00003221 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00003222
Igor Sysoev140c7552007-09-01 12:12:48 +00003223 ngx_conf_merge_ptr_value(conf->open_file_cache,
Igor Sysoev513fec72007-12-27 08:40:14 +00003224 prev->open_file_cache, NULL);
Igor Sysoev140c7552007-09-01 12:12:48 +00003225
Igor Sysoev9b9616e2007-12-21 16:19:48 +00003226 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
Igor Sysoev513fec72007-12-27 08:40:14 +00003227 prev->open_file_cache_valid, 60);
Igor Sysoev140c7552007-09-01 12:12:48 +00003228
Igor Sysoevf3b0e492007-12-22 13:19:39 +00003229 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
Igor Sysoev513fec72007-12-27 08:40:14 +00003230 prev->open_file_cache_min_uses, 1);
Igor Sysoevf3b0e492007-12-22 13:19:39 +00003231
Igor Sysoev140c7552007-09-01 12:12:48 +00003232 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
Igor Sysoev513fec72007-12-27 08:40:14 +00003233 prev->open_file_cache_errors, 0);
Igor Sysoev865c1502003-11-30 20:03:18 +00003234
Igor Sysoev9afd58f2007-09-03 08:41:42 +00003235 ngx_conf_merge_sec_value(conf->open_file_cache_events,
Igor Sysoev513fec72007-12-27 08:40:14 +00003236 prev->open_file_cache_events, 0);
Igor Sysoevc16b0052007-12-27 14:21:59 +00003237#if (NGX_HTTP_GZIP)
3238
3239 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
3240 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
3241 NGX_HTTP_VERSION_11);
3242 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
3243 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
3244
Igor Sysoev8eac7262007-12-28 13:15:11 +00003245#if (NGX_PCRE)
Igor Sysoevc16b0052007-12-27 14:21:59 +00003246 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
Igor Sysoev8eac7262007-12-28 13:15:11 +00003247#endif
Igor Sysoevc16b0052007-12-27 14:21:59 +00003248
Igor Sysoev54477e42008-08-26 15:09:28 +00003249 if (conf->gzip_disable_msie6 == 3) {
3250 conf->gzip_disable_msie6 =
3251 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
3252 }
3253
Igor Sysoevc16b0052007-12-27 14:21:59 +00003254#endif
Igor Sysoev9afd58f2007-09-03 08:41:42 +00003255
Igor Sysoeve2a31542003-04-08 15:40:10 +00003256 return NGX_CONF_OK;
3257}
3258
Igor Sysoev79a80482003-05-14 17:13:13 +00003259
Igor Sysoevaa828612005-02-09 14:31:07 +00003260static char *
3261ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003262{
Igor Sysoev79d630a2009-10-21 08:19:46 +00003263 ngx_http_core_srv_conf_t *cscf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00003264
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003265 ngx_str_t *value, size;
3266 ngx_url_t u;
3267 ngx_uint_t n;
3268 ngx_http_listen_opt_t lsopt;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003269
Igor Sysoev79d630a2009-10-21 08:19:46 +00003270 cscf->listen = 1;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +00003271
Igor Sysoevb145b062005-06-15 18:33:41 +00003272 value = cf->args->elts;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003273
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003274 ngx_memzero(&u, sizeof(ngx_url_t));
Igor Sysoevb145b062005-06-15 18:33:41 +00003275
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003276 u.url = value[1];
3277 u.listen = 1;
Igor Sysoevbf3aaac2006-12-12 16:46:16 +00003278 u.default_port = 80;
Igor Sysoevb145b062005-06-15 18:33:41 +00003279
Igor Sysoev7ed63ee2007-10-08 08:55:12 +00003280 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
Igor Sysoev20bf47b2006-10-24 13:06:55 +00003281 if (u.err) {
3282 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3283 "%s in \"%V\" of the \"listen\" directive",
3284 u.err, &u.url);
3285 }
Igor Sysoevb145b062005-06-15 18:33:41 +00003286
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00003287 return NGX_CONF_ERROR;
Igor Sysoevb145b062005-06-15 18:33:41 +00003288 }
3289
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003290 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003291
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003292 ngx_memcpy(lsopt.sockaddr, u.sockaddr, u.socklen);
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003293
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003294 lsopt.socklen = u.socklen;
3295 lsopt.backlog = NGX_LISTEN_BACKLOG;
3296 lsopt.rcvbuf = -1;
3297 lsopt.sndbuf = -1;
3298 lsopt.wildcard = u.wildcard;
Igor Sysoeva35eacc2009-02-21 07:02:02 +00003299
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003300 (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
Igor Sysoeva35eacc2009-02-21 07:02:02 +00003301 NGX_SOCKADDR_STRLEN, 1);
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003302
Igor Sysoev5a950802009-10-21 19:16:38 +00003303 for (n = 2; n < cf->args->nelts; n++) {
Igor Sysoev24025022005-12-16 15:07:08 +00003304
Igor Sysoev98269612009-10-21 19:18:50 +00003305 if (ngx_strcmp(value[n].data, "default_server") == 0
3306 || ngx_strcmp(value[n].data, "default") == 0)
3307 {
Igor Sysoev5a950802009-10-21 19:16:38 +00003308 lsopt.default_server = 1;
3309 continue;
Igor Sysoev13933252003-05-29 13:02:09 +00003310 }
3311
Igor Sysoevb145b062005-06-15 18:33:41 +00003312 if (ngx_strcmp(value[n].data, "bind") == 0) {
Igor Sysoev5a950802009-10-21 19:16:38 +00003313 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003314 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003315 continue;
3316 }
3317
Igor Sysoevc2068d02005-10-19 12:33:58 +00003318 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003319 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
Igor Sysoev5a950802009-10-21 19:16:38 +00003320 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003321 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003322
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003323 if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
Igor Sysoevb145b062005-06-15 18:33:41 +00003324 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3325 "invalid backlog \"%V\"", &value[n]);
3326 return NGX_CONF_ERROR;
3327 }
3328
3329 continue;
3330 }
3331
Igor Sysoevc2068d02005-10-19 12:33:58 +00003332 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
3333 size.len = value[n].len - 7;
3334 size.data = value[n].data + 7;
3335
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003336 lsopt.rcvbuf = ngx_parse_size(&size);
Igor Sysoev5a950802009-10-21 19:16:38 +00003337 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003338 lsopt.bind = 1;
Igor Sysoevc2068d02005-10-19 12:33:58 +00003339
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003340 if (lsopt.rcvbuf == NGX_ERROR) {
Igor Sysoevc2068d02005-10-19 12:33:58 +00003341 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3342 "invalid rcvbuf \"%V\"", &value[n]);
3343 return NGX_CONF_ERROR;
3344 }
3345
3346 continue;
3347 }
3348
3349 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
3350 size.len = value[n].len - 7;
3351 size.data = value[n].data + 7;
3352
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003353 lsopt.sndbuf = ngx_parse_size(&size);
Igor Sysoev5a950802009-10-21 19:16:38 +00003354 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003355 lsopt.bind = 1;
Igor Sysoevc2068d02005-10-19 12:33:58 +00003356
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003357 if (lsopt.sndbuf == NGX_ERROR) {
Igor Sysoevc2068d02005-10-19 12:33:58 +00003358 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3359 "invalid sndbuf \"%V\"", &value[n]);
3360 return NGX_CONF_ERROR;
3361 }
3362
3363 continue;
3364 }
3365
3366 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
Igor Sysoevb145b062005-06-15 18:33:41 +00003367#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003368 lsopt.accept_filter = (char *) &value[n].data[14];
Igor Sysoev5a950802009-10-21 19:16:38 +00003369 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003370 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003371#else
3372 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3373 "accept filters \"%V\" are not supported "
3374 "on this platform, ignored",
3375 &value[n]);
3376#endif
3377 continue;
3378 }
3379
3380 if (ngx_strcmp(value[n].data, "deferred") == 0) {
3381#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003382 lsopt.deferred_accept = 1;
Igor Sysoev5a950802009-10-21 19:16:38 +00003383 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003384 lsopt.bind = 1;
Igor Sysoevb145b062005-06-15 18:33:41 +00003385#else
3386 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3387 "the deferred accept is not supported "
3388 "on this platform, ignored");
3389#endif
3390 continue;
3391 }
3392
Igor Sysoev6d94b512009-03-13 14:20:34 +00003393 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
3394#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3395 struct sockaddr *sa;
3396
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003397 sa = (struct sockaddr *) lsopt.sockaddr;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003398
3399 if (sa->sa_family == AF_INET6) {
3400
3401 if (ngx_strcmp(&value[n].data[10], "n") == 0) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003402 lsopt.ipv6only = 1;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003403
3404 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003405 lsopt.ipv6only = 2;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003406
3407 } else {
3408 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3409 "invalid ipv6only flags \"%s\"",
3410 &value[n].data[9]);
3411 return NGX_CONF_ERROR;
3412 }
3413
Igor Sysoev5a950802009-10-21 19:16:38 +00003414 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003415 lsopt.bind = 1;
Igor Sysoev6d94b512009-03-13 14:20:34 +00003416
3417 } else {
3418 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3419 "ipv6only is not supported "
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003420 "on addr \"%s\", ignored", lsopt.addr);
Igor Sysoev6d94b512009-03-13 14:20:34 +00003421 }
3422
3423 continue;
3424#else
3425 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3426 "bind ipv6only is not supported "
3427 "on this platform");
3428 return NGX_CONF_ERROR;
3429#endif
3430 }
3431
Igor Sysoevf100c782008-09-01 14:19:01 +00003432 if (ngx_strcmp(value[n].data, "ssl") == 0) {
3433#if (NGX_HTTP_SSL)
Igor Sysoev5a950802009-10-21 19:16:38 +00003434 lsopt.set = 1;
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003435 lsopt.ssl = 1;
Igor Sysoevf100c782008-09-01 14:19:01 +00003436 continue;
3437#else
3438 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3439 "the \"ssl\" parameter requires "
3440 "ngx_http_ssl_module");
3441 return NGX_CONF_ERROR;
3442#endif
3443 }
3444
Igor Sysoevb145b062005-06-15 18:33:41 +00003445 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3446 "the invalid \"%V\" parameter", &value[n]);
3447 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00003448 }
3449
Igor Sysoevf2694cb2009-10-21 16:47:44 +00003450 if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
Igor Sysoev79d630a2009-10-21 08:19:46 +00003451 return NGX_CONF_OK;
3452 }
3453
3454 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00003455}
3456
3457
Igor Sysoevaa828612005-02-09 14:31:07 +00003458static char *
3459ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev13933252003-05-29 13:02:09 +00003460{
Igor Sysoev305a9d82005-12-26 17:07:48 +00003461 ngx_http_core_srv_conf_t *cscf = conf;
Igor Sysoev13933252003-05-29 13:02:09 +00003462
Igor Sysoev305a9d82005-12-26 17:07:48 +00003463 u_char ch;
3464 ngx_str_t *value, name;
3465 ngx_uint_t i;
3466 ngx_http_server_name_t *sn;
Igor Sysoevb1af9bb2004-06-25 14:42:03 +00003467
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003468 value = cf->args->elts;
Igor Sysoev13933252003-05-29 13:02:09 +00003469
Igor Sysoev305a9d82005-12-26 17:07:48 +00003470 ch = value[1].data[0];
3471
Igor Sysoevb29426d2008-08-21 12:56:10 +00003472 if (cscf->server_name.data == NULL) {
3473 if (value[1].len) {
3474 name = value[1];
Igor Sysoev305a9d82005-12-26 17:07:48 +00003475
Igor Sysoevb29426d2008-08-21 12:56:10 +00003476 if (ch == '.') {
3477 name.len--;
3478 name.data++;
3479 }
Igor Sysoev305a9d82005-12-26 17:07:48 +00003480
Igor Sysoevb29426d2008-08-21 12:56:10 +00003481 cscf->server_name.len = name.len;
3482 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
3483 if (cscf->server_name.data == NULL) {
3484 return NGX_CONF_ERROR;
3485 }
3486
3487 } else {
3488 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3489 "the first server name must not be empty");
Igor Sysoev305a9d82005-12-26 17:07:48 +00003490 return NGX_CONF_ERROR;
3491 }
3492 }
3493
3494 for (i = 1; i < cf->args->nelts; i++) {
3495
3496 ch = value[i].data[0];
3497
Igor Sysoevb29426d2008-08-21 12:56:10 +00003498 if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
Igor Sysoev305a9d82005-12-26 17:07:48 +00003499 || (ch == '.' && value[i].len < 2))
3500 {
3501 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3502 "server name \"%V\" is invalid", &value[i]);
3503 return NGX_CONF_ERROR;
3504 }
3505
Igor Sysoev7a588602007-04-02 06:27:30 +00003506 if (ngx_strchr(value[i].data, '/')) {
3507 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
3508 "server name \"%V\" has strange symbols",
3509 &value[i]);
3510 }
3511
Igor Sysoevc24de1e2007-12-29 19:05:21 +00003512 if (value[i].len == 1 && ch == '*') {
3513 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3514 "\"server_name *\" is unsupported, use "
3515 "\"server_name_in_redirect off\" instead");
3516 return NGX_CONF_ERROR;
3517 }
3518
Igor Sysoev305a9d82005-12-26 17:07:48 +00003519 sn = ngx_array_push(&cscf->server_names);
Igor Sysoevc1571722005-03-19 12:38:37 +00003520 if (sn == NULL) {
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00003521 return NGX_CONF_ERROR;
3522 }
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003523
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003524#if (NGX_PCRE)
3525 sn->regex = NULL;
3526#endif
Igor Sysoevcd8b43c2009-10-21 16:52:10 +00003527 sn->server = cscf;
Igor Sysoev99c3ab92007-12-27 09:17:20 +00003528 sn->name = value[i];
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003529
Igor Sysoev2a634f52009-10-21 16:27:48 +00003530 ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
3531
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003532 if (value[i].data[0] != '~') {
3533 continue;
3534 }
3535
3536#if (NGX_PCRE)
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00003537 {
3538 ngx_str_t err;
3539 u_char errstr[NGX_MAX_CONF_ERRSTR];
3540
Igor Sysoevbe9d1652009-09-14 09:48:48 +00003541 if (value[i].len == 1) {
3542 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3543 "empty regex in server name \"%V\"", &value[i]);
3544 return NGX_CONF_ERROR;
3545 }
3546
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003547 err.len = NGX_MAX_CONF_ERRSTR;
3548 err.data = errstr;
3549
3550 value[i].len--;
3551 value[i].data++;
3552
Igor Sysoev5fd09312008-05-15 14:44:47 +00003553 sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err);
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003554
3555 if (sn->regex == NULL) {
3556 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
3557 return NGX_CONF_ERROR;
3558 }
3559
Igor Sysoev99c3ab92007-12-27 09:17:20 +00003560 sn->name = value[i];
Igor Sysoev2a634f52009-10-21 16:27:48 +00003561 cscf->captures = (ngx_regex_capture_count(sn->regex) > 0);
Igor Sysoev86ef6aa2007-12-10 12:09:51 +00003562 }
Igor Sysoev43c3bf42007-08-12 19:48:12 +00003563#else
3564 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3565 "the using of the regex \"%V\" "
3566 "requires PCRE library", &value[i]);
3567
3568 return NGX_CONF_ERROR;
3569#endif
Igor Sysoevaa3436c2003-05-30 14:27:59 +00003570 }
Igor Sysoev13933252003-05-29 13:02:09 +00003571
Igor Sysoeva19a85e2003-01-28 15:56:37 +00003572 return NGX_CONF_OK;
3573}
Igor Sysoev9d639522003-07-07 06:11:50 +00003574
3575
Igor Sysoevaa828612005-02-09 14:31:07 +00003576static char *
3577ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev10a543a2004-03-16 07:10:12 +00003578{
Igor Sysoev30870b42009-11-13 19:59:54 +00003579 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev10a543a2004-03-16 07:10:12 +00003580
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003581 ngx_str_t *value;
3582 ngx_uint_t alias, n;
3583 ngx_http_script_compile_t sc;
Igor Sysoev10a543a2004-03-16 07:10:12 +00003584
3585 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
3586
Igor Sysoev30870b42009-11-13 19:59:54 +00003587 if (clcf->root.data) {
Igor Sysoeva741f8d2004-03-30 20:31:58 +00003588
3589 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
3590
Igor Sysoev30870b42009-11-13 19:59:54 +00003591 if ((ngx_uint_t) clcf->alias == alias) {
Igor Sysoev10a543a2004-03-16 07:10:12 +00003592 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003593 "\"%V\" directive is duplicate",
3594 &cmd->name);
Igor Sysoev10a543a2004-03-16 07:10:12 +00003595 } else {
3596 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003597 "\"%V\" directive is duplicate, "
Igor Sysoev10a543a2004-03-16 07:10:12 +00003598 "\"%s\" directive is specified before",
Igor Sysoev30870b42009-11-13 19:59:54 +00003599 &cmd->name, clcf->alias ? "alias" : "root");
Igor Sysoev10a543a2004-03-16 07:10:12 +00003600 }
3601
3602 return NGX_CONF_ERROR;
3603 }
3604
Igor Sysoev30870b42009-11-13 19:59:54 +00003605 if (clcf->named && alias) {
Igor Sysoev8889b652007-07-29 18:11:39 +00003606 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3607 "the \"alias\" directive may not be used "
3608 "inside named location");
3609
3610 return NGX_CONF_ERROR;
3611 }
3612
Igor Sysoev10a543a2004-03-16 07:10:12 +00003613 value = cf->args->elts;
3614
Igor Sysoev10b98942007-04-02 05:43:21 +00003615 if (ngx_strstr(value[1].data, "$document_root")
3616 || ngx_strstr(value[1].data, "${document_root}"))
Igor Sysoevceab3692007-04-01 09:03:14 +00003617 {
3618 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3619 "the $document_root variable may not be used "
3620 "in the \"%V\" directive",
3621 &cmd->name);
3622
3623 return NGX_CONF_ERROR;
3624 }
3625
Igor Sysoev4ca2acf2008-09-29 04:47:22 +00003626 if (ngx_strstr(value[1].data, "$realpath_root")
3627 || ngx_strstr(value[1].data, "${realpath_root}"))
3628 {
3629 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3630 "the $realpath_root variable may not be used "
3631 "in the \"%V\" directive",
3632 &cmd->name);
3633
3634 return NGX_CONF_ERROR;
3635 }
3636
Igor Sysoev30870b42009-11-13 19:59:54 +00003637 clcf->alias = alias;
3638 clcf->root = value[1];
Igor Sysoev10a543a2004-03-16 07:10:12 +00003639
Igor Sysoev30870b42009-11-13 19:59:54 +00003640 if (!alias && clcf->root.data[clcf->root.len - 1] == '/') {
3641 clcf->root.len--;
Igor Sysoev71057632004-08-30 19:24:51 +00003642 }
3643
Igor Sysoev30870b42009-11-13 19:59:54 +00003644 if (clcf->root.data[0] != '$') {
3645 if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) {
Igor Sysoev8f125582006-07-28 15:16:17 +00003646 return NGX_CONF_ERROR;
3647 }
Igor Sysoev34303462006-01-24 16:08:27 +00003648 }
3649
Igor Sysoev30870b42009-11-13 19:59:54 +00003650 n = ngx_http_script_variables_count(&clcf->root);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003651
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003652 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3653
Igor Sysoev925baa02009-03-06 12:49:22 +00003654 if (n) {
3655 sc.cf = cf;
Igor Sysoev30870b42009-11-13 19:59:54 +00003656 sc.source = &clcf->root;
3657 sc.lengths = &clcf->root_lengths;
3658 sc.values = &clcf->root_values;
Igor Sysoev925baa02009-03-06 12:49:22 +00003659 sc.variables = n;
3660 sc.complete_lengths = 1;
3661 sc.complete_values = 1;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003662
Igor Sysoev925baa02009-03-06 12:49:22 +00003663 if (ngx_http_script_compile(&sc) != NGX_OK) {
3664 return NGX_CONF_ERROR;
3665 }
3666 }
3667
3668#if (NGX_PCRE)
3669
Igor Sysoev30870b42009-11-13 19:59:54 +00003670 if (alias && clcf->regex
3671 && (ngx_regex_capture_count(clcf->regex) <= 0 || sc.ncaptures == 0))
Igor Sysoev925baa02009-03-06 12:49:22 +00003672 {
3673 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3674 "the \"alias\" directive must use captures "
3675 "inside location given by regular expression");
3676
Igor Sysoev3ca233e2005-12-28 14:23:52 +00003677 return NGX_CONF_ERROR;
3678 }
3679
Igor Sysoev925baa02009-03-06 12:49:22 +00003680#endif
3681
Igor Sysoev10a543a2004-03-16 07:10:12 +00003682 return NGX_CONF_OK;
3683}
3684
3685
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003686static ngx_http_method_name_t ngx_methods_names[] = {
Igor Sysoev722231f2007-02-14 18:51:19 +00003687 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
3688 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
3689 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
3690 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
3691 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
3692 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
3693 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
3694 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
3695 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
3696 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
3697 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
3698 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
3699 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003700 { NULL, 0 }
3701};
3702
3703
3704static char *
3705ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3706{
Igor Sysoeve55988c2008-05-24 14:14:13 +00003707 ngx_http_core_loc_conf_t *pclcf = conf;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003708
3709 char *rv;
3710 void *mconf;
3711 ngx_str_t *value;
3712 ngx_uint_t i;
3713 ngx_conf_t save;
3714 ngx_http_module_t *module;
3715 ngx_http_conf_ctx_t *ctx, *pctx;
3716 ngx_http_method_name_t *name;
Igor Sysoeve55988c2008-05-24 14:14:13 +00003717 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003718
Igor Sysoeve55988c2008-05-24 14:14:13 +00003719 if (pclcf->limit_except) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003720 return "duplicate";
3721 }
3722
Igor Sysoeve55988c2008-05-24 14:14:13 +00003723 pclcf->limit_except = 0xffffffff;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003724
3725 value = cf->args->elts;
3726
3727 for (i = 1; i < cf->args->nelts; i++) {
3728 for (name = ngx_methods_names; name->name; name++) {
3729
3730 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
Igor Sysoeve55988c2008-05-24 14:14:13 +00003731 pclcf->limit_except &= name->method;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003732 goto next;
3733 }
3734 }
3735
3736 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3737 "invalid method \"%V\"", &value[i]);
3738 return NGX_CONF_ERROR;
3739
3740 next:
3741 continue;
3742 }
3743
Igor Sysoeve55988c2008-05-24 14:14:13 +00003744 if (!(pclcf->limit_except & NGX_HTTP_GET)) {
3745 pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003746 }
3747
3748 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
3749 if (ctx == NULL) {
3750 return NGX_CONF_ERROR;
3751 }
3752
3753 pctx = cf->ctx;
3754 ctx->main_conf = pctx->main_conf;
3755 ctx->srv_conf = pctx->srv_conf;
3756
3757 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
3758 if (ctx->loc_conf == NULL) {
3759 return NGX_CONF_ERROR;
3760 }
3761
3762 for (i = 0; ngx_modules[i]; i++) {
3763 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
3764 continue;
3765 }
3766
3767 module = ngx_modules[i]->ctx;
3768
3769 if (module->create_loc_conf) {
3770
3771 mconf = module->create_loc_conf(cf);
3772 if (mconf == NULL) {
3773 return NGX_CONF_ERROR;
3774 }
3775
3776 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
3777 }
3778 }
3779
3780
Igor Sysoeve55988c2008-05-24 14:14:13 +00003781 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
3782 pclcf->limit_except_loc_conf = ctx->loc_conf;
3783 clcf->loc_conf = ctx->loc_conf;
3784 clcf->name = pclcf->name;
3785 clcf->noname = 1;
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003786
Igor Sysoeve55988c2008-05-24 14:14:13 +00003787 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003788 return NGX_CONF_ERROR;
3789 }
3790
Igor Sysoev94e32ce2006-04-07 14:08:04 +00003791 save = *cf;
3792 cf->ctx = ctx;
3793 cf->cmd_type = NGX_HTTP_LMT_CONF;
3794
3795 rv = ngx_conf_parse(cf, NULL);
3796
3797 *cf = save;
3798
3799 return rv;
3800}
3801
3802
Igor Sysoevaa828612005-02-09 14:31:07 +00003803static char *
Igor Sysoev385af282008-07-30 12:34:04 +00003804ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3805{
3806 ngx_http_core_loc_conf_t *clcf = conf;
3807
3808 ngx_str_t *value;
3809
3810 if (clcf->directio != NGX_CONF_UNSET) {
3811 return "is duplicate";
3812 }
3813
3814 value = cf->args->elts;
3815
3816 if (ngx_strcmp(value[1].data, "off") == 0) {
Igor Sysoevad1e1232008-10-16 13:31:00 +00003817 clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
Igor Sysoev385af282008-07-30 12:34:04 +00003818 return NGX_CONF_OK;
3819 }
3820
3821 clcf->directio = ngx_parse_offset(&value[1]);
3822 if (clcf->directio == (off_t) NGX_ERROR) {
3823 return "invalid value";
3824 }
3825
3826 return NGX_CONF_OK;
3827}
3828
3829
3830static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00003831ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev74e95c22003-11-09 20:03:38 +00003832{
Igor Sysoev30870b42009-11-13 19:59:54 +00003833 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003834
Igor Sysoev17f0e662009-03-22 09:40:04 +00003835 u_char *p;
3836 ngx_int_t overwrite;
3837 ngx_str_t *value, uri, args;
3838 ngx_uint_t i, n;
3839 ngx_http_err_page_t *err;
3840 ngx_http_complex_value_t cv;
3841 ngx_http_compile_complex_value_t ccv;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003842
Igor Sysoev30870b42009-11-13 19:59:54 +00003843 if (clcf->error_pages == NULL) {
3844 clcf->error_pages = ngx_array_create(cf->pool, 4,
3845 sizeof(ngx_http_err_page_t));
3846 if (clcf->error_pages == NULL) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003847 return NGX_CONF_ERROR;
3848 }
3849 }
3850
3851 value = cf->args->elts;
3852
Igor Sysoev732a2712004-04-21 18:54:33 +00003853 i = cf->args->nelts - 2;
3854
3855 if (value[i].data[0] == '=') {
3856 if (i == 1) {
3857 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003858 "invalid value \"%V\"", &value[i]);
Igor Sysoev732a2712004-04-21 18:54:33 +00003859 return NGX_CONF_ERROR;
3860 }
3861
Igor Sysoeva2573672005-10-05 14:46:21 +00003862 if (value[i].len > 1) {
3863 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
Igor Sysoev732a2712004-04-21 18:54:33 +00003864
Igor Sysoeva2573672005-10-05 14:46:21 +00003865 if (overwrite == NGX_ERROR) {
3866 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3867 "invalid value \"%V\"", &value[i]);
3868 return NGX_CONF_ERROR;
3869 }
3870
3871 } else {
3872 overwrite = 0;
Igor Sysoev732a2712004-04-21 18:54:33 +00003873 }
3874
3875 n = 2;
3876
3877 } else {
Igor Sysoeva2573672005-10-05 14:46:21 +00003878 overwrite = -1;
Igor Sysoev732a2712004-04-21 18:54:33 +00003879 n = 1;
3880 }
3881
Igor Sysoev08e63d42006-08-14 15:09:38 +00003882 uri = value[cf->args->nelts - 1];
Igor Sysoev08e63d42006-08-14 15:09:38 +00003883
Igor Sysoev17f0e662009-03-22 09:40:04 +00003884 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
Igor Sysoev08e63d42006-08-14 15:09:38 +00003885
Igor Sysoev17f0e662009-03-22 09:40:04 +00003886 ccv.cf = cf;
3887 ccv.value = &uri;
3888 ccv.complex_value = &cv;
Igor Sysoev08e63d42006-08-14 15:09:38 +00003889
Igor Sysoev17f0e662009-03-22 09:40:04 +00003890 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
3891 return NGX_CONF_ERROR;
Igor Sysoev08e63d42006-08-14 15:09:38 +00003892 }
3893
Igor Sysoev17f0e662009-03-22 09:40:04 +00003894 args.len = 0;
3895 args.data = NULL;
3896
Igor Sysoev64851bb2009-04-07 15:50:08 +00003897 if (cv.lengths == NULL && uri.data[0] == '/') {
Igor Sysoev17f0e662009-03-22 09:40:04 +00003898 p = (u_char *) ngx_strchr(uri.data, '?');
3899
3900 if (p) {
3901 cv.value.len = p - uri.data;
3902 cv.value.data = uri.data;
3903 p++;
3904 args.len = (uri.data + uri.len) - p;
3905 args.data = p;
3906 }
3907 }
Igor Sysoev615fe7f2008-04-29 10:06:43 +00003908
Igor Sysoev732a2712004-04-21 18:54:33 +00003909 for (i = 1; i < cf->args->nelts - n; i++) {
Igor Sysoev30870b42009-11-13 19:59:54 +00003910 err = ngx_array_push(clcf->error_pages);
Igor Sysoevc1571722005-03-19 12:38:37 +00003911 if (err == NULL) {
Igor Sysoev732a2712004-04-21 18:54:33 +00003912 return NGX_CONF_ERROR;
3913 }
3914
Igor Sysoev3f4685f2004-04-25 20:13:21 +00003915 err->status = ngx_atoi(value[i].data, value[i].len);
Igor Sysoevaa828612005-02-09 14:31:07 +00003916
Igor Sysoev586f7a52006-09-25 17:48:34 +00003917 if (err->status == NGX_ERROR || err->status == 499) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003918 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003919 "invalid value \"%V\"", &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00003920 return NGX_CONF_ERROR;
3921 }
3922
Igor Sysoev3f4685f2004-04-25 20:13:21 +00003923 if (err->status < 400 || err->status > 599) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00003924 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00003925 "value \"%V\" must be between 400 and 599",
3926 &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00003927 return NGX_CONF_ERROR;
3928 }
3929
Igor Sysoevfb140922008-03-10 14:45:41 +00003930 if (overwrite >= 0) {
3931 err->overwrite = overwrite;
3932
3933 } else {
3934 switch (err->status) {
3935 case NGX_HTTP_TO_HTTPS:
3936 case NGX_HTTPS_CERT_ERROR:
3937 case NGX_HTTPS_NO_CERT:
3938 err->overwrite = NGX_HTTP_BAD_REQUEST;
3939 break;
3940
3941 default:
3942 err->overwrite = err->status;
3943 break;
3944 }
3945 }
Igor Sysoeva2573672005-10-05 14:46:21 +00003946
Igor Sysoev17f0e662009-03-22 09:40:04 +00003947 err->value = cv;
Igor Sysoev1af70902009-03-22 15:52:52 +00003948 err->args = args;
Igor Sysoev74e95c22003-11-09 20:03:38 +00003949 }
3950
3951 return NGX_CONF_OK;
3952}
3953
3954
Igor Sysoevaa828612005-02-09 14:31:07 +00003955static char *
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003956ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3957{
3958 ngx_http_core_loc_conf_t *clcf = conf;
3959
3960 ngx_str_t *value;
Igor Sysoevecd82282009-04-11 11:02:36 +00003961 ngx_int_t code;
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003962 ngx_uint_t i, n;
3963 ngx_http_try_file_t *tf;
3964 ngx_http_script_compile_t sc;
3965 ngx_http_core_main_conf_t *cmcf;
3966
3967 if (clcf->try_files) {
3968 return "is duplicate";
3969 }
3970
3971 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
3972
3973 cmcf->try_files = 1;
3974
3975 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
3976 if (tf == NULL) {
3977 return NGX_CONF_ERROR;
3978 }
3979
3980 clcf->try_files = tf;
3981
3982 value = cf->args->elts;
3983
3984 for (i = 0; i < cf->args->nelts - 1; i++) {
3985
3986 tf[i].name = value[i + 1];
3987
Igor Sysoev319dc272009-01-21 12:11:22 +00003988 if (tf[i].name.data[tf[i].name.len - 1] == '/') {
3989 tf[i].test_dir = 1;
3990 tf[i].name.len--;
Igor Sysoevcd70a522009-03-20 16:47:23 +00003991 tf[i].name.data[tf[i].name.len] = '\0';
Igor Sysoev319dc272009-01-21 12:11:22 +00003992 }
3993
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00003994 n = ngx_http_script_variables_count(&tf[i].name);
3995
3996 if (n) {
3997 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3998
3999 sc.cf = cf;
4000 sc.source = &tf[i].name;
4001 sc.lengths = &tf[i].lengths;
4002 sc.values = &tf[i].values;
4003 sc.variables = n;
4004 sc.complete_lengths = 1;
4005 sc.complete_values = 1;
4006
4007 if (ngx_http_script_compile(&sc) != NGX_OK) {
4008 return NGX_CONF_ERROR;
4009 }
4010
4011 } else {
4012 /* add trailing '\0' to length */
4013 tf[i].name.len++;
4014 }
4015 }
4016
Igor Sysoevecd82282009-04-11 11:02:36 +00004017 if (tf[i - 1].name.data[0] == '=') {
4018
4019 code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
4020
4021 if (code == NGX_ERROR) {
4022 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4023 "invalid code \"%*s\"",
4024 tf[i - 1].name.len - 1, tf[i - 1].name.data);
4025 return NGX_CONF_ERROR;
4026 }
4027
4028 tf[i].code = code;
4029 }
4030
Igor Sysoevd8e3d0b2008-12-15 10:56:48 +00004031 return NGX_CONF_OK;
4032}
4033
4034
4035static char *
Igor Sysoev140c7552007-09-01 12:12:48 +00004036ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4037{
Igor Sysoev30870b42009-11-13 19:59:54 +00004038 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev140c7552007-09-01 12:12:48 +00004039
4040 time_t inactive;
4041 ngx_str_t *value, s;
4042 ngx_int_t max;
4043 ngx_uint_t i;
4044
Igor Sysoev30870b42009-11-13 19:59:54 +00004045 if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) {
Igor Sysoev140c7552007-09-01 12:12:48 +00004046 return "is duplicate";
4047 }
4048
4049 value = cf->args->elts;
4050
4051 max = 0;
4052 inactive = 60;
4053
4054 for (i = 1; i < cf->args->nelts; i++) {
4055
4056 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
4057
4058 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
4059 if (max == NGX_ERROR) {
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004060 goto failed;
Igor Sysoev140c7552007-09-01 12:12:48 +00004061 }
4062
4063 continue;
4064 }
4065
4066 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
4067
4068 s.len = value[i].len - 9;
4069 s.data = value[i].data + 9;
4070
4071 inactive = ngx_parse_time(&s, 1);
4072 if (inactive < 0) {
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004073 goto failed;
Igor Sysoev140c7552007-09-01 12:12:48 +00004074 }
4075
4076 continue;
4077 }
4078
4079 if (ngx_strcmp(value[i].data, "off") == 0) {
4080
Igor Sysoev30870b42009-11-13 19:59:54 +00004081 clcf->open_file_cache = NULL;
Igor Sysoev140c7552007-09-01 12:12:48 +00004082
4083 continue;
4084 }
4085
Igor Sysoev8d9c63f2008-07-03 19:19:45 +00004086 failed:
4087
Igor Sysoev140c7552007-09-01 12:12:48 +00004088 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4089 "invalid \"open_file_cache\" parameter \"%V\"",
4090 &value[i]);
4091 return NGX_CONF_ERROR;
4092 }
4093
Igor Sysoev30870b42009-11-13 19:59:54 +00004094 if (clcf->open_file_cache == NULL) {
Igor Sysoev140c7552007-09-01 12:12:48 +00004095 return NGX_CONF_OK;
4096 }
4097
4098 if (max == 0) {
4099 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4100 "\"open_file_cache\" must have \"max\" parameter");
4101 return NGX_CONF_ERROR;
4102 }
4103
Igor Sysoev30870b42009-11-13 19:59:54 +00004104 clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
4105 if (clcf->open_file_cache) {
Igor Sysoev140c7552007-09-01 12:12:48 +00004106 return NGX_CONF_OK;
4107 }
4108
4109 return NGX_CONF_ERROR;
4110}
4111
4112
4113static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00004114ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4115{
Igor Sysoev30870b42009-11-13 19:59:54 +00004116 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev899b44e2005-05-12 14:58:06 +00004117
Igor Sysoevc134eb02009-04-24 14:27:36 +00004118 ngx_str_t *value;
4119
Igor Sysoev30870b42009-11-13 19:59:54 +00004120 if (clcf->error_log) {
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00004121 return "is duplicate";
4122 }
4123
Igor Sysoevc134eb02009-04-24 14:27:36 +00004124 value = cf->args->elts;
4125
Igor Sysoev30870b42009-11-13 19:59:54 +00004126 clcf->error_log = ngx_log_create(cf->cycle, &value[1]);
4127 if (clcf->error_log == NULL) {
Igor Sysoev899b44e2005-05-12 14:58:06 +00004128 return NGX_CONF_ERROR;
4129 }
4130
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00004131 if (cf->args->nelts == 2) {
Igor Sysoev30870b42009-11-13 19:59:54 +00004132 clcf->error_log->log_level = NGX_LOG_ERR;
Igor Sysoev0cd76ea2009-04-30 13:53:42 +00004133 return NGX_CONF_OK;
4134 }
4135
Igor Sysoev30870b42009-11-13 19:59:54 +00004136 return ngx_log_set_levels(cf, clcf->error_log);
Igor Sysoev899b44e2005-05-12 14:58:06 +00004137}
4138
4139
4140static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00004141ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004142{
Igor Sysoev30870b42009-11-13 19:59:54 +00004143 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004144
4145 ngx_str_t *value;
4146
Igor Sysoev30870b42009-11-13 19:59:54 +00004147 if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004148 return "is duplicate";
4149 }
4150
4151 value = cf->args->elts;
4152
Igor Sysoev30870b42009-11-13 19:59:54 +00004153 clcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
Igor Sysoevaa828612005-02-09 14:31:07 +00004154
Igor Sysoev30870b42009-11-13 19:59:54 +00004155 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004156 return "invalid value";
4157 }
4158
Igor Sysoev30870b42009-11-13 19:59:54 +00004159 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004160 return "value must be less than 597 hours";
4161 }
4162
4163 if (cf->args->nelts == 2) {
4164 return NGX_CONF_OK;
4165 }
4166
Igor Sysoev30870b42009-11-13 19:59:54 +00004167 clcf->keepalive_header = ngx_parse_time(&value[2], 1);
Igor Sysoevaa828612005-02-09 14:31:07 +00004168
Igor Sysoev30870b42009-11-13 19:59:54 +00004169 if (clcf->keepalive_header == NGX_ERROR) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004170 return "invalid value";
4171 }
4172
Igor Sysoev30870b42009-11-13 19:59:54 +00004173 if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
Igor Sysoev307c3ad2004-09-17 16:07:35 +00004174 return "value must be less than 68 years";
4175 }
4176
4177 return NGX_CONF_OK;
4178}
4179
4180
Igor Sysoevaa828612005-02-09 14:31:07 +00004181static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00004182ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev9d639522003-07-07 06:11:50 +00004183{
Igor Sysoev30870b42009-11-13 19:59:54 +00004184 ngx_http_core_loc_conf_t *clcf = conf;
Igor Sysoev9d639522003-07-07 06:11:50 +00004185
Igor Sysoev30870b42009-11-13 19:59:54 +00004186 if (clcf->internal != NGX_CONF_UNSET) {
Igor Sysoev899b44e2005-05-12 14:58:06 +00004187 return "is duplicate";
Igor Sysoev03420a62004-01-20 20:40:08 +00004188 }
Igor Sysoev9d639522003-07-07 06:11:50 +00004189
Igor Sysoev30870b42009-11-13 19:59:54 +00004190 clcf->internal = 1;
Igor Sysoev899b44e2005-05-12 14:58:06 +00004191
4192 return NGX_CONF_OK;
Igor Sysoev9d639522003-07-07 06:11:50 +00004193}
Igor Sysoevb5faed22003-10-29 08:30:44 +00004194
4195
Igor Sysoevaa828612005-02-09 14:31:07 +00004196static char *
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004197ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4198{
4199 ngx_http_core_loc_conf_t *clcf = conf;
4200
4201 ngx_url_t u;
4202 ngx_str_t *value;
4203
Igor Sysoevf39876c2008-03-06 08:48:55 +00004204 if (clcf->resolver) {
4205 return "is duplicate";
4206 }
4207
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004208 value = cf->args->elts;
4209
Igor Sysoev4d65f652007-11-30 22:08:59 +00004210 ngx_memzero(&u, sizeof(ngx_url_t));
4211
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004212 u.host = value[1];
4213 u.port = 53;
4214
4215 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
4216 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
4217 return NGX_CONF_ERROR;
4218 }
4219
Igor Sysoevdfd55112008-03-04 10:42:05 +00004220 clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004221 if (clcf->resolver == NULL) {
4222 return NGX_OK;
4223 }
4224
4225 return NGX_CONF_OK;
4226}
4227
4228
Igor Sysoevc16b0052007-12-27 14:21:59 +00004229#if (NGX_HTTP_GZIP)
4230
4231static char *
4232ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4233{
Igor Sysoevc16b0052007-12-27 14:21:59 +00004234 ngx_http_core_loc_conf_t *clcf = conf;
4235
Igor Sysoev54477e42008-08-26 15:09:28 +00004236#if (NGX_PCRE)
4237
Igor Sysoevc16b0052007-12-27 14:21:59 +00004238 ngx_str_t err, *value;
4239 ngx_uint_t i;
4240 ngx_regex_elt_t *re;
4241 u_char errstr[NGX_MAX_CONF_ERRSTR];
4242
4243 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
4244 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
4245 sizeof(ngx_regex_elt_t));
4246 if (clcf->gzip_disable == NULL) {
4247 return NGX_CONF_ERROR;
4248 }
4249 }
4250
4251 value = cf->args->elts;
4252
4253 err.len = NGX_MAX_CONF_ERRSTR;
4254 err.data = errstr;
4255
4256 for (i = 1; i < cf->args->nelts; i++) {
4257
Igor Sysoev54477e42008-08-26 15:09:28 +00004258 if (ngx_strcmp(value[1].data, "msie6") == 0) {
4259 clcf->gzip_disable_msie6 = 1;
4260 continue;
4261 }
4262
Igor Sysoevc16b0052007-12-27 14:21:59 +00004263 re = ngx_array_push(clcf->gzip_disable);
4264 if (re == NULL) {
4265 return NGX_CONF_ERROR;
4266 }
4267
4268 re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool,
4269 &err);
4270
4271 if (re->regex == NULL) {
4272 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
4273 return NGX_CONF_ERROR;
4274 }
4275
4276 re->name = value[i].data;
4277 }
4278
4279 return NGX_CONF_OK;
4280
4281#else
Igor Sysoev54477e42008-08-26 15:09:28 +00004282 ngx_str_t *value;
4283
4284 value = cf->args->elts;
4285
4286 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "msie6") == 0) {
4287 clcf->gzip_disable_msie6 = 1;
4288 return NGX_CONF_OK;
4289 }
4290
Igor Sysoevc16b0052007-12-27 14:21:59 +00004291 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev54477e42008-08-26 15:09:28 +00004292 "without PCRE library \"gzip_disable\" supports "
4293 "builtin \"msie6\" mask only");
Igor Sysoevc16b0052007-12-27 14:21:59 +00004294
4295 return NGX_CONF_ERROR;
4296#endif
4297}
4298
4299#endif
4300
4301
Igor Sysoev13f5ff92007-11-27 11:33:52 +00004302static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00004303ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
Igor Sysoevb5faed22003-10-29 08:30:44 +00004304{
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00004305#if (NGX_FREEBSD)
Igor Sysoev42b12b32004-12-02 18:40:46 +00004306 ssize_t *np = data;
Igor Sysoev924bd792004-10-11 15:07:03 +00004307
Igor Sysoev08e63d42006-08-14 15:09:38 +00004308 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
Igor Sysoevb5faed22003-10-29 08:30:44 +00004309 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4310 "\"send_lowat\" must be less than %d "
4311 "(sysctl net.inet.tcp.sendspace)",
4312 ngx_freebsd_net_inet_tcp_sendspace);
4313
4314 return NGX_CONF_ERROR;
4315 }
4316
Igor Sysoevf6906042004-11-25 16:17:31 +00004317#elif !(NGX_HAVE_SO_SNDLOWAT)
Igor Sysoev42b12b32004-12-02 18:40:46 +00004318 ssize_t *np = data;
Igor Sysoevb5faed22003-10-29 08:30:44 +00004319
4320 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4321 "\"send_lowat\" is not supported, ignored");
4322
Igor Sysoev924bd792004-10-11 15:07:03 +00004323 *np = 0;
4324
Igor Sysoevb5faed22003-10-29 08:30:44 +00004325#endif
4326
4327 return NGX_CONF_OK;
4328}
Igor Sysoev08d068f2007-05-07 09:20:42 +00004329
4330
4331static char *
4332ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
4333{
4334 size_t *sp = data;
4335
4336 if (*sp < NGX_MIN_POOL_SIZE) {
4337 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4338 "pool must be no less than %uz", NGX_MIN_POOL_SIZE);
4339
4340 return NGX_CONF_ERROR;
4341 }
4342
4343 return NGX_CONF_OK;
4344}