Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 2 | /* |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 3 | * Copyright (C) Igor Sysoev |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 7 | #include <ngx_config.h> |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 8 | #include <ngx_core.h> |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 9 | #include <ngx_http.h> |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 10 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 11 | |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 12 | typedef struct { |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 13 | u_char *name; |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 14 | uint32_t method; |
| 15 | } ngx_http_method_name_t; |
| 16 | |
| 17 | |
Igor Sysoev | 64304df | 2007-01-24 09:14:08 +0000 | [diff] [blame] | 18 | #define NGX_HTTP_REQUEST_BODY_FILE_OFF 0 |
| 19 | #define NGX_HTTP_REQUEST_BODY_FILE_ON 1 |
Igor Sysoev | cd5b99a | 2007-01-25 08:45:04 +0000 | [diff] [blame] | 20 | #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2 |
Igor Sysoev | 64304df | 2007-01-24 09:14:08 +0000 | [diff] [blame] | 21 | |
| 22 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 23 | static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r); |
| 24 | static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r, |
| 25 | ngx_http_location_tree_node_t *node); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 26 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 27 | static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf); |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 28 | static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); |
| 29 | static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); |
| 30 | static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); |
| 31 | static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 32 | void *parent, void *child); |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 33 | static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf); |
| 34 | static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 35 | void *parent, void *child); |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 36 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 37 | static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 38 | void *dummy); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 39 | static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 40 | void *dummy); |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 41 | static 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 Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 43 | |
| 44 | static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 45 | void *conf); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 46 | static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 47 | void *conf); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 48 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 49 | static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 50 | void *conf); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 51 | static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 52 | void *conf); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 53 | static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 54 | static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, |
| 55 | void *conf); |
Igor Sysoev | 385af28 | 2008-07-30 12:34:04 +0000 | [diff] [blame] | 56 | static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, |
| 57 | void *conf); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 58 | static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 59 | void *conf); |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 60 | static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, |
| 61 | void *conf); |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 62 | static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
| 63 | void *conf); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 64 | static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 65 | void *conf); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 66 | static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 67 | void *conf); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 68 | static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, |
| 69 | void *conf); |
Igor Sysoev | 14c8422 | 2007-11-30 22:08:29 +0000 | [diff] [blame] | 70 | static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 71 | void *conf); |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 72 | #if (NGX_HTTP_GZIP) |
| 73 | static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, |
| 74 | void *conf); |
| 75 | #endif |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 76 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 77 | static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); |
Igor Sysoev | 08d068f | 2007-05-07 09:20:42 +0000 | [diff] [blame] | 78 | static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 79 | |
| 80 | static ngx_conf_post_t ngx_http_core_lowat_post = |
Igor Sysoev | 5a8bc36 | 2007-05-07 08:49:15 +0000 | [diff] [blame] | 81 | { ngx_http_core_lowat_check }; |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 82 | |
Igor Sysoev | 08d068f | 2007-05-07 09:20:42 +0000 | [diff] [blame] | 83 | static ngx_conf_post_handler_pt ngx_http_core_pool_size_p = |
| 84 | ngx_http_core_pool_size; |
| 85 | |
Igor Sysoev | 5cdb2ce | 2008-05-24 15:43:48 +0000 | [diff] [blame] | 86 | static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_server_names = { |
| 87 | ngx_conf_deprecated, "optimize_server_names", "server_name_in_redirect" |
Igor Sysoev | 8290d28 | 2006-02-03 12:58:48 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
Igor Sysoev | 9b9616e | 2007-12-21 16:19:48 +0000 | [diff] [blame] | 90 | static 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 Sysoev | 2d028f8 | 2007-12-29 16:38:23 +0000 | [diff] [blame] | 94 | static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any = { |
| 95 | ngx_conf_deprecated, "satisfy_any", "satisfy" |
| 96 | }; |
| 97 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 98 | |
Igor Sysoev | 64304df | 2007-01-24 09:14:08 +0000 | [diff] [blame] | 99 | static 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 Sysoev | cd5b99a | 2007-01-25 08:45:04 +0000 | [diff] [blame] | 102 | { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN }, |
Igor Sysoev | 64304df | 2007-01-24 09:14:08 +0000 | [diff] [blame] | 103 | { ngx_null_string, 0 } |
| 104 | }; |
| 105 | |
| 106 | |
Igor Sysoev | bfff034 | 2009-08-30 09:52:39 +0000 | [diff] [blame] | 107 | #if (NGX_HAVE_FILE_AIO) |
| 108 | |
| 109 | static 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 Sysoev | 2d028f8 | 2007-12-29 16:38:23 +0000 | [diff] [blame] | 121 | static 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 Sysoev | 863325f | 2008-12-01 14:22:51 +0000 | [diff] [blame] | 128 | static ngx_conf_enum_t ngx_http_core_if_modified_since[] = { |
Igor Sysoev | 2c33648 | 2009-02-10 15:05:05 +0000 | [diff] [blame] | 129 | { ngx_string("off"), NGX_HTTP_IMS_OFF }, |
| 130 | { ngx_string("exact"), NGX_HTTP_IMS_EXACT }, |
| 131 | { ngx_string("before"), NGX_HTTP_IMS_BEFORE }, |
Igor Sysoev | 863325f | 2008-12-01 14:22:51 +0000 | [diff] [blame] | 132 | { ngx_null_string, 0 } |
| 133 | }; |
| 134 | |
| 135 | |
Igor Sysoev | 52859f2 | 2009-03-23 13:14:51 +0000 | [diff] [blame] | 136 | static ngx_path_init_t ngx_http_client_temp_path = { |
| 137 | ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 } |
| 138 | }; |
| 139 | |
| 140 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 141 | #if (NGX_HTTP_GZIP) |
| 142 | |
| 143 | static 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 | |
| 150 | static 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 | |
| 164 | static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache"); |
| 165 | static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store"); |
| 166 | static ngx_str_t ngx_http_gzip_private = ngx_string("private"); |
| 167 | |
| 168 | #endif |
| 169 | |
| 170 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 171 | static ngx_command_t ngx_http_core_commands[] = { |
| 172 | |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 173 | { 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 Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 187 | { ngx_string("server_names_hash_max_size"), |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 188 | NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, |
| 189 | ngx_conf_set_num_slot, |
| 190 | NGX_HTTP_MAIN_CONF_OFFSET, |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 191 | offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size), |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 192 | NULL }, |
| 193 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 194 | { ngx_string("server_names_hash_bucket_size"), |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 195 | NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, |
| 196 | ngx_conf_set_num_slot, |
| 197 | NGX_HTTP_MAIN_CONF_OFFSET, |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 198 | offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size), |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 199 | NULL }, |
| 200 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 201 | { ngx_string("server"), |
Igor Sysoev | 6f134cc | 2006-05-23 14:54:58 +0000 | [diff] [blame] | 202 | NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 203 | ngx_http_core_server, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 204 | 0, |
| 205 | 0, |
| 206 | NULL }, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 207 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 208 | { 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 Sysoev | 08d068f | 2007-05-07 09:20:42 +0000 | [diff] [blame] | 213 | &ngx_http_core_pool_size_p }, |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 214 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 215 | { 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 Sysoev | 08d068f | 2007-05-07 09:20:42 +0000 | [diff] [blame] | 220 | &ngx_http_core_pool_size_p }, |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 221 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 222 | { 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 Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 228 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 229 | { 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 Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 235 | |
Igor Sysoev | f7abd72 | 2004-09-23 06:32:00 +0000 | [diff] [blame] | 236 | { ngx_string("large_client_header_buffers"), |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 237 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2, |
| 238 | ngx_conf_set_bufs_slot, |
| 239 | NGX_HTTP_SRV_CONF_OFFSET, |
Igor Sysoev | f7abd72 | 2004-09-23 06:32:00 +0000 | [diff] [blame] | 240 | offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers), |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 241 | NULL }, |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 242 | |
Igor Sysoev | 8290d28 | 2006-02-03 12:58:48 +0000 | [diff] [blame] | 243 | { ngx_string("optimize_server_names"), |
| 244 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, |
| 245 | ngx_conf_set_flag_slot, |
Igor Sysoev | 5cdb2ce | 2008-05-24 15:43:48 +0000 | [diff] [blame] | 246 | 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 Sysoev | 3430346 | 2006-01-24 16:08:27 +0000 | [diff] [blame] | 249 | |
Igor Sysoev | 3362b8d | 2005-05-14 18:42:03 +0000 | [diff] [blame] | 250 | { 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 Sysoev | 8decab3 | 2007-10-18 11:36:58 +0000 | [diff] [blame] | 257 | { 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 Sysoev | 753792e | 2008-09-24 14:02:50 +0000 | [diff] [blame] | 264 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 271 | { ngx_string("location"), |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 272 | NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 273 | ngx_http_core_location, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 274 | NGX_HTTP_SRV_CONF_OFFSET, |
| 275 | 0, |
| 276 | NULL }, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 277 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 278 | { ngx_string("listen"), |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 279 | NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 280 | ngx_http_core_listen, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 281 | NGX_HTTP_SRV_CONF_OFFSET, |
| 282 | 0, |
| 283 | NULL }, |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 284 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 285 | { ngx_string("server_name"), |
| 286 | NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 287 | ngx_http_core_server_name, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 288 | NGX_HTTP_SRV_CONF_OFFSET, |
| 289 | 0, |
| 290 | NULL }, |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 291 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 292 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 306 | { ngx_string("types"), |
| 307 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF |
| 308 | |NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 309 | ngx_http_core_types, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 310 | NGX_HTTP_LOC_CONF_OFFSET, |
| 311 | 0, |
| 312 | NULL }, |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 313 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 314 | { 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 Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 320 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 321 | { ngx_string("root"), |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 322 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
| 323 | |NGX_CONF_TAKE1, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 324 | ngx_http_core_root, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 325 | NGX_HTTP_LOC_CONF_OFFSET, |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 326 | 0, |
| 327 | NULL }, |
| 328 | |
| 329 | { ngx_string("alias"), |
| 330 | NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 331 | ngx_http_core_root, |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 332 | NGX_HTTP_LOC_CONF_OFFSET, |
| 333 | 0, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 334 | NULL }, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 335 | |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 336 | { 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 Sysoev | ae02c19 | 2004-03-19 05:25:53 +0000 | [diff] [blame] | 343 | { ngx_string("client_max_body_size"), |
| 344 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 1765f47 | 2006-07-07 16:33:19 +0000 | [diff] [blame] | 345 | ngx_conf_set_off_slot, |
Igor Sysoev | ae02c19 | 2004-03-19 05:25:53 +0000 | [diff] [blame] | 346 | NGX_HTTP_LOC_CONF_OFFSET, |
| 347 | offsetof(ngx_http_core_loc_conf_t, client_max_body_size), |
| 348 | NULL }, |
| 349 | |
Igor Sysoev | dbb2776 | 2004-04-01 16:20:53 +0000 | [diff] [blame] | 350 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 357 | { 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 Sysoev | 2b0c76c | 2003-10-27 21:01:00 +0000 | [diff] [blame] | 363 | |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 364 | { 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 Sysoev | 52859f2 | 2009-03-23 13:14:51 +0000 | [diff] [blame] | 369 | NULL }, |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 370 | |
Igor Sysoev | 8a2b2fb | 2006-04-14 09:53:38 +0000 | [diff] [blame] | 371 | { ngx_string("client_body_in_file_only"), |
Igor Sysoev | e6460ea | 2009-05-14 11:39:06 +0000 | [diff] [blame] | 372 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 64304df | 2007-01-24 09:14:08 +0000 | [diff] [blame] | 373 | ngx_conf_set_enum_slot, |
Igor Sysoev | 8a2b2fb | 2006-04-14 09:53:38 +0000 | [diff] [blame] | 374 | NGX_HTTP_LOC_CONF_OFFSET, |
| 375 | offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only), |
Igor Sysoev | 64304df | 2007-01-24 09:14:08 +0000 | [diff] [blame] | 376 | &ngx_http_core_request_body_in_file }, |
Igor Sysoev | 8a2b2fb | 2006-04-14 09:53:38 +0000 | [diff] [blame] | 377 | |
Igor Sysoev | bfbded7 | 2009-05-14 11:41:33 +0000 | [diff] [blame] | 378 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 385 | { ngx_string("sendfile"), |
Igor Sysoev | 300de4f | 2007-01-21 17:42:28 +0000 | [diff] [blame] | 386 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
| 387 | |NGX_CONF_TAKE1, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 388 | ngx_conf_set_flag_slot, |
| 389 | NGX_HTTP_LOC_CONF_OFFSET, |
| 390 | offsetof(ngx_http_core_loc_conf_t, sendfile), |
| 391 | NULL }, |
Igor Sysoev | 5bf3d25 | 2003-10-22 07:05:29 +0000 | [diff] [blame] | 392 | |
Igor Sysoev | c9b57dc | 2007-05-07 06:33:39 +0000 | [diff] [blame] | 393 | { 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 Sysoev | a962506 | 2009-08-28 08:12:35 +0000 | [diff] [blame] | 400 | #if (NGX_HAVE_FILE_AIO) |
| 401 | |
| 402 | { ngx_string("aio"), |
Igor Sysoev | bfff034 | 2009-08-30 09:52:39 +0000 | [diff] [blame] | 403 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 404 | ngx_conf_set_enum_slot, |
Igor Sysoev | a962506 | 2009-08-28 08:12:35 +0000 | [diff] [blame] | 405 | NGX_HTTP_LOC_CONF_OFFSET, |
| 406 | offsetof(ngx_http_core_loc_conf_t, aio), |
Igor Sysoev | bfff034 | 2009-08-30 09:52:39 +0000 | [diff] [blame] | 407 | &ngx_http_core_aio }, |
Igor Sysoev | a962506 | 2009-08-28 08:12:35 +0000 | [diff] [blame] | 408 | |
| 409 | #endif |
| 410 | |
Igor Sysoev | 3266171 | 2009-09-30 13:21:52 +0000 | [diff] [blame] | 411 | { 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 Sysoev | 385af28 | 2008-07-30 12:34:04 +0000 | [diff] [blame] | 418 | { 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 Sysoev | 6fb506a | 2009-08-28 08:15:55 +0000 | [diff] [blame] | 425 | { 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 Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 432 | { 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 Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame] | 439 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 446 | { 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 Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 452 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 453 | { 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 Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 458 | &ngx_http_core_lowat_post }, |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 459 | |
Igor Sysoev | 7823cc3 | 2004-07-14 16:01:42 +0000 | [diff] [blame] | 460 | { 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 Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 468 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
| 469 | |NGX_CONF_TAKE1, |
Igor Sysoev | 7823cc3 | 2004-07-14 16:01:42 +0000 | [diff] [blame] | 470 | 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 Sysoev | 80027fc | 2009-06-02 14:01:50 +0000 | [diff] [blame] | 475 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 483 | { ngx_string("keepalive_timeout"), |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 484 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 485 | ngx_http_core_keepalive, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 486 | NGX_HTTP_LOC_CONF_OFFSET, |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 487 | 0, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 488 | NULL }, |
Igor Sysoev | fa73aac | 2003-05-21 13:28:21 +0000 | [diff] [blame] | 489 | |
Igor Sysoev | e959128 | 2009-05-25 15:38:36 +0000 | [diff] [blame] | 490 | { 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 Sysoev | 2d028f8 | 2007-12-29 16:38:23 +0000 | [diff] [blame] | 497 | { 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 Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 504 | { 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 Sysoev | 2d028f8 | 2007-12-29 16:38:23 +0000 | [diff] [blame] | 508 | offsetof(ngx_http_core_loc_conf_t, satisfy), |
| 509 | &ngx_conf_deprecated_satisfy_any }, |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 510 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 511 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 518 | { 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 Sysoev | b738757 | 2003-03-11 20:38:13 +0000 | [diff] [blame] | 524 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 525 | { 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 Sysoev | b738757 | 2003-03-11 20:38:13 +0000 | [diff] [blame] | 531 | |
Igor Sysoev | 0ab91b9 | 2004-06-06 19:49:18 +0000 | [diff] [blame] | 532 | { 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 Sysoev | 3f24ae2 | 2007-12-29 15:30:39 +0000 | [diff] [blame] | 539 | { 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 Sysoev | 7b190b4 | 2005-06-07 15:56:31 +0000 | [diff] [blame] | 546 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 553 | { 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 Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 559 | |
Igor Sysoev | 3f8dc59 | 2006-08-28 16:57:48 +0000 | [diff] [blame] | 560 | { 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 Sysoev | 5192b36 | 2005-07-08 14:34:20 +0000 | [diff] [blame] | 567 | { 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 Sysoev | 2eec1e1 | 2008-09-27 15:08:02 +0000 | [diff] [blame] | 574 | { 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 Sysoev | 3f8dc59 | 2006-08-28 16:57:48 +0000 | [diff] [blame] | 581 | { 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 Sysoev | 070cf22 | 2007-10-22 10:17:34 +0000 | [diff] [blame] | 588 | { 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 Sysoev | 863325f | 2008-12-01 14:22:51 +0000 | [diff] [blame] | 595 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 602 | { ngx_string("error_page"), |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 603 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
| 604 | |NGX_CONF_2MORE, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 605 | ngx_http_core_error_page, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 606 | NGX_HTTP_LOC_CONF_OFFSET, |
| 607 | 0, |
| 608 | NULL }, |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 609 | |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 610 | { ngx_string("try_files"), |
Igor Sysoev | e018a9c | 2009-03-20 16:48:45 +0000 | [diff] [blame] | 611 | NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 612 | ngx_http_core_try_files, |
| 613 | NGX_HTTP_LOC_CONF_OFFSET, |
| 614 | 0, |
| 615 | NULL }, |
| 616 | |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 617 | { 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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 625 | { ngx_string("error_log"), |
Igor Sysoev | 03420a6 | 2004-01-20 20:40:08 +0000 | [diff] [blame] | 626 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 627 | ngx_http_core_error_log, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 628 | NGX_HTTP_LOC_CONF_OFFSET, |
| 629 | 0, |
| 630 | NULL }, |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 631 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 632 | { ngx_string("open_file_cache"), |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 633 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, |
| 634 | ngx_http_core_open_file_cache, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 635 | NGX_HTTP_LOC_CONF_OFFSET, |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 636 | offsetof(ngx_http_core_loc_conf_t, open_file_cache), |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 637 | NULL }, |
| 638 | |
Igor Sysoev | 9b9616e | 2007-12-21 16:19:48 +0000 | [diff] [blame] | 639 | { 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 Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 646 | { 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 Sysoev | 9b9616e | 2007-12-21 16:19:48 +0000 | [diff] [blame] | 650 | offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid), |
| 651 | &ngx_conf_deprecated_open_file_cache_retest }, |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 652 | |
Igor Sysoev | f3b0e49 | 2007-12-22 13:19:39 +0000 | [diff] [blame] | 653 | { 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 Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 660 | { 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 Sysoev | 67f88e9 | 2004-03-12 16:57:08 +0000 | [diff] [blame] | 666 | |
Igor Sysoev | 9afd58f | 2007-09-03 08:41:42 +0000 | [diff] [blame] | 667 | { 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 Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 674 | { 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 Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 688 | #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 Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 720 | ngx_null_command |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 721 | }; |
| 722 | |
| 723 | |
Igor Sysoev | 8f12558 | 2006-07-28 15:16:17 +0000 | [diff] [blame] | 724 | static ngx_http_module_t ngx_http_core_module_ctx = { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 725 | ngx_http_core_preconfiguration, /* preconfiguration */ |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 726 | NULL, /* postconfiguration */ |
Igor Sysoev | 7832933 | 2003-11-10 17:17:31 +0000 | [diff] [blame] | 727 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 728 | ngx_http_core_create_main_conf, /* create main configuration */ |
| 729 | ngx_http_core_init_main_conf, /* init main configuration */ |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 730 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 731 | 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 Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 736 | }; |
| 737 | |
| 738 | |
| 739 | ngx_module_t ngx_http_core_module = { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 740 | NGX_MODULE_V1, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 741 | &ngx_http_core_module_ctx, /* module context */ |
| 742 | ngx_http_core_commands, /* module directives */ |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 743 | NGX_HTTP_MODULE, /* module type */ |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 744 | NULL, /* init master */ |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 745 | NULL, /* init module */ |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 746 | 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 Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 752 | }; |
| 753 | |
| 754 | |
Igor Sysoev | ea8536b | 2009-04-15 09:53:22 +0000 | [diff] [blame] | 755 | ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " }; |
Igor Sysoev | 88b2406 | 2008-02-07 10:38:13 +0000 | [diff] [blame] | 756 | |
| 757 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 758 | void |
| 759 | ngx_http_handler(ngx_http_request_t *r) |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 760 | { |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 761 | ngx_http_core_main_conf_t *cmcf; |
| 762 | |
Igor Sysoev | e5a222c | 2005-01-25 12:27:35 +0000 | [diff] [blame] | 763 | r->connection->log->action = NULL; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 764 | |
| 765 | r->connection->unexpected_eof = 0; |
| 766 | |
Igor Sysoev | ef31643 | 2006-08-16 13:09:33 +0000 | [diff] [blame] | 767 | if (!r->internal) { |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 768 | 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 Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 782 | r->keepalive = 1; |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 783 | break; |
| 784 | } |
| 785 | |
| 786 | if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) { |
| 787 | |
| 788 | /* |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 789 | * MSIE may wait for some time if an response for |
| 790 | * a POST request was sent over a keepalive connection |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 791 | */ |
| 792 | |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 793 | r->keepalive = 0; |
| 794 | } |
Igor Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 795 | |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 796 | if (r->headers_in.content_length_n > 0) { |
| 797 | r->lingering_close = 1; |
Igor Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 798 | |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 799 | } else { |
| 800 | r->lingering_close = 0; |
| 801 | } |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 802 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 803 | r->phase_handler = 0; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 804 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 805 | } 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 Sysoev | 8a3cdc0 | 2006-09-25 17:49:49 +0000 | [diff] [blame] | 810 | if (r->unparsed_uri.len) { |
| 811 | r->valid_unparsed_uri = 1; |
| 812 | } |
| 813 | |
| 814 | r->valid_location = 1; |
Igor Sysoev | 6c49a5a | 2009-11-12 13:41:56 +0000 | [diff] [blame] | 815 | #if (NGX_HTTP_GZIP) |
| 816 | r->gzip_tested = 0; |
| 817 | r->gzip_ok = 0; |
| 818 | r->gzip_vary = 0; |
| 819 | #endif |
Igor Sysoev | 8a3cdc0 | 2006-09-25 17:49:49 +0000 | [diff] [blame] | 820 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 821 | r->write_event_handler = ngx_http_core_run_phases; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 822 | ngx_http_core_run_phases(r); |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 823 | } |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 824 | |
| 825 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 826 | void |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 827 | ngx_http_core_run_phases(ngx_http_request_t *r) |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 828 | { |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 829 | ngx_int_t rc; |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 830 | ngx_http_phase_handler_t *ph; |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 831 | ngx_http_core_main_conf_t *cmcf; |
| 832 | |
| 833 | cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
| 834 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 835 | ph = cmcf->phase_engine.handlers; |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 836 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 837 | while (ph[r->phase_handler].checker) { |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 838 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 839 | rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 840 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 841 | if (rc == NGX_OK) { |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 842 | return; |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 843 | } |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 844 | } |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 848 | ngx_int_t |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 849 | ngx_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 | |
| 885 | ngx_int_t |
| 886 | ngx_http_core_find_config_phase(ngx_http_request_t *r, |
| 887 | ngx_http_phase_handler_t *ph) |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 888 | { |
Igor Sysoev | 966e2a5 | 2007-08-15 15:57:26 +0000 | [diff] [blame] | 889 | u_char *p; |
| 890 | size_t len; |
Igor Sysoev | 303df47 | 2008-12-26 13:43:42 +0000 | [diff] [blame] | 891 | ngx_int_t rc; |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 892 | ngx_http_core_loc_conf_t *clcf; |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 893 | |
Igor Sysoev | 1ebfead | 2005-02-16 13:40:36 +0000 | [diff] [blame] | 894 | r->content_handler = NULL; |
| 895 | r->uri_changed = 0; |
| 896 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 897 | rc = ngx_http_core_find_location(r); |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 898 | |
Igor Sysoev | dc91128 | 2008-08-17 18:02:55 +0000 | [diff] [blame] | 899 | if (rc == NGX_ERROR) { |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 900 | ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
| 901 | return NGX_OK; |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Igor Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 904 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 905 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 906 | if (!r->internal && clcf->internal) { |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 907 | ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND); |
| 908 | return NGX_OK; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Igor Sysoev | a257367 | 2005-10-05 14:46:21 +0000 | [diff] [blame] | 911 | 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 Sysoev | b85fd59 | 2005-08-23 15:36:54 +0000 | [diff] [blame] | 916 | ngx_http_update_location_config(r); |
Igor Sysoev | 89690bf | 2004-03-23 06:01:52 +0000 | [diff] [blame] | 917 | |
| 918 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
Igor Sysoev | 1765f47 | 2006-07-07 16:33:19 +0000 | [diff] [blame] | 919 | "http cl:%O max:%O", |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 920 | r->headers_in.content_length_n, clcf->client_max_body_size); |
Igor Sysoev | 89690bf | 2004-03-23 06:01:52 +0000 | [diff] [blame] | 921 | |
| 922 | if (r->headers_in.content_length_n != -1 |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 923 | && !r->discard_body |
Igor Sysoev | 89690bf | 2004-03-23 06:01:52 +0000 | [diff] [blame] | 924 | && clcf->client_max_body_size |
Igor Sysoev | 1765f47 | 2006-07-07 16:33:19 +0000 | [diff] [blame] | 925 | && clcf->client_max_body_size < r->headers_in.content_length_n) |
Igor Sysoev | 89690bf | 2004-03-23 06:01:52 +0000 | [diff] [blame] | 926 | { |
| 927 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
Igor Sysoev | e345d26 | 2007-10-18 15:53:38 +0000 | [diff] [blame] | 928 | "client intended to send too large body: %O bytes", |
Igor Sysoev | 89690bf | 2004-03-23 06:01:52 +0000 | [diff] [blame] | 929 | r->headers_in.content_length_n); |
| 930 | |
Igor Sysoev | 21e3e05 | 2009-09-01 12:47:34 +0000 | [diff] [blame] | 931 | (void) ngx_http_discard_request_body(r); |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 932 | ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE); |
| 933 | return NGX_OK; |
Igor Sysoev | 89690bf | 2004-03-23 06:01:52 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 936 | if (rc == NGX_DONE) { |
Igor Sysoev | aab4d8c | 2004-09-06 18:45:00 +0000 | [diff] [blame] | 937 | r->headers_out.location = ngx_list_push(&r->headers_out.headers); |
| 938 | if (r->headers_out.location == NULL) { |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 939 | ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
| 940 | return NGX_OK; |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 943 | /* |
| 944 | * we do not need to set the r->headers_out.location->hash and |
| 945 | * r->headers_out.location->key fields |
| 946 | */ |
| 947 | |
Igor Sysoev | 966e2a5 | 2007-08-15 15:57:26 +0000 | [diff] [blame] | 948 | 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 Sysoev | 7f6b2ff | 2008-06-17 15:00:30 +0000 | [diff] [blame] | 953 | p = ngx_pnalloc(r->pool, len); |
Igor Sysoev | 966e2a5 | 2007-08-15 15:57:26 +0000 | [diff] [blame] | 954 | |
| 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 Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 967 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 968 | ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY); |
| 969 | return NGX_OK; |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 972 | r->phase_handler++; |
| 973 | return NGX_AGAIN; |
| 974 | } |
| 975 | |
| 976 | |
| 977 | ngx_int_t |
| 978 | ngx_http_core_post_rewrite_phase(ngx_http_request_t *r, |
| 979 | ngx_http_phase_handler_t *ph) |
| 980 | { |
Igor Sysoev | b078075 | 2008-06-15 19:07:35 +0000 | [diff] [blame] | 981 | ngx_http_core_srv_conf_t *cscf; |
| 982 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 983 | 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 Sysoev | b078075 | 2008-06-15 19:07:35 +0000 | [diff] [blame] | 1014 | cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
| 1015 | r->loc_conf = cscf->ctx->loc_conf; |
| 1016 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 1017 | return NGX_AGAIN; |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | ngx_int_t |
| 1022 | ngx_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 Sysoev | 2d028f8 | 2007-12-29 16:38:23 +0000 | [diff] [blame] | 1048 | if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) { |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 1049 | |
| 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 | |
| 1082 | ngx_int_t |
| 1083 | ngx_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 | |
| 1105 | ngx_int_t |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1106 | ngx_http_core_try_files_phase(ngx_http_request_t *r, |
| 1107 | ngx_http_phase_handler_t *ph) |
| 1108 | { |
Igor Sysoev | 67392e8 | 2009-01-27 16:22:02 +0000 | [diff] [blame] | 1109 | size_t len, root, alias, reserve, allocated; |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1110 | u_char *p, *name; |
Igor Sysoev | b03aa7f | 2009-03-19 13:42:27 +0000 | [diff] [blame] | 1111 | ngx_str_t path, args; |
Igor Sysoev | 319dc27 | 2009-01-21 12:11:22 +0000 | [diff] [blame] | 1112 | ngx_uint_t test_dir; |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1113 | 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 Sysoev | 67392e8 | 2009-01-27 16:22:02 +0000 | [diff] [blame] | 1133 | /* suppress MSVC warning */ |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1134 | 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 Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1147 | |
| 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 Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1160 | /* 16 bytes are preallocation */ |
Igor Sysoev | 42c67dd | 2009-03-01 19:10:36 +0000 | [diff] [blame] | 1161 | reserve = ngx_abs((ssize_t) (len - r->uri.len)) + alias + 16; |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1162 | |
| 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 Sysoev | 195860b | 2008-12-24 07:14:01 +0000 | [diff] [blame] | 1187 | e.flushed = 1; |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1188 | |
| 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 Sysoev | 51ed97f | 2009-03-14 17:10:25 +0000 | [diff] [blame] | 1196 | *e.pos = '\0'; |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1197 | |
| 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 Sysoev | 319dc27 | 2009-01-21 12:11:22 +0000 | [diff] [blame] | 1204 | test_dir = tf->test_dir; |
| 1205 | |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1206 | tf++; |
| 1207 | |
Igor Sysoev | c7ce3a9 | 2009-03-20 16:50:53 +0000 | [diff] [blame] | 1208 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 1209 | "try to use file: \"%s\" \"%s\"", name, path.data); |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1210 | |
| 1211 | if (tf->lengths == NULL && tf->name.len == 0) { |
| 1212 | |
Igor Sysoev | ecd8228 | 2009-04-11 11:02:36 +0000 | [diff] [blame] | 1213 | if (tf->code) { |
| 1214 | ngx_http_finalize_request(r, tf->code); |
| 1215 | return NGX_OK; |
| 1216 | } |
| 1217 | |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1218 | 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 Sysoev | b03aa7f | 2009-03-19 13:42:27 +0000 | [diff] [blame] | 1225 | ngx_http_split_args(r, &path, &args); |
| 1226 | |
| 1227 | (void) ngx_http_internal_redirect(r, &path, &args); |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Igor Sysoev | fb30a18 | 2009-08-31 11:21:04 +0000 | [diff] [blame] | 1230 | ngx_http_finalize_request(r, NGX_DONE); |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1231 | 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 Sysoev | f1cc457 | 2009-04-27 09:55:53 +0000 | [diff] [blame] | 1239 | of.test_only = 1; |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1240 | 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 Sysoev | 7f6d71b | 2009-09-25 09:13:08 +0000 | [diff] [blame] | 1246 | if (of.err != NGX_ENOENT |
| 1247 | && of.err != NGX_ENOTDIR |
| 1248 | && of.err != NGX_ENAMETOOLONG) |
| 1249 | { |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1250 | ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, |
Igor Sysoev | f1cc457 | 2009-04-27 09:55:53 +0000 | [diff] [blame] | 1251 | "%s \"%s\" failed", of.failed, path.data); |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | continue; |
| 1255 | } |
| 1256 | |
Igor Sysoev | 319dc27 | 2009-01-21 12:11:22 +0000 | [diff] [blame] | 1257 | if (of.is_dir && !test_dir) { |
Igor Sysoev | 977fd90 | 2009-01-19 11:24:25 +0000 | [diff] [blame] | 1258 | continue; |
| 1259 | } |
| 1260 | |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1261 | 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 Sysoev | c28d632 | 2009-07-14 08:38:28 +0000 | [diff] [blame] | 1279 | ngx_http_set_exten(r); |
Igor Sysoev | b17bf52 | 2009-02-14 17:26:26 +0000 | [diff] [blame] | 1280 | |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 1281 | 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 | |
| 1292 | ngx_int_t |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 1293 | ngx_http_core_content_phase(ngx_http_request_t *r, |
| 1294 | ngx_http_phase_handler_t *ph) |
| 1295 | { |
Igor Sysoev | 0e5f86d | 2006-10-12 13:36:54 +0000 | [diff] [blame] | 1296 | size_t root; |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 1297 | 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 Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 1311 | 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 Sysoev | 0e5f86d | 2006-10-12 13:36:54 +0000 | [diff] [blame] | 1329 | if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) { |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 1330 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
Igor Sysoev | 9d2811b | 2007-09-27 09:39:29 +0000 | [diff] [blame] | 1331 | "directory index of \"%s\" is forbidden", path.data); |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 1332 | } |
| 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 Sysoev | b85fd59 | 2005-08-23 15:36:54 +0000 | [diff] [blame] | 1341 | return NGX_OK; |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | void |
| 1346 | ngx_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 Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 1352 | 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 Sysoev | b051817 | 2006-04-26 15:21:08 +0000 | [diff] [blame] | 1357 | if (r == r->main) { |
Igor Sysoev | 0cd76ea | 2009-04-30 13:53:42 +0000 | [diff] [blame] | 1358 | r->connection->log->file = clcf->error_log->file; |
Igor Sysoev | 4ca98f6 | 2007-03-28 14:38:33 +0000 | [diff] [blame] | 1359 | |
Igor Sysoev | b051817 | 2006-04-26 15:21:08 +0000 | [diff] [blame] | 1360 | if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { |
Igor Sysoev | 0cd76ea | 2009-04-30 13:53:42 +0000 | [diff] [blame] | 1361 | r->connection->log->log_level = clcf->error_log->log_level; |
Igor Sysoev | b051817 | 2006-04-26 15:21:08 +0000 | [diff] [blame] | 1362 | } |
Igor Sysoev | b85fd59 | 2005-08-23 15:36:54 +0000 | [diff] [blame] | 1363 | } |
| 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 Sysoev | 8a2b2fb | 2006-04-14 09:53:38 +0000 | [diff] [blame] | 1372 | if (clcf->client_body_in_file_only) { |
| 1373 | r->request_body_in_file_only = 1; |
| 1374 | r->request_body_in_persistent_file = 1; |
Igor Sysoev | cd5b99a | 2007-01-25 08:45:04 +0000 | [diff] [blame] | 1375 | r->request_body_in_clean_file = |
| 1376 | clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN; |
Igor Sysoev | 7bdb720 | 2006-04-19 15:30:56 +0000 | [diff] [blame] | 1377 | r->request_body_file_log_level = NGX_LOG_NOTICE; |
| 1378 | |
| 1379 | } else { |
| 1380 | r->request_body_file_log_level = NGX_LOG_WARN; |
Igor Sysoev | 8a2b2fb | 2006-04-14 09:53:38 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Igor Sysoev | bfbded7 | 2009-05-14 11:41:33 +0000 | [diff] [blame] | 1383 | r->request_body_in_single_buf = clcf->client_body_in_single_buffer; |
| 1384 | |
Igor Sysoev | e959128 | 2009-05-25 15:38:36 +0000 | [diff] [blame] | 1385 | 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 Sysoev | b85fd59 | 2005-08-23 15:36:54 +0000 | [diff] [blame] | 1392 | } |
| 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 Sysoev | c2807ec | 2006-02-16 15:26:46 +0000 | [diff] [blame] | 1399 | if (r->limit_rate == 0) { |
| 1400 | r->limit_rate = clcf->limit_rate; |
| 1401 | } |
Igor Sysoev | 5192b36 | 2005-07-08 14:34:20 +0000 | [diff] [blame] | 1402 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 1403 | if (clcf->handler) { |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 1404 | r->content_handler = clcf->handler; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1405 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | |
Igor Sysoev | dc91128 | 2008-08-17 18:02:55 +0000 | [diff] [blame] | 1409 | /* |
| 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 Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 1417 | static ngx_int_t |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1418 | ngx_http_core_find_location(ngx_http_request_t *r) |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1419 | { |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1420 | ngx_int_t rc; |
| 1421 | ngx_http_core_loc_conf_t *pclcf; |
Igor Sysoev | 9a70242 | 2008-08-17 17:58:16 +0000 | [diff] [blame] | 1422 | #if (NGX_PCRE) |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 1423 | ngx_int_t n; |
Igor Sysoev | 9a70242 | 2008-08-17 17:58:16 +0000 | [diff] [blame] | 1424 | ngx_uint_t noregex; |
| 1425 | ngx_http_core_loc_conf_t *clcf, **clcfp; |
| 1426 | |
| 1427 | noregex = 0; |
| 1428 | #endif |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1429 | |
| 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 Sysoev | 9a70242 | 2008-08-17 17:58:16 +0000 | [diff] [blame] | 1435 | |
| 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 Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1442 | /* look up nested locations */ |
Igor Sysoev | 9a70242 | 2008-08-17 17:58:16 +0000 | [diff] [blame] | 1443 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1444 | 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 Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1454 | |
Igor Sysoev | 9a70242 | 2008-08-17 17:58:16 +0000 | [diff] [blame] | 1455 | if (noregex == 0 && pclcf->regex_locations) { |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1456 | |
| 1457 | for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) { |
| 1458 | |
| 1459 | ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 1460 | "test location: ~ \"%V\"", &(*clcfp)->name); |
| 1461 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 1462 | n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri); |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 1463 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 1464 | if (n == NGX_OK) { |
| 1465 | r->loc_conf = (*clcfp)->loc_conf; |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 1466 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 1467 | /* look up nested locations */ |
| 1468 | |
| 1469 | rc = ngx_http_core_find_location(r); |
| 1470 | |
| 1471 | return (rc == NGX_ERROR) ? rc : NGX_OK; |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 1474 | if (n == NGX_DECLINED) { |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1475 | continue; |
| 1476 | } |
| 1477 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 1478 | return NGX_ERROR; |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1479 | } |
| 1480 | } |
Igor Sysoev | 307ab0d | 2007-08-12 15:25:09 +0000 | [diff] [blame] | 1481 | #endif |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1482 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1483 | return rc; |
| 1484 | } |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1485 | |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1486 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1487 | /* |
| 1488 | * NGX_OK - exact match |
| 1489 | * NGX_DONE - auto redirect |
| 1490 | * NGX_AGAIN - inclusive match |
| 1491 | * NGX_DECLINED - no match |
| 1492 | */ |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1493 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1494 | static ngx_int_t |
| 1495 | ngx_http_core_find_static_location(ngx_http_request_t *r, |
| 1496 | ngx_http_location_tree_node_t *node) |
| 1497 | { |
| 1498 | u_char *uri; |
| 1499 | size_t len, n; |
| 1500 | ngx_int_t rc, rv; |
| 1501 | |
| 1502 | len = r->uri.len; |
| 1503 | uri = r->uri.data; |
| 1504 | |
| 1505 | rv = NGX_DECLINED; |
| 1506 | |
| 1507 | for ( ;; ) { |
| 1508 | |
| 1509 | if (node == NULL) { |
| 1510 | return rv; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1513 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1514 | "test location: \"%*s\"", node->len, node->name); |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1515 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1516 | n = (len <= (size_t) node->len) ? len : node->len; |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1517 | |
Igor Sysoev | 0f17f6c | 2008-07-29 16:55:11 +0000 | [diff] [blame] | 1518 | rc = ngx_filename_cmp(uri, node->name, n); |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1519 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1520 | if (rc != 0) { |
| 1521 | node = (rc < 0) ? node->left : node->right; |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1522 | |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1523 | continue; |
| 1524 | } |
| 1525 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1526 | if (len > (size_t) node->len) { |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1527 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1528 | if (node->inclusive) { |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1529 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1530 | r->loc_conf = node->inclusive->loc_conf; |
| 1531 | rv = NGX_AGAIN; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1532 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1533 | node = node->tree; |
| 1534 | uri += n; |
| 1535 | len -= n; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1536 | |
| 1537 | continue; |
Igor Sysoev | ea52123 | 2004-07-26 16:21:18 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1540 | /* exact only */ |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1541 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1542 | node = node->right; |
Igor Sysoev | 307ab0d | 2007-08-12 15:25:09 +0000 | [diff] [blame] | 1543 | |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1544 | continue; |
| 1545 | } |
| 1546 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1547 | if (len == (size_t) node->len) { |
| 1548 | |
| 1549 | r->loc_conf = (node->exact) ? node->exact->loc_conf: |
| 1550 | node->inclusive->loc_conf; |
| 1551 | return NGX_OK; |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1554 | /* len < node->len */ |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1555 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1556 | if (len + 1 == (size_t) node->len && node->auto_redirect) { |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1557 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 1558 | r->loc_conf = (node->exact) ? node->exact->loc_conf: |
| 1559 | node->inclusive->loc_conf; |
| 1560 | rv = NGX_DONE; |
| 1561 | } |
| 1562 | |
| 1563 | node = node->left; |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1564 | } |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1568 | void * |
| 1569 | ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash) |
| 1570 | { |
Igor Sysoev | 77fd67c | 2009-05-25 09:00:35 +0000 | [diff] [blame] | 1571 | u_char c, *lowcase; |
| 1572 | size_t len; |
| 1573 | ngx_uint_t i, hash; |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1574 | |
Igor Sysoev | 1cfb972 | 2009-11-30 13:15:10 +0000 | [diff] [blame] | 1575 | if (types_hash->size == 0) { |
| 1576 | return (void *) 4; |
| 1577 | } |
| 1578 | |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1579 | if (r->headers_out.content_type.len == 0) { |
| 1580 | return NULL; |
| 1581 | } |
| 1582 | |
Igor Sysoev | 77fd67c | 2009-05-25 09:00:35 +0000 | [diff] [blame] | 1583 | len = r->headers_out.content_type_len; |
| 1584 | |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1585 | if (r->headers_out.content_type_lowcase == NULL) { |
| 1586 | |
Igor Sysoev | 77fd67c | 2009-05-25 09:00:35 +0000 | [diff] [blame] | 1587 | lowcase = ngx_pnalloc(r->pool, len); |
| 1588 | if (lowcase == NULL) { |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1589 | return NULL; |
| 1590 | } |
| 1591 | |
Igor Sysoev | 77fd67c | 2009-05-25 09:00:35 +0000 | [diff] [blame] | 1592 | r->headers_out.content_type_lowcase = lowcase; |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1593 | |
| 1594 | hash = 0; |
| 1595 | |
Igor Sysoev | 77fd67c | 2009-05-25 09:00:35 +0000 | [diff] [blame] | 1596 | for (i = 0; i < len; i++) { |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1597 | c = ngx_tolower(r->headers_out.content_type.data[i]); |
| 1598 | hash = ngx_hash(hash, c); |
Igor Sysoev | 77fd67c | 2009-05-25 09:00:35 +0000 | [diff] [blame] | 1599 | lowcase[i] = c; |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | r->headers_out.content_type_hash = hash; |
| 1603 | } |
| 1604 | |
Igor Sysoev | 77fd67c | 2009-05-25 09:00:35 +0000 | [diff] [blame] | 1605 | return ngx_hash_find(types_hash, r->headers_out.content_type_hash, |
| 1606 | r->headers_out.content_type_lowcase, len); |
Igor Sysoev | b5bc3f9 | 2008-08-04 11:29:09 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 1610 | ngx_int_t |
| 1611 | ngx_http_set_content_type(ngx_http_request_t *r) |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1612 | { |
Igor Sysoev | 6a07833 | 2008-08-04 10:18:36 +0000 | [diff] [blame] | 1613 | u_char c, *exten; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 1614 | ngx_str_t *type; |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1615 | ngx_uint_t i, hash; |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1616 | ngx_http_core_loc_conf_t *clcf; |
| 1617 | |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 1618 | if (r->headers_out.content_type.len) { |
| 1619 | return NGX_OK; |
| 1620 | } |
| 1621 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1622 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 1623 | |
| 1624 | if (r->exten.len) { |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1625 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1626 | hash = 0; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1627 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1628 | for (i = 0; i < r->exten.len; i++) { |
| 1629 | c = r->exten.data[i]; |
| 1630 | |
| 1631 | if (c >= 'A' && c <= 'Z') { |
| 1632 | |
Igor Sysoev | 6a07833 | 2008-08-04 10:18:36 +0000 | [diff] [blame] | 1633 | exten = ngx_pnalloc(r->pool, r->exten.len); |
| 1634 | if (exten == NULL) { |
Igor Sysoev | 1f4220e | 2009-02-24 10:42:23 +0000 | [diff] [blame] | 1635 | return NGX_ERROR; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Igor Sysoev | 6a07833 | 2008-08-04 10:18:36 +0000 | [diff] [blame] | 1638 | hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1639 | |
| 1640 | r->exten.data = exten; |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1641 | |
| 1642 | break; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1645 | hash = ngx_hash(hash, c); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1648 | type = ngx_hash_find(&clcf->types_hash, hash, |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 1649 | r->exten.data, r->exten.len); |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1650 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 1651 | if (type) { |
Igor Sysoev | ef809b8 | 2006-06-28 16:00:26 +0000 | [diff] [blame] | 1652 | r->headers_out.content_type_len = type->len; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 1653 | r->headers_out.content_type = *type; |
Igor Sysoev | ef809b8 | 2006-06-28 16:00:26 +0000 | [diff] [blame] | 1654 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 1655 | return NGX_OK; |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | |
Igor Sysoev | ef809b8 | 2006-06-28 16:00:26 +0000 | [diff] [blame] | 1659 | r->headers_out.content_type_len = clcf->default_type.len; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 1660 | r->headers_out.content_type = clcf->default_type; |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1661 | |
| 1662 | return NGX_OK; |
| 1663 | } |
| 1664 | |
| 1665 | |
Igor Sysoev | c28d632 | 2009-07-14 08:38:28 +0000 | [diff] [blame] | 1666 | void |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 1667 | ngx_http_set_exten(ngx_http_request_t *r) |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 1668 | { |
| 1669 | ngx_int_t i; |
| 1670 | |
| 1671 | r->exten.len = 0; |
| 1672 | r->exten.data = NULL; |
| 1673 | |
| 1674 | for (i = r->uri.len - 1; i > 1; i--) { |
| 1675 | if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1676 | |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 1677 | r->exten.len = r->uri.len - i - 1; |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1678 | r->exten.data = &r->uri.data[i + 1]; |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 1679 | |
Igor Sysoev | c28d632 | 2009-07-14 08:38:28 +0000 | [diff] [blame] | 1680 | return; |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 1681 | |
| 1682 | } else if (r->uri.data[i] == '/') { |
Igor Sysoev | c28d632 | 2009-07-14 08:38:28 +0000 | [diff] [blame] | 1683 | return; |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
Igor Sysoev | c28d632 | 2009-07-14 08:38:28 +0000 | [diff] [blame] | 1687 | return; |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 1691 | ngx_int_t |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1692 | ngx_http_send_header(ngx_http_request_t *r) |
| 1693 | { |
| 1694 | if (r->err_status) { |
| 1695 | r->headers_out.status = r->err_status; |
| 1696 | r->headers_out.status_line.len = 0; |
| 1697 | } |
| 1698 | |
| 1699 | return ngx_http_top_header_filter(r); |
| 1700 | } |
| 1701 | |
| 1702 | |
| 1703 | ngx_int_t |
| 1704 | ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) |
| 1705 | { |
Igor Sysoev | 8bb3912 | 2009-05-08 14:31:59 +0000 | [diff] [blame] | 1706 | ngx_int_t rc; |
| 1707 | ngx_connection_t *c; |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1708 | |
Igor Sysoev | 8bb3912 | 2009-05-08 14:31:59 +0000 | [diff] [blame] | 1709 | c = r->connection; |
| 1710 | |
| 1711 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 1712 | "http output filter \"%V?%V\"", &r->uri, &r->args); |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1713 | |
| 1714 | rc = ngx_http_top_body_filter(r, in); |
| 1715 | |
| 1716 | if (rc == NGX_ERROR) { |
| 1717 | /* NGX_ERROR may be returned by any filter */ |
Igor Sysoev | 8bb3912 | 2009-05-08 14:31:59 +0000 | [diff] [blame] | 1718 | c->error = 1; |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | return rc; |
| 1722 | } |
| 1723 | |
| 1724 | |
| 1725 | u_char * |
| 1726 | ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path, |
Igor Sysoev | 0e5f86d | 2006-10-12 13:36:54 +0000 | [diff] [blame] | 1727 | size_t *root_length, size_t reserved) |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1728 | { |
Igor Sysoev | 8fea885 | 2006-03-15 09:53:04 +0000 | [diff] [blame] | 1729 | u_char *last; |
| 1730 | size_t alias; |
| 1731 | ngx_http_core_loc_conf_t *clcf; |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1732 | |
| 1733 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 1734 | |
| 1735 | alias = clcf->alias ? clcf->name.len : 0; |
| 1736 | |
Igor Sysoev | 3430346 | 2006-01-24 16:08:27 +0000 | [diff] [blame] | 1737 | if (alias && !r->valid_location) { |
| 1738 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
| 1739 | "\"alias\" could not be used in location \"%V\" " |
| 1740 | "where URI was rewritten", &clcf->name); |
| 1741 | return NULL; |
| 1742 | } |
| 1743 | |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 1744 | if (clcf->root_lengths == NULL) { |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1745 | |
Igor Sysoev | 0e5f86d | 2006-10-12 13:36:54 +0000 | [diff] [blame] | 1746 | *root_length = clcf->root.len; |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 1747 | |
Igor Sysoev | bb7d615 | 2009-03-14 19:20:34 +0000 | [diff] [blame] | 1748 | path->len = clcf->root.len + reserved + r->uri.len - alias + 1; |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 1749 | |
Igor Sysoev | 7f6b2ff | 2008-06-17 15:00:30 +0000 | [diff] [blame] | 1750 | path->data = ngx_pnalloc(r->pool, path->len); |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 1751 | if (path->data == NULL) { |
| 1752 | return NULL; |
| 1753 | } |
| 1754 | |
| 1755 | last = ngx_copy(path->data, clcf->root.data, clcf->root.len); |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 1756 | |
Igor Sysoev | 8fea885 | 2006-03-15 09:53:04 +0000 | [diff] [blame] | 1757 | } else { |
Igor Sysoev | 1e5ef6b | 2009-03-26 15:24:19 +0000 | [diff] [blame] | 1758 | |
| 1759 | #if (NGX_PCRE) |
| 1760 | ngx_uint_t captures; |
| 1761 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 1762 | captures = alias && clcf->regex; |
Igor Sysoev | 1e5ef6b | 2009-03-26 15:24:19 +0000 | [diff] [blame] | 1763 | reserved += captures ? 1 : r->uri.len - alias + 1; |
| 1764 | #else |
| 1765 | reserved += r->uri.len - alias + 1; |
| 1766 | #endif |
Igor Sysoev | f76a6c2 | 2009-03-18 12:21:19 +0000 | [diff] [blame] | 1767 | |
| 1768 | if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved, |
Igor Sysoev | c55a104 | 2006-08-09 19:59:45 +0000 | [diff] [blame] | 1769 | clcf->root_values->elts) |
Igor Sysoev | 8f12558 | 2006-07-28 15:16:17 +0000 | [diff] [blame] | 1770 | == NULL) |
| 1771 | { |
| 1772 | return NULL; |
| 1773 | } |
| 1774 | |
Igor Sysoev | 1f4220e | 2009-02-24 10:42:23 +0000 | [diff] [blame] | 1775 | if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) { |
Igor Sysoev | 8fea885 | 2006-03-15 09:53:04 +0000 | [diff] [blame] | 1776 | return NULL; |
| 1777 | } |
| 1778 | |
Igor Sysoev | 0e5f86d | 2006-10-12 13:36:54 +0000 | [diff] [blame] | 1779 | *root_length = path->len - reserved; |
| 1780 | last = path->data + *root_length; |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 1781 | |
Igor Sysoev | 1e5ef6b | 2009-03-26 15:24:19 +0000 | [diff] [blame] | 1782 | #if (NGX_PCRE) |
| 1783 | if (captures) { |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 1784 | *last = '\0'; |
| 1785 | return last; |
| 1786 | } |
Igor Sysoev | 1e5ef6b | 2009-03-26 15:24:19 +0000 | [diff] [blame] | 1787 | #endif |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Igor Sysoev | 8fea885 | 2006-03-15 09:53:04 +0000 | [diff] [blame] | 1790 | last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); |
Igor Sysoev | 208eed2 | 2005-10-07 13:30:52 +0000 | [diff] [blame] | 1791 | |
| 1792 | return last; |
| 1793 | } |
| 1794 | |
| 1795 | |
| 1796 | ngx_int_t |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1797 | ngx_http_auth_basic_user(ngx_http_request_t *r) |
| 1798 | { |
| 1799 | ngx_str_t auth, encoded; |
| 1800 | ngx_uint_t len; |
| 1801 | |
| 1802 | if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) { |
| 1803 | return NGX_DECLINED; |
| 1804 | } |
| 1805 | |
| 1806 | if (r->headers_in.authorization == NULL) { |
| 1807 | r->headers_in.user.data = (u_char *) ""; |
| 1808 | return NGX_DECLINED; |
| 1809 | } |
| 1810 | |
| 1811 | encoded = r->headers_in.authorization->value; |
| 1812 | |
| 1813 | if (encoded.len < sizeof("Basic ") - 1 |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 1814 | || ngx_strncasecmp(encoded.data, (u_char *) "Basic ", |
| 1815 | sizeof("Basic ") - 1) |
| 1816 | != 0) |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1817 | { |
| 1818 | r->headers_in.user.data = (u_char *) ""; |
| 1819 | return NGX_DECLINED; |
| 1820 | } |
| 1821 | |
| 1822 | encoded.len -= sizeof("Basic ") - 1; |
| 1823 | encoded.data += sizeof("Basic ") - 1; |
| 1824 | |
| 1825 | while (encoded.len && encoded.data[0] == ' ') { |
| 1826 | encoded.len--; |
| 1827 | encoded.data++; |
| 1828 | } |
| 1829 | |
| 1830 | if (encoded.len == 0) { |
| 1831 | r->headers_in.user.data = (u_char *) ""; |
| 1832 | return NGX_DECLINED; |
| 1833 | } |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 1834 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1835 | auth.len = ngx_base64_decoded_length(encoded.len); |
Igor Sysoev | 7f6b2ff | 2008-06-17 15:00:30 +0000 | [diff] [blame] | 1836 | auth.data = ngx_pnalloc(r->pool, auth.len + 1); |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1837 | if (auth.data == NULL) { |
| 1838 | return NGX_ERROR; |
| 1839 | } |
| 1840 | |
| 1841 | if (ngx_decode_base64(&auth, &encoded) != NGX_OK) { |
| 1842 | r->headers_in.user.data = (u_char *) ""; |
| 1843 | return NGX_DECLINED; |
| 1844 | } |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 1845 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1846 | auth.data[auth.len] = '\0'; |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 1847 | |
| 1848 | for (len = 0; len < auth.len; len++) { |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1849 | if (auth.data[len] == ':') { |
| 1850 | break; |
| 1851 | } |
| 1852 | } |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 1853 | |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 1854 | if (len == 0 || len == auth.len) { |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1855 | r->headers_in.user.data = (u_char *) ""; |
| 1856 | return NGX_DECLINED; |
| 1857 | } |
| 1858 | |
| 1859 | r->headers_in.user.len = len; |
| 1860 | r->headers_in.user.data = auth.data; |
| 1861 | r->headers_in.passwd.len = auth.len - len - 1; |
| 1862 | r->headers_in.passwd.data = &auth.data[len + 1]; |
| 1863 | |
| 1864 | return NGX_OK; |
| 1865 | } |
| 1866 | |
| 1867 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 1868 | #if (NGX_HTTP_GZIP) |
| 1869 | |
| 1870 | ngx_int_t |
| 1871 | ngx_http_gzip_ok(ngx_http_request_t *r) |
| 1872 | { |
| 1873 | time_t date, expires; |
| 1874 | ngx_uint_t p; |
| 1875 | ngx_array_t *cc; |
| 1876 | ngx_table_elt_t *e, *d; |
| 1877 | ngx_http_core_loc_conf_t *clcf; |
| 1878 | |
Igor Sysoev | 6c49a5a | 2009-11-12 13:41:56 +0000 | [diff] [blame] | 1879 | r->gzip_tested = 1; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 1880 | |
| 1881 | if (r != r->main |
| 1882 | || r->headers_in.accept_encoding == NULL |
| 1883 | || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, |
| 1884 | "gzip", 4 - 1) |
| 1885 | == NULL |
| 1886 | |
| 1887 | /* |
| 1888 | * if the URL (without the "http://" prefix) is longer than 253 bytes, |
| 1889 | * then MSIE 4.x can not handle the compressed stream - it waits |
| 1890 | * too long, hangs up or crashes |
| 1891 | */ |
| 1892 | |
| 1893 | || (r->headers_in.msie4 && r->unparsed_uri.len > 200)) |
| 1894 | { |
| 1895 | return NGX_DECLINED; |
| 1896 | } |
| 1897 | |
| 1898 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 1899 | |
Igor Sysoev | 54477e4 | 2008-08-26 15:09:28 +0000 | [diff] [blame] | 1900 | if (r->headers_in.msie6 && clcf->gzip_disable_msie6) { |
| 1901 | return NGX_DECLINED; |
| 1902 | } |
| 1903 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 1904 | if (r->http_version < clcf->gzip_http_version) { |
| 1905 | return NGX_DECLINED; |
| 1906 | } |
| 1907 | |
| 1908 | if (r->headers_in.via == NULL) { |
| 1909 | goto ok; |
| 1910 | } |
| 1911 | |
| 1912 | p = clcf->gzip_proxied; |
| 1913 | |
| 1914 | if (p & NGX_HTTP_GZIP_PROXIED_OFF) { |
| 1915 | return NGX_DECLINED; |
| 1916 | } |
| 1917 | |
| 1918 | if (p & NGX_HTTP_GZIP_PROXIED_ANY) { |
| 1919 | goto ok; |
| 1920 | } |
| 1921 | |
| 1922 | if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) { |
| 1923 | goto ok; |
| 1924 | } |
| 1925 | |
| 1926 | e = r->headers_out.expires; |
| 1927 | |
| 1928 | if (e) { |
| 1929 | |
| 1930 | if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) { |
| 1931 | return NGX_DECLINED; |
| 1932 | } |
| 1933 | |
| 1934 | expires = ngx_http_parse_time(e->value.data, e->value.len); |
| 1935 | if (expires == NGX_ERROR) { |
| 1936 | return NGX_DECLINED; |
| 1937 | } |
| 1938 | |
| 1939 | d = r->headers_out.date; |
| 1940 | |
| 1941 | if (d) { |
| 1942 | date = ngx_http_parse_time(d->value.data, d->value.len); |
| 1943 | if (date == NGX_ERROR) { |
| 1944 | return NGX_DECLINED; |
| 1945 | } |
| 1946 | |
| 1947 | } else { |
| 1948 | date = ngx_time(); |
| 1949 | } |
| 1950 | |
| 1951 | if (expires < date) { |
| 1952 | goto ok; |
| 1953 | } |
| 1954 | |
| 1955 | return NGX_DECLINED; |
| 1956 | } |
| 1957 | |
| 1958 | cc = &r->headers_out.cache_control; |
| 1959 | |
| 1960 | if (cc->elts) { |
| 1961 | |
| 1962 | if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE) |
| 1963 | && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache, |
| 1964 | NULL) |
| 1965 | >= 0) |
| 1966 | { |
| 1967 | goto ok; |
| 1968 | } |
| 1969 | |
| 1970 | if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE) |
| 1971 | && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store, |
| 1972 | NULL) |
| 1973 | >= 0) |
| 1974 | { |
| 1975 | goto ok; |
| 1976 | } |
| 1977 | |
| 1978 | if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE) |
| 1979 | && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private, |
| 1980 | NULL) |
| 1981 | >= 0) |
| 1982 | { |
| 1983 | goto ok; |
| 1984 | } |
| 1985 | |
| 1986 | return NGX_DECLINED; |
| 1987 | } |
| 1988 | |
| 1989 | if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) { |
| 1990 | return NGX_DECLINED; |
| 1991 | } |
| 1992 | |
| 1993 | if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) { |
| 1994 | return NGX_DECLINED; |
| 1995 | } |
| 1996 | |
| 1997 | ok: |
| 1998 | |
| 1999 | #if (NGX_PCRE) |
| 2000 | |
| 2001 | if (clcf->gzip_disable && r->headers_in.user_agent) { |
| 2002 | |
Igor Sysoev | d5fe818 | 2007-12-28 13:15:36 +0000 | [diff] [blame] | 2003 | if (ngx_regex_exec_array(clcf->gzip_disable, |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 2004 | &r->headers_in.user_agent->value, |
| 2005 | r->connection->log) |
| 2006 | != NGX_DECLINED) |
| 2007 | { |
| 2008 | return NGX_DECLINED; |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | #endif |
| 2013 | |
Igor Sysoev | 6c49a5a | 2009-11-12 13:41:56 +0000 | [diff] [blame] | 2014 | r->gzip_ok = 1; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 2015 | |
| 2016 | return NGX_OK; |
| 2017 | } |
| 2018 | |
| 2019 | #endif |
| 2020 | |
| 2021 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 2022 | ngx_int_t |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2023 | ngx_http_subrequest(ngx_http_request_t *r, |
Igor Sysoev | 9fcccaf | 2006-10-10 14:30:39 +0000 | [diff] [blame] | 2024 | ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr, |
Igor Sysoev | 960100e | 2006-10-13 15:20:10 +0000 | [diff] [blame] | 2025 | ngx_http_post_subrequest_t *ps, ngx_uint_t flags) |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2026 | { |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 2027 | ngx_connection_t *c; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2028 | ngx_http_request_t *sr; |
| 2029 | ngx_http_core_srv_conf_t *cscf; |
| 2030 | ngx_http_postponed_request_t *pr, *p; |
| 2031 | |
Igor Sysoev | ef809b8 | 2006-06-28 16:00:26 +0000 | [diff] [blame] | 2032 | r->main->subrequests--; |
| 2033 | |
| 2034 | if (r->main->subrequests == 0) { |
| 2035 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
Igor Sysoev | 3f8dc59 | 2006-08-28 16:57:48 +0000 | [diff] [blame] | 2036 | "subrequests cycle while processing \"%V\"", uri); |
Igor Sysoev | 5fd6d34 | 2006-11-02 13:48:28 +0000 | [diff] [blame] | 2037 | r->main->subrequests = 1; |
Igor Sysoev | ef809b8 | 2006-06-28 16:00:26 +0000 | [diff] [blame] | 2038 | return NGX_ERROR; |
| 2039 | } |
| 2040 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2041 | sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t)); |
| 2042 | if (sr == NULL) { |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 2043 | return NGX_ERROR; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | sr->signature = NGX_HTTP_MODULE; |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 2047 | |
| 2048 | c = r->connection; |
| 2049 | sr->connection = c; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2050 | |
| 2051 | sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); |
| 2052 | if (sr->ctx == NULL) { |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 2053 | return NGX_ERROR; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | if (ngx_list_init(&sr->headers_out.headers, r->pool, 20, |
Igor Sysoev | c31a9bb | 2005-11-26 10:11:11 +0000 | [diff] [blame] | 2057 | sizeof(ngx_table_elt_t)) |
Igor Sysoev | 1f4220e | 2009-02-24 10:42:23 +0000 | [diff] [blame] | 2058 | != NGX_OK) |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2059 | { |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 2060 | return NGX_ERROR; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
| 2064 | sr->main_conf = cscf->ctx->main_conf; |
| 2065 | sr->srv_conf = cscf->ctx->srv_conf; |
| 2066 | sr->loc_conf = cscf->ctx->loc_conf; |
| 2067 | |
| 2068 | sr->pool = r->pool; |
| 2069 | |
| 2070 | sr->headers_in = r->headers_in; |
| 2071 | |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 2072 | ngx_http_clear_content_length(sr); |
| 2073 | ngx_http_clear_accept_ranges(sr); |
| 2074 | ngx_http_clear_last_modified(sr); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2075 | |
| 2076 | sr->request_body = r->request_body; |
| 2077 | |
| 2078 | sr->method = NGX_HTTP_GET; |
| 2079 | sr->http_version = r->http_version; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2080 | |
| 2081 | sr->request_line = r->request_line; |
| 2082 | sr->uri = *uri; |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 2083 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2084 | if (args) { |
| 2085 | sr->args = *args; |
| 2086 | } |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 2087 | |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 2088 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
| 2089 | "http subrequest \"%V?%V\"", uri, &sr->args); |
| 2090 | |
Igor Sysoev | 960100e | 2006-10-13 15:20:10 +0000 | [diff] [blame] | 2091 | sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0; |
| 2092 | sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0; |
Igor Sysoev | 851cd73 | 2008-12-08 14:23:20 +0000 | [diff] [blame] | 2093 | sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0; |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 2094 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2095 | sr->unparsed_uri = r->unparsed_uri; |
Igor Sysoev | 5a45c68 | 2008-01-08 21:06:38 +0000 | [diff] [blame] | 2096 | sr->method_name = ngx_http_core_get_method; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2097 | sr->http_protocol = r->http_protocol; |
| 2098 | |
Igor Sysoev | c28d632 | 2009-07-14 08:38:28 +0000 | [diff] [blame] | 2099 | ngx_http_set_exten(sr); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2100 | |
Igor Sysoev | f6e1fe3 | 2005-10-04 10:38:53 +0000 | [diff] [blame] | 2101 | sr->main = r->main; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2102 | sr->parent = r; |
Igor Sysoev | 960100e | 2006-10-13 15:20:10 +0000 | [diff] [blame] | 2103 | sr->post_subrequest = ps; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2104 | sr->read_event_handler = ngx_http_request_empty_handler; |
Igor Sysoev | 851cd73 | 2008-12-08 14:23:20 +0000 | [diff] [blame] | 2105 | sr->write_event_handler = ngx_http_handler; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2106 | |
Igor Sysoev | d8e54ad | 2008-12-24 06:11:04 +0000 | [diff] [blame] | 2107 | if (c->data == r && r->postponed == NULL) { |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 2108 | c->data = sr; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2111 | sr->variables = r->variables; |
| 2112 | |
| 2113 | sr->log_handler = r->log_handler; |
| 2114 | |
| 2115 | pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t)); |
| 2116 | if (pr == NULL) { |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 2117 | return NGX_ERROR; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | pr->request = sr; |
| 2121 | pr->out = NULL; |
| 2122 | pr->next = NULL; |
| 2123 | |
| 2124 | if (r->postponed) { |
| 2125 | for (p = r->postponed; p->next; p = p->next) { /* void */ } |
| 2126 | p->next = pr; |
| 2127 | |
| 2128 | } else { |
| 2129 | r->postponed = pr; |
| 2130 | } |
| 2131 | |
| 2132 | sr->internal = 1; |
| 2133 | |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 2134 | sr->discard_body = r->discard_body; |
Igor Sysoev | 303df47 | 2008-12-26 13:43:42 +0000 | [diff] [blame] | 2135 | sr->expect_tested = 1; |
Igor Sysoev | d52477f | 2005-05-16 13:53:20 +0000 | [diff] [blame] | 2136 | sr->main_filter_need_in_memory = r->main_filter_need_in_memory; |
| 2137 | |
Igor Sysoev | 6f134cc | 2006-05-23 14:54:58 +0000 | [diff] [blame] | 2138 | sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1; |
| 2139 | |
Igor Sysoev | 851cd73 | 2008-12-08 14:23:20 +0000 | [diff] [blame] | 2140 | r->main->subrequests++; |
Igor Sysoev | b603dd4 | 2009-08-26 16:04:05 +0000 | [diff] [blame] | 2141 | r->main->count++; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2142 | |
Igor Sysoev | 851cd73 | 2008-12-08 14:23:20 +0000 | [diff] [blame] | 2143 | *psr = sr; |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 2144 | |
Igor Sysoev | ddda411 | 2009-08-30 09:47:11 +0000 | [diff] [blame] | 2145 | return ngx_http_post_request(sr, NULL); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | |
| 2149 | ngx_int_t |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2150 | ngx_http_internal_redirect(ngx_http_request_t *r, |
| 2151 | ngx_str_t *uri, ngx_str_t *args) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2152 | { |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2153 | ngx_http_core_srv_conf_t *cscf; |
| 2154 | |
Igor Sysoev | 5fede1e | 2006-08-18 14:17:54 +0000 | [diff] [blame] | 2155 | r->uri_changes--; |
| 2156 | |
| 2157 | if (r->uri_changes == 0) { |
| 2158 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
Igor Sysoev | 3f8dc59 | 2006-08-28 16:57:48 +0000 | [diff] [blame] | 2159 | "rewrite or internal redirection cycle " |
| 2160 | "while internal redirect to \"%V\"", uri); |
| 2161 | |
Igor Sysoev | 526f36a | 2009-09-10 16:34:09 +0000 | [diff] [blame] | 2162 | r->main->count++; |
Igor Sysoev | 5fede1e | 2006-08-18 14:17:54 +0000 | [diff] [blame] | 2163 | ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
| 2164 | return NGX_DONE; |
| 2165 | } |
| 2166 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 2167 | r->uri = *uri; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 2168 | |
| 2169 | if (args) { |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 2170 | r->args = *args; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2171 | |
| 2172 | } else { |
| 2173 | r->args.len = 0; |
| 2174 | r->args.data = NULL; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 2177 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 2178 | "internal redirect: \"%V?%V\"", uri, &r->args); |
| 2179 | |
Igor Sysoev | c28d632 | 2009-07-14 08:38:28 +0000 | [diff] [blame] | 2180 | ngx_http_set_exten(r); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2181 | |
Igor Sysoev | ef31643 | 2006-08-16 13:09:33 +0000 | [diff] [blame] | 2182 | /* clear the modules contexts */ |
| 2183 | ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 2184 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2185 | cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
| 2186 | r->loc_conf = cscf->ctx->loc_conf; |
| 2187 | |
Igor Sysoev | b85fd59 | 2005-08-23 15:36:54 +0000 | [diff] [blame] | 2188 | ngx_http_update_location_config(r); |
| 2189 | |
Igor Sysoev | 52859f2 | 2009-03-23 13:14:51 +0000 | [diff] [blame] | 2190 | #if (NGX_HTTP_CACHE) |
| 2191 | r->cache = NULL; |
| 2192 | #endif |
| 2193 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2194 | r->internal = 1; |
Igor Sysoev | b603dd4 | 2009-08-26 16:04:05 +0000 | [diff] [blame] | 2195 | r->main->count++; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2196 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2197 | ngx_http_handler(r); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 2198 | |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 2199 | return NGX_DONE; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2203 | ngx_int_t |
| 2204 | ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name) |
| 2205 | { |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2206 | ngx_http_core_srv_conf_t *cscf; |
| 2207 | ngx_http_core_loc_conf_t **clcfp; |
| 2208 | ngx_http_core_main_conf_t *cmcf; |
| 2209 | |
Igor Sysoev | b603dd4 | 2009-08-26 16:04:05 +0000 | [diff] [blame] | 2210 | r->main->count++; |
| 2211 | |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2212 | cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
| 2213 | |
Igor Sysoev | 3dde93b | 2008-12-11 17:32:52 +0000 | [diff] [blame] | 2214 | if (cscf->named_locations) { |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2215 | |
Igor Sysoev | 3dde93b | 2008-12-11 17:32:52 +0000 | [diff] [blame] | 2216 | for (clcfp = cscf->named_locations; *clcfp; clcfp++) { |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2217 | |
Igor Sysoev | 3dde93b | 2008-12-11 17:32:52 +0000 | [diff] [blame] | 2218 | ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 2219 | "test location: \"%V\"", &(*clcfp)->name); |
| 2220 | |
| 2221 | if (name->len != (*clcfp)->name.len |
| 2222 | || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0) |
| 2223 | { |
| 2224 | continue; |
| 2225 | } |
| 2226 | |
| 2227 | ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 2228 | "using location: %V \"%V?%V\"", |
| 2229 | name, &r->uri, &r->args); |
| 2230 | |
| 2231 | r->internal = 1; |
| 2232 | r->content_handler = NULL; |
| 2233 | r->loc_conf = (*clcfp)->loc_conf; |
| 2234 | |
| 2235 | ngx_http_update_location_config(r); |
| 2236 | |
| 2237 | cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
| 2238 | |
| 2239 | r->phase_handler = cmcf->phase_engine.location_rewrite_index; |
| 2240 | |
| 2241 | ngx_http_core_run_phases(r); |
| 2242 | |
| 2243 | return NGX_DONE; |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2244 | } |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
Igor Sysoev | 9e039cf | 2007-10-22 10:15:48 +0000 | [diff] [blame] | 2248 | "could not find named location \"%V\"", name); |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2249 | |
| 2250 | ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 2251 | |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2252 | return NGX_DONE; |
| 2253 | } |
| 2254 | |
| 2255 | |
Igor Sysoev | 9ac946b | 2005-10-24 15:09:41 +0000 | [diff] [blame] | 2256 | ngx_http_cleanup_t * |
| 2257 | ngx_http_cleanup_add(ngx_http_request_t *r, size_t size) |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 2258 | { |
Igor Sysoev | 9ac946b | 2005-10-24 15:09:41 +0000 | [diff] [blame] | 2259 | ngx_http_cleanup_t *cln; |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 2260 | |
Igor Sysoev | 9ac946b | 2005-10-24 15:09:41 +0000 | [diff] [blame] | 2261 | r = r->main; |
| 2262 | |
| 2263 | cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t)); |
| 2264 | if (cln == NULL) { |
| 2265 | return NULL; |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
Igor Sysoev | 9ac946b | 2005-10-24 15:09:41 +0000 | [diff] [blame] | 2268 | if (size) { |
| 2269 | cln->data = ngx_palloc(r->pool, size); |
| 2270 | if (cln->data == NULL) { |
| 2271 | return NULL; |
| 2272 | } |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 2273 | |
Igor Sysoev | 9ac946b | 2005-10-24 15:09:41 +0000 | [diff] [blame] | 2274 | } else { |
| 2275 | cln->data = NULL; |
| 2276 | } |
| 2277 | |
| 2278 | cln->handler = NULL; |
| 2279 | cln->next = r->cleanup; |
| 2280 | |
| 2281 | r->cleanup = cln; |
| 2282 | |
| 2283 | ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 2284 | "http cleanup add: %p", cln); |
| 2285 | |
| 2286 | return cln; |
| 2287 | } |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 2288 | |
| 2289 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2290 | static char * |
| 2291 | ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2292 | { |
Igor Sysoev | c915106 | 2007-06-05 06:44:08 +0000 | [diff] [blame] | 2293 | char *rv; |
| 2294 | void *mconf; |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2295 | ngx_uint_t i; |
Igor Sysoev | c915106 | 2007-06-05 06:44:08 +0000 | [diff] [blame] | 2296 | ngx_conf_t pcf; |
| 2297 | ngx_http_module_t *module; |
| 2298 | ngx_http_conf_ctx_t *ctx, *http_ctx; |
| 2299 | ngx_http_core_srv_conf_t *cscf, **cscfp; |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2300 | ngx_http_core_main_conf_t *cmcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2301 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2302 | ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
| 2303 | if (ctx == NULL) { |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2304 | return NGX_CONF_ERROR; |
| 2305 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2306 | |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2307 | http_ctx = cf->ctx; |
| 2308 | ctx->main_conf = http_ctx->main_conf; |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 2309 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2310 | /* the server{}'s srv_conf */ |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 2311 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2312 | ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); |
| 2313 | if (ctx->srv_conf == NULL) { |
| 2314 | return NGX_CONF_ERROR; |
| 2315 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2316 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2317 | /* the server{}'s loc_conf */ |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 2318 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2319 | ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); |
| 2320 | if (ctx->loc_conf == NULL) { |
| 2321 | return NGX_CONF_ERROR; |
| 2322 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2323 | |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2324 | for (i = 0; ngx_modules[i]; i++) { |
| 2325 | if (ngx_modules[i]->type != NGX_HTTP_MODULE) { |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2326 | continue; |
| 2327 | } |
| 2328 | |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2329 | module = ngx_modules[i]->ctx; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2330 | |
| 2331 | if (module->create_srv_conf) { |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2332 | mconf = module->create_srv_conf(cf); |
| 2333 | if (mconf == NULL) { |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2334 | return NGX_CONF_ERROR; |
| 2335 | } |
| 2336 | |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2337 | ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | if (module->create_loc_conf) { |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2341 | mconf = module->create_loc_conf(cf); |
| 2342 | if (mconf == NULL) { |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2343 | return NGX_CONF_ERROR; |
| 2344 | } |
| 2345 | |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2346 | ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2347 | } |
| 2348 | } |
| 2349 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2350 | |
| 2351 | /* the server configuration context */ |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2352 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 2353 | cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2354 | cscf->ctx = ctx; |
| 2355 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2356 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 2357 | cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2358 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2359 | cscfp = ngx_array_push(&cmcf->servers); |
| 2360 | if (cscfp == NULL) { |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2361 | return NGX_CONF_ERROR; |
| 2362 | } |
| 2363 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2364 | *cscfp = cscf; |
| 2365 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2366 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2367 | /* parse inside server{} */ |
| 2368 | |
Igor Sysoev | 7b190b4 | 2005-06-07 15:56:31 +0000 | [diff] [blame] | 2369 | pcf = *cf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2370 | cf->ctx = ctx; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2371 | cf->cmd_type = NGX_HTTP_SRV_CONF; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2372 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2373 | rv = ngx_conf_parse(cf, NULL); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2374 | |
Igor Sysoev | 7b190b4 | 2005-06-07 15:56:31 +0000 | [diff] [blame] | 2375 | *cf = pcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2376 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2377 | return rv; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2381 | static char * |
| 2382 | ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2383 | { |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2384 | char *rv; |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2385 | u_char *mod; |
| 2386 | size_t len; |
| 2387 | ngx_str_t *value, *name; |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2388 | ngx_uint_t i; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2389 | ngx_conf_t save; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2390 | ngx_http_module_t *module; |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2391 | ngx_http_conf_ctx_t *ctx, *pctx; |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 2392 | ngx_http_core_loc_conf_t *clcf, *pclcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2393 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2394 | ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
| 2395 | if (ctx == NULL) { |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2396 | return NGX_CONF_ERROR; |
| 2397 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2398 | |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2399 | pctx = cf->ctx; |
| 2400 | ctx->main_conf = pctx->main_conf; |
| 2401 | ctx->srv_conf = pctx->srv_conf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2402 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2403 | ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); |
| 2404 | if (ctx->loc_conf == NULL) { |
| 2405 | return NGX_CONF_ERROR; |
| 2406 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2407 | |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2408 | for (i = 0; ngx_modules[i]; i++) { |
| 2409 | if (ngx_modules[i]->type != NGX_HTTP_MODULE) { |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2410 | continue; |
| 2411 | } |
| 2412 | |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2413 | module = ngx_modules[i]->ctx; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2414 | |
| 2415 | if (module->create_loc_conf) { |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2416 | ctx->loc_conf[ngx_modules[i]->ctx_index] = |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2417 | module->create_loc_conf(cf); |
Igor Sysoev | 6d9a660 | 2007-06-08 05:40:59 +0000 | [diff] [blame] | 2418 | if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) { |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2419 | return NGX_CONF_ERROR; |
| 2420 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2421 | } |
| 2422 | } |
| 2423 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 2424 | clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2425 | clcf->loc_conf = ctx->loc_conf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2426 | |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 2427 | value = cf->args->elts; |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2428 | |
| 2429 | if (cf->args->nelts == 3) { |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2430 | |
| 2431 | len = value[1].len; |
| 2432 | mod = value[1].data; |
| 2433 | name = &value[2]; |
| 2434 | |
| 2435 | if (len == 1 && mod[0] == '=') { |
| 2436 | |
| 2437 | clcf->name = *name; |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2438 | clcf->exact_match = 1; |
| 2439 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2440 | } else if (len == 2 && mod[0] == '^' && mod[1] == '~') { |
| 2441 | |
| 2442 | clcf->name = *name; |
Igor Sysoev | d43bee8 | 2004-11-20 19:52:20 +0000 | [diff] [blame] | 2443 | clcf->noregex = 1; |
| 2444 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2445 | } else if (len == 1 && mod[0] == '~') { |
Igor Sysoev | 86ef6aa | 2007-12-10 12:09:51 +0000 | [diff] [blame] | 2446 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2447 | if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) { |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2448 | return NGX_CONF_ERROR; |
| 2449 | } |
| 2450 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2451 | } else if (len == 2 && mod[0] == '~' && mod[1] == '*') { |
| 2452 | |
| 2453 | if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) { |
| 2454 | return NGX_CONF_ERROR; |
| 2455 | } |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2456 | |
| 2457 | } else { |
| 2458 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 2459 | "invalid location modifier \"%V\"", &value[1]); |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2460 | return NGX_CONF_ERROR; |
| 2461 | } |
| 2462 | |
| 2463 | } else { |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2464 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2465 | name = &value[1]; |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2466 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2467 | if (name->data[0] == '=') { |
| 2468 | |
| 2469 | clcf->name.len = name->len - 1; |
| 2470 | clcf->name.data = name->data + 1; |
| 2471 | clcf->exact_match = 1; |
| 2472 | |
| 2473 | } else if (name->data[0] == '^' && name->data[1] == '~') { |
| 2474 | |
| 2475 | clcf->name.len = name->len - 2; |
| 2476 | clcf->name.data = name->data + 2; |
| 2477 | clcf->noregex = 1; |
| 2478 | |
| 2479 | } else if (name->data[0] == '~') { |
| 2480 | |
| 2481 | name->len--; |
| 2482 | name->data++; |
| 2483 | |
| 2484 | if (name->data[0] == '*') { |
| 2485 | |
| 2486 | name->len--; |
| 2487 | name->data++; |
| 2488 | |
| 2489 | if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) { |
| 2490 | return NGX_CONF_ERROR; |
| 2491 | } |
| 2492 | |
| 2493 | } else { |
| 2494 | if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) { |
| 2495 | return NGX_CONF_ERROR; |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | } else { |
| 2500 | |
| 2501 | clcf->name = *name; |
| 2502 | |
| 2503 | if (name->data[0] == '@') { |
| 2504 | clcf->named = 1; |
| 2505 | } |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2506 | } |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2509 | pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; |
| 2510 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 2511 | if (pclcf->name.len) { |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2512 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 2513 | /* nested location */ |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2514 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2515 | #if 0 |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2516 | clcf->prev_location = pclcf; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2517 | #endif |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2518 | |
| 2519 | if (pclcf->exact_match) { |
| 2520 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 2521 | "location \"%V\" could not be inside " |
| 2522 | "the exact location \"%V\"", |
| 2523 | &clcf->name, &pclcf->name); |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2524 | return NGX_CONF_ERROR; |
| 2525 | } |
| 2526 | |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 2527 | if (pclcf->named) { |
| 2528 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 2529 | "location \"%V\" could not be inside " |
| 2530 | "the named location \"%V\"", |
| 2531 | &clcf->name, &pclcf->name); |
| 2532 | return NGX_CONF_ERROR; |
| 2533 | } |
| 2534 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 2535 | if (clcf->named) { |
| 2536 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 2537 | "named location \"%V\" must be " |
| 2538 | "on server level only", |
| 2539 | &clcf->name); |
| 2540 | return NGX_CONF_ERROR; |
| 2541 | } |
| 2542 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2543 | len = pclcf->name.len; |
| 2544 | |
Igor Sysoev | c0edbcc | 2004-10-21 15:34:38 +0000 | [diff] [blame] | 2545 | #if (NGX_PCRE) |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2546 | if (clcf->regex == NULL |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2547 | && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0) |
Igor Sysoev | ea52123 | 2004-07-26 16:21:18 +0000 | [diff] [blame] | 2548 | #else |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2549 | if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0) |
Igor Sysoev | ea52123 | 2004-07-26 16:21:18 +0000 | [diff] [blame] | 2550 | #endif |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2551 | { |
| 2552 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 2553 | "location \"%V\" is outside location \"%V\"", |
| 2554 | &clcf->name, &pclcf->name); |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2555 | return NGX_CONF_ERROR; |
| 2556 | } |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 2557 | } |
Igor Sysoev | 74a5ddb | 2004-07-18 19:11:20 +0000 | [diff] [blame] | 2558 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 2559 | if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) { |
| 2560 | return NGX_CONF_ERROR; |
| 2561 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2562 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2563 | save = *cf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2564 | cf->ctx = ctx; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2565 | cf->cmd_type = NGX_HTTP_LOC_CONF; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2566 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2567 | rv = ngx_conf_parse(cf, NULL); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2568 | |
| 2569 | *cf = save; |
| 2570 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2571 | return rv; |
| 2572 | } |
| 2573 | |
| 2574 | |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2575 | static ngx_int_t |
| 2576 | ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf, |
| 2577 | ngx_str_t *regex, ngx_uint_t caseless) |
| 2578 | { |
| 2579 | #if (NGX_PCRE) |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 2580 | ngx_regex_compile_t rc; |
| 2581 | u_char errstr[NGX_MAX_CONF_ERRSTR]; |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2582 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 2583 | ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
| 2584 | |
| 2585 | rc.pattern = *regex; |
| 2586 | rc.err.len = NGX_MAX_CONF_ERRSTR; |
| 2587 | rc.err.data = errstr; |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2588 | |
Igor Sysoev | 2642bf1 | 2009-07-14 08:53:37 +0000 | [diff] [blame] | 2589 | #if (NGX_HAVE_CASELESS_FILESYSTEM) |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 2590 | rc.options = NGX_REGEX_CASELESS; |
Igor Sysoev | 733fb74 | 2009-12-17 14:25:46 +0000 | [diff] [blame] | 2591 | #else |
| 2592 | rc.options = caseless; |
Igor Sysoev | 2642bf1 | 2009-07-14 08:53:37 +0000 | [diff] [blame] | 2593 | #endif |
| 2594 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 2595 | clcf->regex = ngx_http_regex_compile(cf, &rc); |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2596 | if (clcf->regex == NULL) { |
Igor Sysoev | 22f6d86 | 2008-12-11 10:21:08 +0000 | [diff] [blame] | 2597 | return NGX_ERROR; |
| 2598 | } |
| 2599 | |
| 2600 | clcf->name = *regex; |
| 2601 | |
| 2602 | return NGX_OK; |
| 2603 | |
| 2604 | #else |
| 2605 | |
| 2606 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 2607 | "the using of the regex \"%V\" requires PCRE library", |
| 2608 | regex); |
| 2609 | return NGX_ERROR; |
| 2610 | |
| 2611 | #endif |
| 2612 | } |
| 2613 | |
| 2614 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2615 | static char * |
| 2616 | ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2617 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2618 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 7bdb720 | 2006-04-19 15:30:56 +0000 | [diff] [blame] | 2619 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 2620 | char *rv; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2621 | ngx_conf_t save; |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 2622 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2623 | if (clcf->types == NULL) { |
| 2624 | clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t)); |
| 2625 | if (clcf->types == NULL) { |
Igor Sysoev | 7bdb720 | 2006-04-19 15:30:56 +0000 | [diff] [blame] | 2626 | return NGX_CONF_ERROR; |
| 2627 | } |
| 2628 | } |
| 2629 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2630 | save = *cf; |
| 2631 | cf->handler = ngx_http_core_type; |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 2632 | cf->handler_conf = conf; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2633 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 2634 | rv = ngx_conf_parse(cf, NULL); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2635 | |
| 2636 | *cf = save; |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 2637 | |
| 2638 | return rv; |
| 2639 | } |
| 2640 | |
| 2641 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2642 | static char * |
| 2643 | ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 2644 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2645 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2646 | |
Igor Sysoev | eba03e6 | 2007-03-29 10:27:24 +0000 | [diff] [blame] | 2647 | ngx_str_t *value, *content_type, *old, file; |
Igor Sysoev | 6a07833 | 2008-08-04 10:18:36 +0000 | [diff] [blame] | 2648 | ngx_uint_t i, n, hash; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2649 | ngx_hash_key_t *type; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2650 | |
Igor Sysoev | eba03e6 | 2007-03-29 10:27:24 +0000 | [diff] [blame] | 2651 | value = cf->args->elts; |
| 2652 | |
| 2653 | if (ngx_strcmp(value[0].data, "include") == 0) { |
| 2654 | file = value[1]; |
| 2655 | |
Igor Sysoev | 1f4220e | 2009-02-24 10:42:23 +0000 | [diff] [blame] | 2656 | if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) { |
Igor Sysoev | eba03e6 | 2007-03-29 10:27:24 +0000 | [diff] [blame] | 2657 | return NGX_CONF_ERROR; |
| 2658 | } |
| 2659 | |
| 2660 | ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data); |
| 2661 | |
| 2662 | return ngx_conf_parse(cf, &file); |
| 2663 | } |
| 2664 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2665 | content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t)); |
| 2666 | if (content_type == NULL) { |
| 2667 | return NGX_CONF_ERROR; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2670 | *content_type = value[0]; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2671 | |
| 2672 | for (i = 1; i < cf->args->nelts; i++) { |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2673 | |
Igor Sysoev | 6a07833 | 2008-08-04 10:18:36 +0000 | [diff] [blame] | 2674 | hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2675 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2676 | type = clcf->types->elts; |
| 2677 | for (n = 0; n < clcf->types->nelts; n++) { |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2678 | if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { |
| 2679 | old = type[n].value; |
| 2680 | type[n].value = content_type; |
| 2681 | |
| 2682 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 2683 | "duplicate extention \"%V\", " |
| 2684 | "content type: \"%V\", " |
| 2685 | "old content type: \"%V\"", |
| 2686 | &value[i], content_type, old); |
| 2687 | continue; |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2692 | type = ngx_array_push(clcf->types); |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2693 | if (type == NULL) { |
Igor Sysoev | dc3b2a7 | 2004-09-14 19:39:54 +0000 | [diff] [blame] | 2694 | return NGX_CONF_ERROR; |
| 2695 | } |
| 2696 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2697 | type->key = value[i]; |
Igor Sysoev | 6a07833 | 2008-08-04 10:18:36 +0000 | [diff] [blame] | 2698 | type->key_hash = hash; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2699 | type->value = content_type; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | return NGX_CONF_OK; |
| 2703 | } |
| 2704 | |
| 2705 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 2706 | static ngx_int_t |
| 2707 | ngx_http_core_preconfiguration(ngx_conf_t *cf) |
| 2708 | { |
| 2709 | return ngx_http_variables_add_core_vars(cf); |
| 2710 | } |
| 2711 | |
| 2712 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2713 | static void * |
| 2714 | ngx_http_core_create_main_conf(ngx_conf_t *cf) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2715 | { |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2716 | ngx_http_core_main_conf_t *cmcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2717 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2718 | cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t)); |
| 2719 | if (cmcf == NULL) { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 2720 | return NULL; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2721 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2722 | |
Igor Sysoev | 8184d1b | 2005-03-04 14:06:57 +0000 | [diff] [blame] | 2723 | if (ngx_array_init(&cmcf->servers, cf->pool, 4, |
Igor Sysoev | 9ac946b | 2005-10-24 15:09:41 +0000 | [diff] [blame] | 2724 | sizeof(ngx_http_core_srv_conf_t *)) |
Igor Sysoev | 6f134cc | 2006-05-23 14:54:58 +0000 | [diff] [blame] | 2725 | != NGX_OK) |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2726 | { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 2727 | return NULL; |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 2728 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2729 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 2730 | cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT; |
| 2731 | cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT; |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 2732 | |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 2733 | cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT; |
| 2734 | cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT; |
| 2735 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2736 | return cmcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2740 | static char * |
| 2741 | ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2742 | { |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 2743 | ngx_http_core_main_conf_t *cmcf = conf; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2744 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 2745 | if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) { |
| 2746 | cmcf->server_names_hash_max_size = 512; |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 2749 | if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) { |
| 2750 | cmcf->server_names_hash_bucket_size = ngx_cacheline_size; |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 2751 | } |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2752 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 2753 | cmcf->server_names_hash_bucket_size = |
| 2754 | ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size); |
| 2755 | |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 2756 | |
| 2757 | if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) { |
| 2758 | cmcf->variables_hash_max_size = 512; |
| 2759 | } |
| 2760 | |
| 2761 | if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) { |
| 2762 | cmcf->variables_hash_bucket_size = 64; |
| 2763 | } |
| 2764 | |
| 2765 | cmcf->variables_hash_bucket_size = |
| 2766 | ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size); |
| 2767 | |
Igor Sysoev | 42f5fb1 | 2009-11-16 19:11:38 +0000 | [diff] [blame] | 2768 | if (cmcf->ncaptures) { |
| 2769 | cmcf->ncaptures = (cmcf->ncaptures + 1) * 3; |
| 2770 | } |
| 2771 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2772 | return NGX_CONF_OK; |
| 2773 | } |
| 2774 | |
| 2775 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2776 | static void * |
| 2777 | ngx_http_core_create_srv_conf(ngx_conf_t *cf) |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2778 | { |
| 2779 | ngx_http_core_srv_conf_t *cscf; |
| 2780 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 2781 | cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)); |
| 2782 | if (cscf == NULL) { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 2783 | return NULL; |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 2786 | /* |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 2787 | * set by ngx_pcalloc(): |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2788 | * |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 2789 | * conf->client_large_buffers.num = 0; |
| 2790 | */ |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 2791 | |
Igor Sysoev | da173ab | 2006-08-30 10:39:17 +0000 | [diff] [blame] | 2792 | if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4, |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 2793 | sizeof(ngx_http_server_name_t)) |
Igor Sysoev | 1f4220e | 2009-02-24 10:42:23 +0000 | [diff] [blame] | 2794 | != NGX_OK) |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2795 | { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 2796 | return NULL; |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2797 | } |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2798 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 2799 | cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 2800 | cscf->request_pool_size = NGX_CONF_UNSET_SIZE; |
| 2801 | cscf->client_header_timeout = NGX_CONF_UNSET_MSEC; |
| 2802 | cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE; |
Igor Sysoev | 3362b8d | 2005-05-14 18:42:03 +0000 | [diff] [blame] | 2803 | cscf->ignore_invalid_headers = NGX_CONF_UNSET; |
Igor Sysoev | 8decab3 | 2007-10-18 11:36:58 +0000 | [diff] [blame] | 2804 | cscf->merge_slashes = NGX_CONF_UNSET; |
Igor Sysoev | 753792e | 2008-09-24 14:02:50 +0000 | [diff] [blame] | 2805 | cscf->underscores_in_headers = NGX_CONF_UNSET; |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 2806 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2807 | return cscf; |
| 2808 | } |
| 2809 | |
| 2810 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2811 | static char * |
| 2812 | ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2813 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 2814 | ngx_http_core_srv_conf_t *prev = parent; |
| 2815 | ngx_http_core_srv_conf_t *conf = child; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2816 | |
Igor Sysoev | a35eacc | 2009-02-21 07:02:02 +0000 | [diff] [blame] | 2817 | struct sockaddr_in *sin; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 2818 | ngx_http_listen_opt_t lsopt; |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 2819 | ngx_http_server_name_t *sn; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2820 | |
Igor Sysoev | 7578ec9 | 2003-06-02 15:24:30 +0000 | [diff] [blame] | 2821 | /* TODO: it does not merge, it inits only */ |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 2822 | |
Igor Sysoev | 44fa887 | 2009-10-29 15:53:50 +0000 | [diff] [blame] | 2823 | ngx_conf_merge_size_value(conf->connection_pool_size, |
| 2824 | prev->connection_pool_size, 256); |
| 2825 | ngx_conf_merge_size_value(conf->request_pool_size, |
| 2826 | prev->request_pool_size, 4096); |
| 2827 | ngx_conf_merge_msec_value(conf->client_header_timeout, |
| 2828 | prev->client_header_timeout, 60000); |
| 2829 | ngx_conf_merge_size_value(conf->client_header_buffer_size, |
| 2830 | prev->client_header_buffer_size, 1024); |
| 2831 | ngx_conf_merge_bufs_value(conf->large_client_header_buffers, |
| 2832 | prev->large_client_header_buffers, |
Igor Sysoev | 29b5a13 | 2009-12-09 06:37:41 +0000 | [diff] [blame] | 2833 | 4, 8192); |
Igor Sysoev | 44fa887 | 2009-10-29 15:53:50 +0000 | [diff] [blame] | 2834 | |
| 2835 | if (conf->large_client_header_buffers.size < conf->connection_pool_size) { |
| 2836 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 2837 | "the \"large_client_header_buffers\" size must be " |
| 2838 | "equal to or bigger than \"connection_pool_size\""); |
| 2839 | return NGX_CONF_ERROR; |
| 2840 | } |
| 2841 | |
| 2842 | ngx_conf_merge_value(conf->ignore_invalid_headers, |
| 2843 | prev->ignore_invalid_headers, 1); |
| 2844 | |
| 2845 | ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); |
| 2846 | |
| 2847 | ngx_conf_merge_value(conf->underscores_in_headers, |
| 2848 | prev->underscores_in_headers, 0); |
| 2849 | |
Igor Sysoev | 79d630a | 2009-10-21 08:19:46 +0000 | [diff] [blame] | 2850 | if (!conf->listen) { |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 2851 | ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2852 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 2853 | sin = (struct sockaddr_in *) &lsopt.sockaddr; |
Igor Sysoev | a35eacc | 2009-02-21 07:02:02 +0000 | [diff] [blame] | 2854 | |
| 2855 | sin->sin_family = AF_INET; |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 2856 | #if (NGX_WIN32) |
Igor Sysoev | a35eacc | 2009-02-21 07:02:02 +0000 | [diff] [blame] | 2857 | sin->sin_port = htons(80); |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 2858 | #else |
Igor Sysoev | a35eacc | 2009-02-21 07:02:02 +0000 | [diff] [blame] | 2859 | sin->sin_port = htons((getuid() == 0) ? 80 : 8000); |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 2860 | #endif |
Igor Sysoev | a35eacc | 2009-02-21 07:02:02 +0000 | [diff] [blame] | 2861 | sin->sin_addr.s_addr = INADDR_ANY; |
Igor Sysoev | 9ac946b | 2005-10-24 15:09:41 +0000 | [diff] [blame] | 2862 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 2863 | lsopt.socklen = sizeof(struct sockaddr_in); |
Igor Sysoev | e10385e | 2009-02-21 10:23:30 +0000 | [diff] [blame] | 2864 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 2865 | lsopt.backlog = NGX_LISTEN_BACKLOG; |
| 2866 | lsopt.rcvbuf = -1; |
| 2867 | lsopt.sndbuf = -1; |
| 2868 | lsopt.wildcard = 1; |
Igor Sysoev | e10385e | 2009-02-21 10:23:30 +0000 | [diff] [blame] | 2869 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 2870 | (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr, |
Igor Sysoev | e10385e | 2009-02-21 10:23:30 +0000 | [diff] [blame] | 2871 | NGX_SOCKADDR_STRLEN, 1); |
Igor Sysoev | 79d630a | 2009-10-21 08:19:46 +0000 | [diff] [blame] | 2872 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 2873 | if (ngx_http_add_listen(cf, conf, &lsopt) == NGX_OK) { |
Igor Sysoev | 79d630a | 2009-10-21 08:19:46 +0000 | [diff] [blame] | 2874 | return NGX_CONF_OK; |
| 2875 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2876 | } |
| 2877 | |
Igor Sysoev | 9e58019 | 2006-02-01 18:22:15 +0000 | [diff] [blame] | 2878 | if (conf->server_name.data == NULL) { |
Igor Sysoev | 3be5257 | 2008-05-16 14:39:06 +0000 | [diff] [blame] | 2879 | conf->server_name = cf->cycle->hostname; |
Igor Sysoev | 9e58019 | 2006-02-01 18:22:15 +0000 | [diff] [blame] | 2880 | |
| 2881 | sn = ngx_array_push(&conf->server_names); |
| 2882 | if (sn == NULL) { |
| 2883 | return NGX_CONF_ERROR; |
| 2884 | } |
| 2885 | |
Igor Sysoev | 12446d8 | 2007-10-17 13:22:26 +0000 | [diff] [blame] | 2886 | #if (NGX_PCRE) |
| 2887 | sn->regex = NULL; |
| 2888 | #endif |
Igor Sysoev | cd8b43c | 2009-10-21 16:52:10 +0000 | [diff] [blame] | 2889 | sn->server = conf; |
Igor Sysoev | 9e58019 | 2006-02-01 18:22:15 +0000 | [diff] [blame] | 2890 | sn->name.len = conf->server_name.len; |
| 2891 | sn->name.data = conf->server_name.data; |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2894 | return NGX_CONF_OK; |
| 2895 | } |
| 2896 | |
| 2897 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2898 | static void * |
| 2899 | ngx_http_core_create_loc_conf(ngx_conf_t *cf) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2900 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2901 | ngx_http_core_loc_conf_t *clcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2902 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2903 | clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)); |
| 2904 | if (clcf == NULL) { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 2905 | return NULL; |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2906 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2907 | |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 2908 | /* |
| 2909 | * set by ngx_pcalloc(): |
| 2910 | * |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2911 | * clcf->root = { 0, NULL }; |
| 2912 | * clcf->limit_except = 0; |
| 2913 | * clcf->post_action = { 0, NULL }; |
| 2914 | * clcf->types = NULL; |
| 2915 | * clcf->default_type = { 0, NULL }; |
| 2916 | * clcf->error_log = NULL; |
| 2917 | * clcf->error_pages = NULL; |
| 2918 | * clcf->try_files = NULL; |
| 2919 | * clcf->client_body_path = NULL; |
| 2920 | * clcf->regex = NULL; |
| 2921 | * clcf->exact_match = 0; |
| 2922 | * clcf->auto_redirect = 0; |
| 2923 | * clcf->alias = 0; |
| 2924 | * clcf->gzip_proxied = 0; |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 2925 | */ |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2926 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2927 | clcf->client_max_body_size = NGX_CONF_UNSET; |
| 2928 | clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; |
| 2929 | clcf->client_body_timeout = NGX_CONF_UNSET_MSEC; |
| 2930 | clcf->satisfy = NGX_CONF_UNSET_UINT; |
| 2931 | clcf->if_modified_since = NGX_CONF_UNSET_UINT; |
| 2932 | clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT; |
| 2933 | clcf->client_body_in_single_buffer = NGX_CONF_UNSET; |
| 2934 | clcf->internal = NGX_CONF_UNSET; |
| 2935 | clcf->sendfile = NGX_CONF_UNSET; |
| 2936 | clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE; |
Igor Sysoev | a962506 | 2009-08-28 08:12:35 +0000 | [diff] [blame] | 2937 | #if (NGX_HAVE_FILE_AIO) |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2938 | clcf->aio = NGX_CONF_UNSET; |
Igor Sysoev | a962506 | 2009-08-28 08:12:35 +0000 | [diff] [blame] | 2939 | #endif |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2940 | clcf->read_ahead = NGX_CONF_UNSET_SIZE; |
| 2941 | clcf->directio = NGX_CONF_UNSET; |
| 2942 | clcf->directio_alignment = NGX_CONF_UNSET; |
| 2943 | clcf->tcp_nopush = NGX_CONF_UNSET; |
| 2944 | clcf->tcp_nodelay = NGX_CONF_UNSET; |
| 2945 | clcf->send_timeout = NGX_CONF_UNSET_MSEC; |
| 2946 | clcf->send_lowat = NGX_CONF_UNSET_SIZE; |
| 2947 | clcf->postpone_output = NGX_CONF_UNSET_SIZE; |
| 2948 | clcf->limit_rate = NGX_CONF_UNSET_SIZE; |
| 2949 | clcf->limit_rate_after = NGX_CONF_UNSET_SIZE; |
| 2950 | clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; |
| 2951 | clcf->keepalive_header = NGX_CONF_UNSET; |
| 2952 | clcf->keepalive_requests = NGX_CONF_UNSET_UINT; |
| 2953 | clcf->lingering_time = NGX_CONF_UNSET_MSEC; |
| 2954 | clcf->lingering_timeout = NGX_CONF_UNSET_MSEC; |
| 2955 | clcf->resolver_timeout = NGX_CONF_UNSET_MSEC; |
| 2956 | clcf->reset_timedout_connection = NGX_CONF_UNSET; |
| 2957 | clcf->server_name_in_redirect = NGX_CONF_UNSET; |
| 2958 | clcf->port_in_redirect = NGX_CONF_UNSET; |
| 2959 | clcf->msie_padding = NGX_CONF_UNSET; |
| 2960 | clcf->msie_refresh = NGX_CONF_UNSET; |
| 2961 | clcf->log_not_found = NGX_CONF_UNSET; |
| 2962 | clcf->log_subrequest = NGX_CONF_UNSET; |
| 2963 | clcf->recursive_error_pages = NGX_CONF_UNSET; |
| 2964 | clcf->server_tokens = NGX_CONF_UNSET; |
| 2965 | clcf->types_hash_max_size = NGX_CONF_UNSET_UINT; |
| 2966 | clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 2967 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2968 | clcf->open_file_cache = NGX_CONF_UNSET_PTR; |
| 2969 | clcf->open_file_cache_valid = NGX_CONF_UNSET; |
| 2970 | clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT; |
| 2971 | clcf->open_file_cache_errors = NGX_CONF_UNSET; |
| 2972 | clcf->open_file_cache_events = NGX_CONF_UNSET; |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 2973 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 2974 | #if (NGX_HTTP_GZIP) |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2975 | clcf->gzip_vary = NGX_CONF_UNSET; |
| 2976 | clcf->gzip_http_version = NGX_CONF_UNSET_UINT; |
Igor Sysoev | 8eac726 | 2007-12-28 13:15:11 +0000 | [diff] [blame] | 2977 | #if (NGX_PCRE) |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2978 | clcf->gzip_disable = NGX_CONF_UNSET_PTR; |
| 2979 | clcf->gzip_disable_msie6 = 3; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 2980 | #endif |
Igor Sysoev | 8eac726 | 2007-12-28 13:15:11 +0000 | [diff] [blame] | 2981 | #endif |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 2982 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 2983 | return clcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 2984 | } |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 2985 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2986 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 2987 | static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html"); |
| 2988 | static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif"); |
| 2989 | static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg"); |
| 2990 | |
| 2991 | static ngx_hash_key_t ngx_http_core_default_types[] = { |
| 2992 | { ngx_string("html"), 0, &ngx_http_core_text_html_type }, |
| 2993 | { ngx_string("gif"), 0, &ngx_http_core_image_gif_type }, |
| 2994 | { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type }, |
| 2995 | { ngx_null_string, 0, NULL } |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 2996 | }; |
| 2997 | |
| 2998 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 2999 | static char * |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3000 | ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 3001 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 3002 | ngx_http_core_loc_conf_t *prev = parent; |
| 3003 | ngx_http_core_loc_conf_t *conf = child; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3004 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3005 | ngx_uint_t i; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3006 | ngx_hash_key_t *type; |
| 3007 | ngx_hash_init_t types_hash; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3008 | |
Igor Sysoev | 3430346 | 2006-01-24 16:08:27 +0000 | [diff] [blame] | 3009 | if (conf->root.data == NULL) { |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3010 | |
Igor Sysoev | 455a7fc | 2006-03-21 08:20:41 +0000 | [diff] [blame] | 3011 | conf->alias = prev->alias; |
Igor Sysoev | 3430346 | 2006-01-24 16:08:27 +0000 | [diff] [blame] | 3012 | conf->root = prev->root; |
| 3013 | conf->root_lengths = prev->root_lengths; |
| 3014 | conf->root_values = prev->root_values; |
| 3015 | |
| 3016 | if (prev->root.data == NULL) { |
| 3017 | conf->root.len = sizeof("html") - 1; |
| 3018 | conf->root.data = (u_char *) "html"; |
| 3019 | |
Igor Sysoev | 1f4220e | 2009-02-24 10:42:23 +0000 | [diff] [blame] | 3020 | if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) { |
Igor Sysoev | 3430346 | 2006-01-24 16:08:27 +0000 | [diff] [blame] | 3021 | return NGX_CONF_ERROR; |
| 3022 | } |
| 3023 | } |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 3026 | if (conf->post_action.data == NULL) { |
| 3027 | conf->post_action = prev->post_action; |
| 3028 | } |
| 3029 | |
Igor Sysoev | 1765f47 | 2006-07-07 16:33:19 +0000 | [diff] [blame] | 3030 | ngx_conf_merge_uint_value(conf->types_hash_max_size, |
| 3031 | prev->types_hash_max_size, 1024); |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3032 | |
Igor Sysoev | 1765f47 | 2006-07-07 16:33:19 +0000 | [diff] [blame] | 3033 | ngx_conf_merge_uint_value(conf->types_hash_bucket_size, |
| 3034 | prev->types_hash_bucket_size, |
| 3035 | ngx_cacheline_size); |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3036 | |
| 3037 | conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size, |
| 3038 | ngx_cacheline_size); |
| 3039 | |
| 3040 | /* |
| 3041 | * the special handling the "types" directive in the "http" section |
| 3042 | * to inherit the http's conf->types_hash to all servers |
| 3043 | */ |
| 3044 | |
| 3045 | if (prev->types && prev->types_hash.buckets == NULL) { |
| 3046 | |
| 3047 | types_hash.hash = &prev->types_hash; |
| 3048 | types_hash.key = ngx_hash_key_lc; |
| 3049 | types_hash.max_size = conf->types_hash_max_size; |
| 3050 | types_hash.bucket_size = conf->types_hash_bucket_size; |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 3051 | types_hash.name = "types_hash"; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3052 | types_hash.pool = cf->pool; |
| 3053 | types_hash.temp_pool = NULL; |
| 3054 | |
| 3055 | if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts) |
| 3056 | != NGX_OK) |
| 3057 | { |
| 3058 | return NGX_CONF_ERROR; |
| 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | if (conf->types == NULL) { |
| 3063 | conf->types = prev->types; |
| 3064 | conf->types_hash = prev->types_hash; |
| 3065 | } |
| 3066 | |
| 3067 | if (conf->types == NULL) { |
| 3068 | conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t)); |
| 3069 | if (conf->types == NULL) { |
| 3070 | return NGX_CONF_ERROR; |
| 3071 | } |
| 3072 | |
| 3073 | for (i = 0; ngx_http_core_default_types[i].key.len; i++) { |
| 3074 | type = ngx_array_push(conf->types); |
| 3075 | if (type == NULL) { |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3076 | return NGX_CONF_ERROR; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3079 | type->key = ngx_http_core_default_types[i].key; |
| 3080 | type->key_hash = |
| 3081 | ngx_hash_key_lc(ngx_http_core_default_types[i].key.data, |
| 3082 | ngx_http_core_default_types[i].key.len); |
| 3083 | type->value = ngx_http_core_default_types[i].value; |
| 3084 | } |
| 3085 | } |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3086 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3087 | if (conf->types_hash.buckets == NULL) { |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3088 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3089 | types_hash.hash = &conf->types_hash; |
| 3090 | types_hash.key = ngx_hash_key_lc; |
| 3091 | types_hash.max_size = conf->types_hash_max_size; |
| 3092 | types_hash.bucket_size = conf->types_hash_bucket_size; |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 3093 | types_hash.name = "mime_types_hash"; |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3094 | types_hash.pool = cf->pool; |
| 3095 | types_hash.temp_pool = NULL; |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3096 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3097 | if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts) |
| 3098 | != NGX_OK) |
| 3099 | { |
| 3100 | return NGX_CONF_ERROR; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3101 | } |
| 3102 | } |
| 3103 | |
Igor Sysoev | 0cd76ea | 2009-04-30 13:53:42 +0000 | [diff] [blame] | 3104 | if (conf->error_log == NULL) { |
| 3105 | if (prev->error_log) { |
| 3106 | conf->error_log = prev->error_log; |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 3107 | } else { |
Igor Sysoev | 0cd76ea | 2009-04-30 13:53:42 +0000 | [diff] [blame] | 3108 | conf->error_log = &cf->cycle->new_log; |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3112 | if (conf->error_pages == NULL && prev->error_pages) { |
| 3113 | conf->error_pages = prev->error_pages; |
| 3114 | } |
| 3115 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 3116 | ngx_conf_merge_str_value(conf->default_type, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3117 | prev->default_type, "text/plain"); |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 3118 | |
Igor Sysoev | 1765f47 | 2006-07-07 16:33:19 +0000 | [diff] [blame] | 3119 | ngx_conf_merge_off_value(conf->client_max_body_size, |
Igor Sysoev | 8035fd2 | 2004-10-01 15:53:53 +0000 | [diff] [blame] | 3120 | prev->client_max_body_size, 1 * 1024 * 1024); |
Igor Sysoev | dbb2776 | 2004-04-01 16:20:53 +0000 | [diff] [blame] | 3121 | ngx_conf_merge_size_value(conf->client_body_buffer_size, |
Igor Sysoev | 8035fd2 | 2004-10-01 15:53:53 +0000 | [diff] [blame] | 3122 | prev->client_body_buffer_size, |
| 3123 | (size_t) 2 * ngx_pagesize); |
Igor Sysoev | 2b0c76c | 2003-10-27 21:01:00 +0000 | [diff] [blame] | 3124 | ngx_conf_merge_msec_value(conf->client_body_timeout, |
Igor Sysoev | 7af6b16 | 2004-02-09 07:46:43 +0000 | [diff] [blame] | 3125 | prev->client_body_timeout, 60000); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 3126 | |
Igor Sysoev | 2d028f8 | 2007-12-29 16:38:23 +0000 | [diff] [blame] | 3127 | ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy, |
| 3128 | NGX_HTTP_SATISFY_ALL); |
Igor Sysoev | 863325f | 2008-12-01 14:22:51 +0000 | [diff] [blame] | 3129 | ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since, |
Igor Sysoev | 2c33648 | 2009-02-10 15:05:05 +0000 | [diff] [blame] | 3130 | NGX_HTTP_IMS_EXACT); |
Igor Sysoev | 7d9e334 | 2009-05-14 11:31:50 +0000 | [diff] [blame] | 3131 | ngx_conf_merge_uint_value(conf->client_body_in_file_only, |
Igor Sysoev | 8a2b2fb | 2006-04-14 09:53:38 +0000 | [diff] [blame] | 3132 | prev->client_body_in_file_only, 0); |
Igor Sysoev | bfbded7 | 2009-05-14 11:41:33 +0000 | [diff] [blame] | 3133 | ngx_conf_merge_value(conf->client_body_in_single_buffer, |
| 3134 | prev->client_body_in_single_buffer, 0); |
Igor Sysoev | 7d9e334 | 2009-05-14 11:31:50 +0000 | [diff] [blame] | 3135 | ngx_conf_merge_value(conf->internal, prev->internal, 0); |
Igor Sysoev | 5bf3d25 | 2003-10-22 07:05:29 +0000 | [diff] [blame] | 3136 | ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0); |
Igor Sysoev | c9b57dc | 2007-05-07 06:33:39 +0000 | [diff] [blame] | 3137 | ngx_conf_merge_size_value(conf->sendfile_max_chunk, |
| 3138 | prev->sendfile_max_chunk, 0); |
Igor Sysoev | a962506 | 2009-08-28 08:12:35 +0000 | [diff] [blame] | 3139 | #if (NGX_HAVE_FILE_AIO) |
| 3140 | ngx_conf_merge_value(conf->aio, prev->aio, 0); |
| 3141 | #endif |
Igor Sysoev | 3266171 | 2009-09-30 13:21:52 +0000 | [diff] [blame] | 3142 | ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0); |
Igor Sysoev | 385af28 | 2008-07-30 12:34:04 +0000 | [diff] [blame] | 3143 | ngx_conf_merge_off_value(conf->directio, prev->directio, |
| 3144 | NGX_MAX_OFF_T_VALUE); |
Igor Sysoev | 6fb506a | 2009-08-28 08:15:55 +0000 | [diff] [blame] | 3145 | ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment, |
| 3146 | 512); |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 3147 | ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); |
Igor Sysoev | 3f8dc59 | 2006-08-28 16:57:48 +0000 | [diff] [blame] | 3148 | ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 3149 | |
Igor Sysoev | 7af6b16 | 2004-02-09 07:46:43 +0000 | [diff] [blame] | 3150 | ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000); |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 3151 | ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0); |
Igor Sysoev | 7823cc3 | 2004-07-14 16:01:42 +0000 | [diff] [blame] | 3152 | ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output, |
| 3153 | 1460); |
| 3154 | ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0); |
Igor Sysoev | 80027fc | 2009-06-02 14:01:50 +0000 | [diff] [blame] | 3155 | ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after, |
| 3156 | 0); |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 3157 | ngx_conf_merge_msec_value(conf->keepalive_timeout, |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 3158 | prev->keepalive_timeout, 75000); |
| 3159 | ngx_conf_merge_sec_value(conf->keepalive_header, |
| 3160 | prev->keepalive_header, 0); |
Igor Sysoev | e959128 | 2009-05-25 15:38:36 +0000 | [diff] [blame] | 3161 | ngx_conf_merge_uint_value(conf->keepalive_requests, |
| 3162 | prev->keepalive_requests, 100); |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 3163 | ngx_conf_merge_msec_value(conf->lingering_time, |
| 3164 | prev->lingering_time, 30000); |
| 3165 | ngx_conf_merge_msec_value(conf->lingering_timeout, |
| 3166 | prev->lingering_timeout, 5000); |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 3167 | ngx_conf_merge_msec_value(conf->resolver_timeout, |
| 3168 | prev->resolver_timeout, 30000); |
| 3169 | |
| 3170 | if (conf->resolver == NULL) { |
Igor Sysoev | 6b2fce4 | 2007-12-03 10:05:19 +0000 | [diff] [blame] | 3171 | |
Igor Sysoev | f39876c | 2008-03-06 08:48:55 +0000 | [diff] [blame] | 3172 | if (prev->resolver == NULL) { |
| 3173 | |
| 3174 | /* |
| 3175 | * create dummy resolver in http {} context |
| 3176 | * to inherit it in all servers |
| 3177 | */ |
| 3178 | |
| 3179 | prev->resolver = ngx_resolver_create(cf, NULL); |
| 3180 | if (prev->resolver == NULL) { |
Igor Sysoev | d2d673a | 2008-02-07 08:57:07 +0000 | [diff] [blame] | 3181 | return NGX_CONF_ERROR; |
Igor Sysoev | 6b2fce4 | 2007-12-03 10:05:19 +0000 | [diff] [blame] | 3182 | } |
| 3183 | } |
Igor Sysoev | 433608c | 2008-05-14 07:54:52 +0000 | [diff] [blame] | 3184 | |
Igor Sysoev | f39876c | 2008-03-06 08:48:55 +0000 | [diff] [blame] | 3185 | conf->resolver = prev->resolver; |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 3186 | } |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3187 | |
Igor Sysoev | 52859f2 | 2009-03-23 13:14:51 +0000 | [diff] [blame] | 3188 | if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path, |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 3189 | prev->client_body_temp_path, |
Igor Sysoev | 52859f2 | 2009-03-23 13:14:51 +0000 | [diff] [blame] | 3190 | &ngx_http_client_temp_path) |
| 3191 | != NGX_OK) |
| 3192 | { |
| 3193 | return NGX_CONF_ERROR; |
| 3194 | } |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 3195 | |
Igor Sysoev | 0ab91b9 | 2004-06-06 19:49:18 +0000 | [diff] [blame] | 3196 | ngx_conf_merge_value(conf->reset_timedout_connection, |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3197 | prev->reset_timedout_connection, 0); |
Igor Sysoev | 3f24ae2 | 2007-12-29 15:30:39 +0000 | [diff] [blame] | 3198 | ngx_conf_merge_value(conf->server_name_in_redirect, |
| 3199 | prev->server_name_in_redirect, 1); |
Igor Sysoev | 7b190b4 | 2005-06-07 15:56:31 +0000 | [diff] [blame] | 3200 | ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1); |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 3201 | ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1); |
Igor Sysoev | 3f8dc59 | 2006-08-28 16:57:48 +0000 | [diff] [blame] | 3202 | ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0); |
Igor Sysoev | 5192b36 | 2005-07-08 14:34:20 +0000 | [diff] [blame] | 3203 | ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); |
Igor Sysoev | 2eec1e1 | 2008-09-27 15:08:02 +0000 | [diff] [blame] | 3204 | ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0); |
Igor Sysoev | 3f8dc59 | 2006-08-28 16:57:48 +0000 | [diff] [blame] | 3205 | ngx_conf_merge_value(conf->recursive_error_pages, |
| 3206 | prev->recursive_error_pages, 0); |
Igor Sysoev | 070cf22 | 2007-10-22 10:17:34 +0000 | [diff] [blame] | 3207 | ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1); |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 3208 | |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 3209 | ngx_conf_merge_ptr_value(conf->open_file_cache, |
Igor Sysoev | 513fec7 | 2007-12-27 08:40:14 +0000 | [diff] [blame] | 3210 | prev->open_file_cache, NULL); |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 3211 | |
Igor Sysoev | 9b9616e | 2007-12-21 16:19:48 +0000 | [diff] [blame] | 3212 | ngx_conf_merge_sec_value(conf->open_file_cache_valid, |
Igor Sysoev | 513fec7 | 2007-12-27 08:40:14 +0000 | [diff] [blame] | 3213 | prev->open_file_cache_valid, 60); |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 3214 | |
Igor Sysoev | f3b0e49 | 2007-12-22 13:19:39 +0000 | [diff] [blame] | 3215 | ngx_conf_merge_uint_value(conf->open_file_cache_min_uses, |
Igor Sysoev | 513fec7 | 2007-12-27 08:40:14 +0000 | [diff] [blame] | 3216 | prev->open_file_cache_min_uses, 1); |
Igor Sysoev | f3b0e49 | 2007-12-22 13:19:39 +0000 | [diff] [blame] | 3217 | |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 3218 | ngx_conf_merge_sec_value(conf->open_file_cache_errors, |
Igor Sysoev | 513fec7 | 2007-12-27 08:40:14 +0000 | [diff] [blame] | 3219 | prev->open_file_cache_errors, 0); |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 3220 | |
Igor Sysoev | 9afd58f | 2007-09-03 08:41:42 +0000 | [diff] [blame] | 3221 | ngx_conf_merge_sec_value(conf->open_file_cache_events, |
Igor Sysoev | 513fec7 | 2007-12-27 08:40:14 +0000 | [diff] [blame] | 3222 | prev->open_file_cache_events, 0); |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 3223 | #if (NGX_HTTP_GZIP) |
| 3224 | |
| 3225 | ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0); |
| 3226 | ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version, |
| 3227 | NGX_HTTP_VERSION_11); |
| 3228 | ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied, |
| 3229 | (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF)); |
| 3230 | |
Igor Sysoev | 8eac726 | 2007-12-28 13:15:11 +0000 | [diff] [blame] | 3231 | #if (NGX_PCRE) |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 3232 | ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL); |
Igor Sysoev | 8eac726 | 2007-12-28 13:15:11 +0000 | [diff] [blame] | 3233 | #endif |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 3234 | |
Igor Sysoev | 54477e4 | 2008-08-26 15:09:28 +0000 | [diff] [blame] | 3235 | if (conf->gzip_disable_msie6 == 3) { |
| 3236 | conf->gzip_disable_msie6 = |
| 3237 | (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6; |
| 3238 | } |
| 3239 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 3240 | #endif |
Igor Sysoev | 9afd58f | 2007-09-03 08:41:42 +0000 | [diff] [blame] | 3241 | |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 3242 | return NGX_CONF_OK; |
| 3243 | } |
| 3244 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 3245 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3246 | static char * |
| 3247 | ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 3248 | { |
Igor Sysoev | 79d630a | 2009-10-21 08:19:46 +0000 | [diff] [blame] | 3249 | ngx_http_core_srv_conf_t *cscf = conf; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 3250 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3251 | ngx_str_t *value, size; |
| 3252 | ngx_url_t u; |
| 3253 | ngx_uint_t n; |
| 3254 | ngx_http_listen_opt_t lsopt; |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 3255 | |
Igor Sysoev | 79d630a | 2009-10-21 08:19:46 +0000 | [diff] [blame] | 3256 | cscf->listen = 1; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 3257 | |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3258 | value = cf->args->elts; |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 3259 | |
Igor Sysoev | 20bf47b | 2006-10-24 13:06:55 +0000 | [diff] [blame] | 3260 | ngx_memzero(&u, sizeof(ngx_url_t)); |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3261 | |
Igor Sysoev | 20bf47b | 2006-10-24 13:06:55 +0000 | [diff] [blame] | 3262 | u.url = value[1]; |
| 3263 | u.listen = 1; |
Igor Sysoev | bf3aaac | 2006-12-12 16:46:16 +0000 | [diff] [blame] | 3264 | u.default_port = 80; |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3265 | |
Igor Sysoev | 7ed63ee | 2007-10-08 08:55:12 +0000 | [diff] [blame] | 3266 | if (ngx_parse_url(cf->pool, &u) != NGX_OK) { |
Igor Sysoev | 20bf47b | 2006-10-24 13:06:55 +0000 | [diff] [blame] | 3267 | if (u.err) { |
| 3268 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3269 | "%s in \"%V\" of the \"listen\" directive", |
| 3270 | u.err, &u.url); |
| 3271 | } |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3272 | |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 3273 | return NGX_CONF_ERROR; |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3276 | ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 3277 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3278 | ngx_memcpy(lsopt.sockaddr, u.sockaddr, u.socklen); |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 3279 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3280 | lsopt.socklen = u.socklen; |
| 3281 | lsopt.backlog = NGX_LISTEN_BACKLOG; |
| 3282 | lsopt.rcvbuf = -1; |
| 3283 | lsopt.sndbuf = -1; |
| 3284 | lsopt.wildcard = u.wildcard; |
Igor Sysoev | a35eacc | 2009-02-21 07:02:02 +0000 | [diff] [blame] | 3285 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3286 | (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr, |
Igor Sysoev | a35eacc | 2009-02-21 07:02:02 +0000 | [diff] [blame] | 3287 | NGX_SOCKADDR_STRLEN, 1); |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3288 | |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3289 | for (n = 2; n < cf->args->nelts; n++) { |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 3290 | |
Igor Sysoev | 9826961 | 2009-10-21 19:18:50 +0000 | [diff] [blame] | 3291 | if (ngx_strcmp(value[n].data, "default_server") == 0 |
| 3292 | || ngx_strcmp(value[n].data, "default") == 0) |
| 3293 | { |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3294 | lsopt.default_server = 1; |
| 3295 | continue; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3298 | if (ngx_strcmp(value[n].data, "bind") == 0) { |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3299 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3300 | lsopt.bind = 1; |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3301 | continue; |
| 3302 | } |
| 3303 | |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 3304 | if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) { |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3305 | lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8); |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3306 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3307 | lsopt.bind = 1; |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3308 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3309 | if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) { |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3310 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3311 | "invalid backlog \"%V\"", &value[n]); |
| 3312 | return NGX_CONF_ERROR; |
| 3313 | } |
| 3314 | |
| 3315 | continue; |
| 3316 | } |
| 3317 | |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 3318 | if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) { |
| 3319 | size.len = value[n].len - 7; |
| 3320 | size.data = value[n].data + 7; |
| 3321 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3322 | lsopt.rcvbuf = ngx_parse_size(&size); |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3323 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3324 | lsopt.bind = 1; |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 3325 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3326 | if (lsopt.rcvbuf == NGX_ERROR) { |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 3327 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3328 | "invalid rcvbuf \"%V\"", &value[n]); |
| 3329 | return NGX_CONF_ERROR; |
| 3330 | } |
| 3331 | |
| 3332 | continue; |
| 3333 | } |
| 3334 | |
| 3335 | if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) { |
| 3336 | size.len = value[n].len - 7; |
| 3337 | size.data = value[n].data + 7; |
| 3338 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3339 | lsopt.sndbuf = ngx_parse_size(&size); |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3340 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3341 | lsopt.bind = 1; |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 3342 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3343 | if (lsopt.sndbuf == NGX_ERROR) { |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 3344 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3345 | "invalid sndbuf \"%V\"", &value[n]); |
| 3346 | return NGX_CONF_ERROR; |
| 3347 | } |
| 3348 | |
| 3349 | continue; |
| 3350 | } |
| 3351 | |
| 3352 | if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) { |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3353 | #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3354 | lsopt.accept_filter = (char *) &value[n].data[14]; |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3355 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3356 | lsopt.bind = 1; |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3357 | #else |
| 3358 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3359 | "accept filters \"%V\" are not supported " |
| 3360 | "on this platform, ignored", |
| 3361 | &value[n]); |
| 3362 | #endif |
| 3363 | continue; |
| 3364 | } |
| 3365 | |
| 3366 | if (ngx_strcmp(value[n].data, "deferred") == 0) { |
| 3367 | #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3368 | lsopt.deferred_accept = 1; |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3369 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3370 | lsopt.bind = 1; |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3371 | #else |
| 3372 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3373 | "the deferred accept is not supported " |
| 3374 | "on this platform, ignored"); |
| 3375 | #endif |
| 3376 | continue; |
| 3377 | } |
| 3378 | |
Igor Sysoev | 6d94b51 | 2009-03-13 14:20:34 +0000 | [diff] [blame] | 3379 | if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) { |
| 3380 | #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
| 3381 | struct sockaddr *sa; |
| 3382 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3383 | sa = (struct sockaddr *) lsopt.sockaddr; |
Igor Sysoev | 6d94b51 | 2009-03-13 14:20:34 +0000 | [diff] [blame] | 3384 | |
| 3385 | if (sa->sa_family == AF_INET6) { |
| 3386 | |
| 3387 | if (ngx_strcmp(&value[n].data[10], "n") == 0) { |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3388 | lsopt.ipv6only = 1; |
Igor Sysoev | 6d94b51 | 2009-03-13 14:20:34 +0000 | [diff] [blame] | 3389 | |
| 3390 | } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) { |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3391 | lsopt.ipv6only = 2; |
Igor Sysoev | 6d94b51 | 2009-03-13 14:20:34 +0000 | [diff] [blame] | 3392 | |
| 3393 | } else { |
| 3394 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3395 | "invalid ipv6only flags \"%s\"", |
| 3396 | &value[n].data[9]); |
| 3397 | return NGX_CONF_ERROR; |
| 3398 | } |
| 3399 | |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3400 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3401 | lsopt.bind = 1; |
Igor Sysoev | 6d94b51 | 2009-03-13 14:20:34 +0000 | [diff] [blame] | 3402 | |
| 3403 | } else { |
| 3404 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3405 | "ipv6only is not supported " |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3406 | "on addr \"%s\", ignored", lsopt.addr); |
Igor Sysoev | 6d94b51 | 2009-03-13 14:20:34 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | continue; |
| 3410 | #else |
| 3411 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3412 | "bind ipv6only is not supported " |
| 3413 | "on this platform"); |
| 3414 | return NGX_CONF_ERROR; |
| 3415 | #endif |
| 3416 | } |
| 3417 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 3418 | if (ngx_strcmp(value[n].data, "ssl") == 0) { |
| 3419 | #if (NGX_HTTP_SSL) |
Igor Sysoev | 5a95080 | 2009-10-21 19:16:38 +0000 | [diff] [blame] | 3420 | lsopt.set = 1; |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3421 | lsopt.ssl = 1; |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 3422 | continue; |
| 3423 | #else |
| 3424 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3425 | "the \"ssl\" parameter requires " |
| 3426 | "ngx_http_ssl_module"); |
| 3427 | return NGX_CONF_ERROR; |
| 3428 | #endif |
| 3429 | } |
| 3430 | |
Igor Sysoev | b145b06 | 2005-06-15 18:33:41 +0000 | [diff] [blame] | 3431 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3432 | "the invalid \"%V\" parameter", &value[n]); |
| 3433 | return NGX_CONF_ERROR; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 3434 | } |
| 3435 | |
Igor Sysoev | f2694cb | 2009-10-21 16:47:44 +0000 | [diff] [blame] | 3436 | if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) { |
Igor Sysoev | 79d630a | 2009-10-21 08:19:46 +0000 | [diff] [blame] | 3437 | return NGX_CONF_OK; |
| 3438 | } |
| 3439 | |
| 3440 | return NGX_CONF_ERROR; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3444 | static char * |
| 3445 | ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 3446 | { |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3447 | ngx_http_core_srv_conf_t *cscf = conf; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 3448 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3449 | u_char ch; |
| 3450 | ngx_str_t *value, name; |
| 3451 | ngx_uint_t i; |
| 3452 | ngx_http_server_name_t *sn; |
Igor Sysoev | b1af9bb | 2004-06-25 14:42:03 +0000 | [diff] [blame] | 3453 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 3454 | value = cf->args->elts; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 3455 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3456 | ch = value[1].data[0]; |
| 3457 | |
Igor Sysoev | b29426d | 2008-08-21 12:56:10 +0000 | [diff] [blame] | 3458 | if (cscf->server_name.data == NULL) { |
| 3459 | if (value[1].len) { |
| 3460 | name = value[1]; |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3461 | |
Igor Sysoev | b29426d | 2008-08-21 12:56:10 +0000 | [diff] [blame] | 3462 | if (ch == '.') { |
| 3463 | name.len--; |
| 3464 | name.data++; |
| 3465 | } |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3466 | |
Igor Sysoev | b29426d | 2008-08-21 12:56:10 +0000 | [diff] [blame] | 3467 | cscf->server_name.len = name.len; |
| 3468 | cscf->server_name.data = ngx_pstrdup(cf->pool, &name); |
| 3469 | if (cscf->server_name.data == NULL) { |
| 3470 | return NGX_CONF_ERROR; |
| 3471 | } |
| 3472 | |
| 3473 | } else { |
| 3474 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3475 | "the first server name must not be empty"); |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3476 | return NGX_CONF_ERROR; |
| 3477 | } |
| 3478 | } |
| 3479 | |
| 3480 | for (i = 1; i < cf->args->nelts; i++) { |
| 3481 | |
| 3482 | ch = value[i].data[0]; |
| 3483 | |
Igor Sysoev | b29426d | 2008-08-21 12:56:10 +0000 | [diff] [blame] | 3484 | if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.')) |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3485 | || (ch == '.' && value[i].len < 2)) |
| 3486 | { |
| 3487 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3488 | "server name \"%V\" is invalid", &value[i]); |
| 3489 | return NGX_CONF_ERROR; |
| 3490 | } |
| 3491 | |
Igor Sysoev | 7a58860 | 2007-04-02 06:27:30 +0000 | [diff] [blame] | 3492 | if (ngx_strchr(value[i].data, '/')) { |
| 3493 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 3494 | "server name \"%V\" has strange symbols", |
| 3495 | &value[i]); |
| 3496 | } |
| 3497 | |
Igor Sysoev | c24de1e | 2007-12-29 19:05:21 +0000 | [diff] [blame] | 3498 | if (value[i].len == 1 && ch == '*') { |
| 3499 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3500 | "\"server_name *\" is unsupported, use " |
| 3501 | "\"server_name_in_redirect off\" instead"); |
| 3502 | return NGX_CONF_ERROR; |
| 3503 | } |
| 3504 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 3505 | sn = ngx_array_push(&cscf->server_names); |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 3506 | if (sn == NULL) { |
Igor Sysoev | c0edbcc | 2004-10-21 15:34:38 +0000 | [diff] [blame] | 3507 | return NGX_CONF_ERROR; |
| 3508 | } |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 3509 | |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3510 | #if (NGX_PCRE) |
| 3511 | sn->regex = NULL; |
| 3512 | #endif |
Igor Sysoev | cd8b43c | 2009-10-21 16:52:10 +0000 | [diff] [blame] | 3513 | sn->server = cscf; |
Igor Sysoev | 99c3ab9 | 2007-12-27 09:17:20 +0000 | [diff] [blame] | 3514 | sn->name = value[i]; |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3515 | |
| 3516 | if (value[i].data[0] != '~') { |
Igor Sysoev | a1b92a9 | 2009-11-29 20:39:32 +0000 | [diff] [blame] | 3517 | ngx_strlow(sn->name.data, sn->name.data, sn->name.len); |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3518 | continue; |
| 3519 | } |
| 3520 | |
| 3521 | #if (NGX_PCRE) |
Igor Sysoev | 86ef6aa | 2007-12-10 12:09:51 +0000 | [diff] [blame] | 3522 | { |
Igor Sysoev | a1b92a9 | 2009-11-29 20:39:32 +0000 | [diff] [blame] | 3523 | u_char *p; |
| 3524 | ngx_regex_compile_t rc; |
| 3525 | u_char errstr[NGX_MAX_CONF_ERRSTR]; |
Igor Sysoev | 86ef6aa | 2007-12-10 12:09:51 +0000 | [diff] [blame] | 3526 | |
Igor Sysoev | be9d165 | 2009-09-14 09:48:48 +0000 | [diff] [blame] | 3527 | if (value[i].len == 1) { |
| 3528 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3529 | "empty regex in server name \"%V\"", &value[i]); |
| 3530 | return NGX_CONF_ERROR; |
| 3531 | } |
| 3532 | |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3533 | value[i].len--; |
| 3534 | value[i].data++; |
| 3535 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 3536 | ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3537 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 3538 | rc.pattern = value[i]; |
| 3539 | rc.err.len = NGX_MAX_CONF_ERRSTR; |
| 3540 | rc.err.data = errstr; |
| 3541 | |
Igor Sysoev | a1b92a9 | 2009-11-29 20:39:32 +0000 | [diff] [blame] | 3542 | for (p = value[i].data; p < value[i].data + value[i].len; p++) { |
| 3543 | if (*p >= 'A' && *p <= 'Z') { |
| 3544 | rc.options = NGX_REGEX_CASELESS; |
| 3545 | break; |
| 3546 | } |
| 3547 | } |
| 3548 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 3549 | sn->regex = ngx_http_regex_compile(cf, &rc); |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3550 | if (sn->regex == NULL) { |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3551 | return NGX_CONF_ERROR; |
| 3552 | } |
| 3553 | |
Igor Sysoev | 99c3ab9 | 2007-12-27 09:17:20 +0000 | [diff] [blame] | 3554 | sn->name = value[i]; |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 3555 | cscf->captures = (rc.captures > 0); |
Igor Sysoev | 86ef6aa | 2007-12-10 12:09:51 +0000 | [diff] [blame] | 3556 | } |
Igor Sysoev | 43c3bf4 | 2007-08-12 19:48:12 +0000 | [diff] [blame] | 3557 | #else |
| 3558 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3559 | "the using of the regex \"%V\" " |
| 3560 | "requires PCRE library", &value[i]); |
| 3561 | |
| 3562 | return NGX_CONF_ERROR; |
| 3563 | #endif |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 3564 | } |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 3565 | |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 3566 | return NGX_CONF_OK; |
| 3567 | } |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 3568 | |
| 3569 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3570 | static char * |
| 3571 | ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3572 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3573 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3574 | |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 3575 | ngx_str_t *value; |
| 3576 | ngx_uint_t alias, n; |
| 3577 | ngx_http_script_compile_t sc; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3578 | |
| 3579 | alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; |
| 3580 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3581 | if (clcf->root.data) { |
Igor Sysoev | a741f8d | 2004-03-30 20:31:58 +0000 | [diff] [blame] | 3582 | |
| 3583 | /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */ |
| 3584 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3585 | if ((ngx_uint_t) clcf->alias == alias) { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3586 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 3587 | "\"%V\" directive is duplicate", |
| 3588 | &cmd->name); |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3589 | } else { |
| 3590 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 3591 | "\"%V\" directive is duplicate, " |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3592 | "\"%s\" directive is specified before", |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3593 | &cmd->name, clcf->alias ? "alias" : "root"); |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | return NGX_CONF_ERROR; |
| 3597 | } |
| 3598 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3599 | if (clcf->named && alias) { |
Igor Sysoev | 8889b65 | 2007-07-29 18:11:39 +0000 | [diff] [blame] | 3600 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3601 | "the \"alias\" directive may not be used " |
| 3602 | "inside named location"); |
| 3603 | |
| 3604 | return NGX_CONF_ERROR; |
| 3605 | } |
| 3606 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3607 | value = cf->args->elts; |
| 3608 | |
Igor Sysoev | 10b9894 | 2007-04-02 05:43:21 +0000 | [diff] [blame] | 3609 | if (ngx_strstr(value[1].data, "$document_root") |
| 3610 | || ngx_strstr(value[1].data, "${document_root}")) |
Igor Sysoev | ceab369 | 2007-04-01 09:03:14 +0000 | [diff] [blame] | 3611 | { |
| 3612 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3613 | "the $document_root variable may not be used " |
| 3614 | "in the \"%V\" directive", |
| 3615 | &cmd->name); |
| 3616 | |
| 3617 | return NGX_CONF_ERROR; |
| 3618 | } |
| 3619 | |
Igor Sysoev | 4ca2acf | 2008-09-29 04:47:22 +0000 | [diff] [blame] | 3620 | if (ngx_strstr(value[1].data, "$realpath_root") |
| 3621 | || ngx_strstr(value[1].data, "${realpath_root}")) |
| 3622 | { |
| 3623 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3624 | "the $realpath_root variable may not be used " |
| 3625 | "in the \"%V\" directive", |
| 3626 | &cmd->name); |
| 3627 | |
| 3628 | return NGX_CONF_ERROR; |
| 3629 | } |
| 3630 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3631 | clcf->alias = alias; |
| 3632 | clcf->root = value[1]; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3633 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3634 | if (!alias && clcf->root.data[clcf->root.len - 1] == '/') { |
| 3635 | clcf->root.len--; |
Igor Sysoev | 7105763 | 2004-08-30 19:24:51 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3638 | if (clcf->root.data[0] != '$') { |
| 3639 | if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) { |
Igor Sysoev | 8f12558 | 2006-07-28 15:16:17 +0000 | [diff] [blame] | 3640 | return NGX_CONF_ERROR; |
| 3641 | } |
Igor Sysoev | 3430346 | 2006-01-24 16:08:27 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3644 | n = ngx_http_script_variables_count(&clcf->root); |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 3645 | |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 3646 | ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
| 3647 | |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 3648 | if (n) { |
| 3649 | sc.cf = cf; |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3650 | sc.source = &clcf->root; |
| 3651 | sc.lengths = &clcf->root_lengths; |
| 3652 | sc.values = &clcf->root_values; |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 3653 | sc.variables = n; |
| 3654 | sc.complete_lengths = 1; |
| 3655 | sc.complete_values = 1; |
Igor Sysoev | 3ca233e | 2005-12-28 14:23:52 +0000 | [diff] [blame] | 3656 | |
Igor Sysoev | 925baa0 | 2009-03-06 12:49:22 +0000 | [diff] [blame] | 3657 | if (ngx_http_script_compile(&sc) != NGX_OK) { |
| 3658 | return NGX_CONF_ERROR; |
| 3659 | } |
| 3660 | } |
| 3661 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 3662 | return NGX_CONF_OK; |
| 3663 | } |
| 3664 | |
| 3665 | |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3666 | static ngx_http_method_name_t ngx_methods_names[] = { |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 3667 | { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET }, |
| 3668 | { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD }, |
| 3669 | { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST }, |
| 3670 | { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT }, |
| 3671 | { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE }, |
| 3672 | { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL }, |
| 3673 | { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY }, |
| 3674 | { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE }, |
| 3675 | { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS }, |
| 3676 | { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND }, |
| 3677 | { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH }, |
| 3678 | { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK }, |
| 3679 | { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK }, |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3680 | { NULL, 0 } |
| 3681 | }; |
| 3682 | |
| 3683 | |
| 3684 | static char * |
| 3685 | ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 3686 | { |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3687 | ngx_http_core_loc_conf_t *pclcf = conf; |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3688 | |
| 3689 | char *rv; |
| 3690 | void *mconf; |
| 3691 | ngx_str_t *value; |
| 3692 | ngx_uint_t i; |
| 3693 | ngx_conf_t save; |
| 3694 | ngx_http_module_t *module; |
| 3695 | ngx_http_conf_ctx_t *ctx, *pctx; |
| 3696 | ngx_http_method_name_t *name; |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3697 | ngx_http_core_loc_conf_t *clcf; |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3698 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3699 | if (pclcf->limit_except) { |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3700 | return "duplicate"; |
| 3701 | } |
| 3702 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3703 | pclcf->limit_except = 0xffffffff; |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3704 | |
| 3705 | value = cf->args->elts; |
| 3706 | |
| 3707 | for (i = 1; i < cf->args->nelts; i++) { |
| 3708 | for (name = ngx_methods_names; name->name; name++) { |
| 3709 | |
| 3710 | if (ngx_strcasecmp(value[i].data, name->name) == 0) { |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3711 | pclcf->limit_except &= name->method; |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3712 | goto next; |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3717 | "invalid method \"%V\"", &value[i]); |
| 3718 | return NGX_CONF_ERROR; |
| 3719 | |
| 3720 | next: |
| 3721 | continue; |
| 3722 | } |
| 3723 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3724 | if (!(pclcf->limit_except & NGX_HTTP_GET)) { |
| 3725 | pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD; |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
| 3729 | if (ctx == NULL) { |
| 3730 | return NGX_CONF_ERROR; |
| 3731 | } |
| 3732 | |
| 3733 | pctx = cf->ctx; |
| 3734 | ctx->main_conf = pctx->main_conf; |
| 3735 | ctx->srv_conf = pctx->srv_conf; |
| 3736 | |
| 3737 | ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); |
| 3738 | if (ctx->loc_conf == NULL) { |
| 3739 | return NGX_CONF_ERROR; |
| 3740 | } |
| 3741 | |
| 3742 | for (i = 0; ngx_modules[i]; i++) { |
| 3743 | if (ngx_modules[i]->type != NGX_HTTP_MODULE) { |
| 3744 | continue; |
| 3745 | } |
| 3746 | |
| 3747 | module = ngx_modules[i]->ctx; |
| 3748 | |
| 3749 | if (module->create_loc_conf) { |
| 3750 | |
| 3751 | mconf = module->create_loc_conf(cf); |
| 3752 | if (mconf == NULL) { |
| 3753 | return NGX_CONF_ERROR; |
| 3754 | } |
| 3755 | |
| 3756 | ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf; |
| 3757 | } |
| 3758 | } |
| 3759 | |
| 3760 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3761 | clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; |
| 3762 | pclcf->limit_except_loc_conf = ctx->loc_conf; |
| 3763 | clcf->loc_conf = ctx->loc_conf; |
| 3764 | clcf->name = pclcf->name; |
| 3765 | clcf->noname = 1; |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3766 | |
Igor Sysoev | e55988c | 2008-05-24 14:14:13 +0000 | [diff] [blame] | 3767 | if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) { |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3768 | return NGX_CONF_ERROR; |
| 3769 | } |
| 3770 | |
Igor Sysoev | 94e32ce | 2006-04-07 14:08:04 +0000 | [diff] [blame] | 3771 | save = *cf; |
| 3772 | cf->ctx = ctx; |
| 3773 | cf->cmd_type = NGX_HTTP_LMT_CONF; |
| 3774 | |
| 3775 | rv = ngx_conf_parse(cf, NULL); |
| 3776 | |
| 3777 | *cf = save; |
| 3778 | |
| 3779 | return rv; |
| 3780 | } |
| 3781 | |
| 3782 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3783 | static char * |
Igor Sysoev | 385af28 | 2008-07-30 12:34:04 +0000 | [diff] [blame] | 3784 | ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 3785 | { |
| 3786 | ngx_http_core_loc_conf_t *clcf = conf; |
| 3787 | |
| 3788 | ngx_str_t *value; |
| 3789 | |
| 3790 | if (clcf->directio != NGX_CONF_UNSET) { |
| 3791 | return "is duplicate"; |
| 3792 | } |
| 3793 | |
| 3794 | value = cf->args->elts; |
| 3795 | |
| 3796 | if (ngx_strcmp(value[1].data, "off") == 0) { |
Igor Sysoev | ad1e123 | 2008-10-16 13:31:00 +0000 | [diff] [blame] | 3797 | clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF; |
Igor Sysoev | 385af28 | 2008-07-30 12:34:04 +0000 | [diff] [blame] | 3798 | return NGX_CONF_OK; |
| 3799 | } |
| 3800 | |
| 3801 | clcf->directio = ngx_parse_offset(&value[1]); |
| 3802 | if (clcf->directio == (off_t) NGX_ERROR) { |
| 3803 | return "invalid value"; |
| 3804 | } |
| 3805 | |
| 3806 | return NGX_CONF_OK; |
| 3807 | } |
| 3808 | |
| 3809 | |
| 3810 | static char * |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3811 | ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3812 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3813 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3814 | |
Igor Sysoev | 17f0e66 | 2009-03-22 09:40:04 +0000 | [diff] [blame] | 3815 | u_char *p; |
| 3816 | ngx_int_t overwrite; |
| 3817 | ngx_str_t *value, uri, args; |
| 3818 | ngx_uint_t i, n; |
| 3819 | ngx_http_err_page_t *err; |
| 3820 | ngx_http_complex_value_t cv; |
| 3821 | ngx_http_compile_complex_value_t ccv; |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3822 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3823 | if (clcf->error_pages == NULL) { |
| 3824 | clcf->error_pages = ngx_array_create(cf->pool, 4, |
| 3825 | sizeof(ngx_http_err_page_t)); |
| 3826 | if (clcf->error_pages == NULL) { |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3827 | return NGX_CONF_ERROR; |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | value = cf->args->elts; |
| 3832 | |
Igor Sysoev | 732a271 | 2004-04-21 18:54:33 +0000 | [diff] [blame] | 3833 | i = cf->args->nelts - 2; |
| 3834 | |
| 3835 | if (value[i].data[0] == '=') { |
| 3836 | if (i == 1) { |
| 3837 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 3838 | "invalid value \"%V\"", &value[i]); |
Igor Sysoev | 732a271 | 2004-04-21 18:54:33 +0000 | [diff] [blame] | 3839 | return NGX_CONF_ERROR; |
| 3840 | } |
| 3841 | |
Igor Sysoev | a257367 | 2005-10-05 14:46:21 +0000 | [diff] [blame] | 3842 | if (value[i].len > 1) { |
| 3843 | overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1); |
Igor Sysoev | 732a271 | 2004-04-21 18:54:33 +0000 | [diff] [blame] | 3844 | |
Igor Sysoev | a257367 | 2005-10-05 14:46:21 +0000 | [diff] [blame] | 3845 | if (overwrite == NGX_ERROR) { |
| 3846 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 3847 | "invalid value \"%V\"", &value[i]); |
| 3848 | return NGX_CONF_ERROR; |
| 3849 | } |
| 3850 | |
| 3851 | } else { |
| 3852 | overwrite = 0; |
Igor Sysoev | 732a271 | 2004-04-21 18:54:33 +0000 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | n = 2; |
| 3856 | |
| 3857 | } else { |
Igor Sysoev | a257367 | 2005-10-05 14:46:21 +0000 | [diff] [blame] | 3858 | overwrite = -1; |
Igor Sysoev | 732a271 | 2004-04-21 18:54:33 +0000 | [diff] [blame] | 3859 | n = 1; |
| 3860 | } |
| 3861 | |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 3862 | uri = value[cf->args->nelts - 1]; |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 3863 | |
Igor Sysoev | 17f0e66 | 2009-03-22 09:40:04 +0000 | [diff] [blame] | 3864 | ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 3865 | |
Igor Sysoev | 17f0e66 | 2009-03-22 09:40:04 +0000 | [diff] [blame] | 3866 | ccv.cf = cf; |
| 3867 | ccv.value = &uri; |
| 3868 | ccv.complex_value = &cv; |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 3869 | |
Igor Sysoev | 17f0e66 | 2009-03-22 09:40:04 +0000 | [diff] [blame] | 3870 | if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
| 3871 | return NGX_CONF_ERROR; |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
Igor Sysoev | 17f0e66 | 2009-03-22 09:40:04 +0000 | [diff] [blame] | 3874 | args.len = 0; |
| 3875 | args.data = NULL; |
| 3876 | |
Igor Sysoev | 64851bb | 2009-04-07 15:50:08 +0000 | [diff] [blame] | 3877 | if (cv.lengths == NULL && uri.data[0] == '/') { |
Igor Sysoev | 17f0e66 | 2009-03-22 09:40:04 +0000 | [diff] [blame] | 3878 | p = (u_char *) ngx_strchr(uri.data, '?'); |
| 3879 | |
| 3880 | if (p) { |
| 3881 | cv.value.len = p - uri.data; |
| 3882 | cv.value.data = uri.data; |
| 3883 | p++; |
| 3884 | args.len = (uri.data + uri.len) - p; |
| 3885 | args.data = p; |
| 3886 | } |
| 3887 | } |
Igor Sysoev | 615fe7f | 2008-04-29 10:06:43 +0000 | [diff] [blame] | 3888 | |
Igor Sysoev | 732a271 | 2004-04-21 18:54:33 +0000 | [diff] [blame] | 3889 | for (i = 1; i < cf->args->nelts - n; i++) { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 3890 | err = ngx_array_push(clcf->error_pages); |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 3891 | if (err == NULL) { |
Igor Sysoev | 732a271 | 2004-04-21 18:54:33 +0000 | [diff] [blame] | 3892 | return NGX_CONF_ERROR; |
| 3893 | } |
| 3894 | |
Igor Sysoev | 3f4685f | 2004-04-25 20:13:21 +0000 | [diff] [blame] | 3895 | err->status = ngx_atoi(value[i].data, value[i].len); |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3896 | |
Igor Sysoev | 586f7a5 | 2006-09-25 17:48:34 +0000 | [diff] [blame] | 3897 | if (err->status == NGX_ERROR || err->status == 499) { |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3898 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 3899 | "invalid value \"%V\"", &value[i]); |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3900 | return NGX_CONF_ERROR; |
| 3901 | } |
| 3902 | |
Igor Sysoev | 3f4685f | 2004-04-25 20:13:21 +0000 | [diff] [blame] | 3903 | if (err->status < 400 || err->status > 599) { |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3904 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 3905 | "value \"%V\" must be between 400 and 599", |
| 3906 | &value[i]); |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3907 | return NGX_CONF_ERROR; |
| 3908 | } |
| 3909 | |
Igor Sysoev | fb14092 | 2008-03-10 14:45:41 +0000 | [diff] [blame] | 3910 | if (overwrite >= 0) { |
| 3911 | err->overwrite = overwrite; |
| 3912 | |
| 3913 | } else { |
| 3914 | switch (err->status) { |
| 3915 | case NGX_HTTP_TO_HTTPS: |
| 3916 | case NGX_HTTPS_CERT_ERROR: |
| 3917 | case NGX_HTTPS_NO_CERT: |
| 3918 | err->overwrite = NGX_HTTP_BAD_REQUEST; |
| 3919 | break; |
| 3920 | |
| 3921 | default: |
| 3922 | err->overwrite = err->status; |
| 3923 | break; |
| 3924 | } |
| 3925 | } |
Igor Sysoev | a257367 | 2005-10-05 14:46:21 +0000 | [diff] [blame] | 3926 | |
Igor Sysoev | 17f0e66 | 2009-03-22 09:40:04 +0000 | [diff] [blame] | 3927 | err->value = cv; |
Igor Sysoev | 1af7090 | 2009-03-22 15:52:52 +0000 | [diff] [blame] | 3928 | err->args = args; |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | return NGX_CONF_OK; |
| 3932 | } |
| 3933 | |
| 3934 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 3935 | static char * |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 3936 | ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 3937 | { |
| 3938 | ngx_http_core_loc_conf_t *clcf = conf; |
| 3939 | |
| 3940 | ngx_str_t *value; |
Igor Sysoev | ecd8228 | 2009-04-11 11:02:36 +0000 | [diff] [blame] | 3941 | ngx_int_t code; |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 3942 | ngx_uint_t i, n; |
| 3943 | ngx_http_try_file_t *tf; |
| 3944 | ngx_http_script_compile_t sc; |
| 3945 | ngx_http_core_main_conf_t *cmcf; |
| 3946 | |
| 3947 | if (clcf->try_files) { |
| 3948 | return "is duplicate"; |
| 3949 | } |
| 3950 | |
| 3951 | cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
| 3952 | |
| 3953 | cmcf->try_files = 1; |
| 3954 | |
| 3955 | tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t)); |
| 3956 | if (tf == NULL) { |
| 3957 | return NGX_CONF_ERROR; |
| 3958 | } |
| 3959 | |
| 3960 | clcf->try_files = tf; |
| 3961 | |
| 3962 | value = cf->args->elts; |
| 3963 | |
| 3964 | for (i = 0; i < cf->args->nelts - 1; i++) { |
| 3965 | |
| 3966 | tf[i].name = value[i + 1]; |
| 3967 | |
Igor Sysoev | 319dc27 | 2009-01-21 12:11:22 +0000 | [diff] [blame] | 3968 | if (tf[i].name.data[tf[i].name.len - 1] == '/') { |
| 3969 | tf[i].test_dir = 1; |
| 3970 | tf[i].name.len--; |
Igor Sysoev | cd70a52 | 2009-03-20 16:47:23 +0000 | [diff] [blame] | 3971 | tf[i].name.data[tf[i].name.len] = '\0'; |
Igor Sysoev | 319dc27 | 2009-01-21 12:11:22 +0000 | [diff] [blame] | 3972 | } |
| 3973 | |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 3974 | n = ngx_http_script_variables_count(&tf[i].name); |
| 3975 | |
| 3976 | if (n) { |
| 3977 | ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
| 3978 | |
| 3979 | sc.cf = cf; |
| 3980 | sc.source = &tf[i].name; |
| 3981 | sc.lengths = &tf[i].lengths; |
| 3982 | sc.values = &tf[i].values; |
| 3983 | sc.variables = n; |
| 3984 | sc.complete_lengths = 1; |
| 3985 | sc.complete_values = 1; |
| 3986 | |
| 3987 | if (ngx_http_script_compile(&sc) != NGX_OK) { |
| 3988 | return NGX_CONF_ERROR; |
| 3989 | } |
| 3990 | |
| 3991 | } else { |
| 3992 | /* add trailing '\0' to length */ |
| 3993 | tf[i].name.len++; |
| 3994 | } |
| 3995 | } |
| 3996 | |
Igor Sysoev | ecd8228 | 2009-04-11 11:02:36 +0000 | [diff] [blame] | 3997 | if (tf[i - 1].name.data[0] == '=') { |
| 3998 | |
| 3999 | code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2); |
| 4000 | |
| 4001 | if (code == NGX_ERROR) { |
| 4002 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 4003 | "invalid code \"%*s\"", |
| 4004 | tf[i - 1].name.len - 1, tf[i - 1].name.data); |
| 4005 | return NGX_CONF_ERROR; |
| 4006 | } |
| 4007 | |
| 4008 | tf[i].code = code; |
| 4009 | } |
| 4010 | |
Igor Sysoev | d8e3d0b | 2008-12-15 10:56:48 +0000 | [diff] [blame] | 4011 | return NGX_CONF_OK; |
| 4012 | } |
| 4013 | |
| 4014 | |
| 4015 | static char * |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4016 | ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 4017 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4018 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4019 | |
| 4020 | time_t inactive; |
| 4021 | ngx_str_t *value, s; |
| 4022 | ngx_int_t max; |
| 4023 | ngx_uint_t i; |
| 4024 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4025 | if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) { |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4026 | return "is duplicate"; |
| 4027 | } |
| 4028 | |
| 4029 | value = cf->args->elts; |
| 4030 | |
| 4031 | max = 0; |
| 4032 | inactive = 60; |
| 4033 | |
| 4034 | for (i = 1; i < cf->args->nelts; i++) { |
| 4035 | |
| 4036 | if (ngx_strncmp(value[i].data, "max=", 4) == 0) { |
| 4037 | |
| 4038 | max = ngx_atoi(value[i].data + 4, value[i].len - 4); |
| 4039 | if (max == NGX_ERROR) { |
Igor Sysoev | 8d9c63f | 2008-07-03 19:19:45 +0000 | [diff] [blame] | 4040 | goto failed; |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | continue; |
| 4044 | } |
| 4045 | |
| 4046 | if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { |
| 4047 | |
| 4048 | s.len = value[i].len - 9; |
| 4049 | s.data = value[i].data + 9; |
| 4050 | |
| 4051 | inactive = ngx_parse_time(&s, 1); |
| 4052 | if (inactive < 0) { |
Igor Sysoev | 8d9c63f | 2008-07-03 19:19:45 +0000 | [diff] [blame] | 4053 | goto failed; |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | continue; |
| 4057 | } |
| 4058 | |
| 4059 | if (ngx_strcmp(value[i].data, "off") == 0) { |
| 4060 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4061 | clcf->open_file_cache = NULL; |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4062 | |
| 4063 | continue; |
| 4064 | } |
| 4065 | |
Igor Sysoev | 8d9c63f | 2008-07-03 19:19:45 +0000 | [diff] [blame] | 4066 | failed: |
| 4067 | |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4068 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 4069 | "invalid \"open_file_cache\" parameter \"%V\"", |
| 4070 | &value[i]); |
| 4071 | return NGX_CONF_ERROR; |
| 4072 | } |
| 4073 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4074 | if (clcf->open_file_cache == NULL) { |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4075 | return NGX_CONF_OK; |
| 4076 | } |
| 4077 | |
| 4078 | if (max == 0) { |
| 4079 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 4080 | "\"open_file_cache\" must have \"max\" parameter"); |
| 4081 | return NGX_CONF_ERROR; |
| 4082 | } |
| 4083 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4084 | clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); |
| 4085 | if (clcf->open_file_cache) { |
Igor Sysoev | 140c755 | 2007-09-01 12:12:48 +0000 | [diff] [blame] | 4086 | return NGX_CONF_OK; |
| 4087 | } |
| 4088 | |
| 4089 | return NGX_CONF_ERROR; |
| 4090 | } |
| 4091 | |
| 4092 | |
| 4093 | static char * |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 4094 | ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 4095 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4096 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 4097 | |
Igor Sysoev | c134eb0 | 2009-04-24 14:27:36 +0000 | [diff] [blame] | 4098 | ngx_str_t *value; |
| 4099 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4100 | if (clcf->error_log) { |
Igor Sysoev | 0cd76ea | 2009-04-30 13:53:42 +0000 | [diff] [blame] | 4101 | return "is duplicate"; |
| 4102 | } |
| 4103 | |
Igor Sysoev | c134eb0 | 2009-04-24 14:27:36 +0000 | [diff] [blame] | 4104 | value = cf->args->elts; |
| 4105 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4106 | clcf->error_log = ngx_log_create(cf->cycle, &value[1]); |
| 4107 | if (clcf->error_log == NULL) { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 4108 | return NGX_CONF_ERROR; |
| 4109 | } |
| 4110 | |
Igor Sysoev | 0cd76ea | 2009-04-30 13:53:42 +0000 | [diff] [blame] | 4111 | if (cf->args->nelts == 2) { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4112 | clcf->error_log->log_level = NGX_LOG_ERR; |
Igor Sysoev | 0cd76ea | 2009-04-30 13:53:42 +0000 | [diff] [blame] | 4113 | return NGX_CONF_OK; |
| 4114 | } |
| 4115 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4116 | return ngx_log_set_levels(cf, clcf->error_log); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | |
| 4120 | static char * |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 4121 | ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 4122 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4123 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 4124 | |
| 4125 | ngx_str_t *value; |
| 4126 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4127 | if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) { |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 4128 | return "is duplicate"; |
| 4129 | } |
| 4130 | |
| 4131 | value = cf->args->elts; |
| 4132 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4133 | clcf->keepalive_timeout = ngx_parse_time(&value[1], 0); |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 4134 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4135 | if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 4136 | return "invalid value"; |
| 4137 | } |
| 4138 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4139 | if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 4140 | return "value must be less than 597 hours"; |
| 4141 | } |
| 4142 | |
| 4143 | if (cf->args->nelts == 2) { |
| 4144 | return NGX_CONF_OK; |
| 4145 | } |
| 4146 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4147 | clcf->keepalive_header = ngx_parse_time(&value[2], 1); |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 4148 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4149 | if (clcf->keepalive_header == NGX_ERROR) { |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 4150 | return "invalid value"; |
| 4151 | } |
| 4152 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4153 | if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) { |
Igor Sysoev | 307c3ad | 2004-09-17 16:07:35 +0000 | [diff] [blame] | 4154 | return "value must be less than 68 years"; |
| 4155 | } |
| 4156 | |
| 4157 | return NGX_CONF_OK; |
| 4158 | } |
| 4159 | |
| 4160 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 4161 | static char * |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 4162 | ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 4163 | { |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4164 | ngx_http_core_loc_conf_t *clcf = conf; |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 4165 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4166 | if (clcf->internal != NGX_CONF_UNSET) { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 4167 | return "is duplicate"; |
Igor Sysoev | 03420a6 | 2004-01-20 20:40:08 +0000 | [diff] [blame] | 4168 | } |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 4169 | |
Igor Sysoev | 30870b4 | 2009-11-13 19:59:54 +0000 | [diff] [blame] | 4170 | clcf->internal = 1; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 4171 | |
| 4172 | return NGX_CONF_OK; |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 4173 | } |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 4174 | |
| 4175 | |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 4176 | static char * |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 4177 | ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 4178 | { |
| 4179 | ngx_http_core_loc_conf_t *clcf = conf; |
| 4180 | |
| 4181 | ngx_url_t u; |
| 4182 | ngx_str_t *value; |
| 4183 | |
Igor Sysoev | f39876c | 2008-03-06 08:48:55 +0000 | [diff] [blame] | 4184 | if (clcf->resolver) { |
| 4185 | return "is duplicate"; |
| 4186 | } |
| 4187 | |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 4188 | value = cf->args->elts; |
| 4189 | |
Igor Sysoev | 4d65f65 | 2007-11-30 22:08:59 +0000 | [diff] [blame] | 4190 | ngx_memzero(&u, sizeof(ngx_url_t)); |
| 4191 | |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 4192 | u.host = value[1]; |
| 4193 | u.port = 53; |
| 4194 | |
| 4195 | if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) { |
| 4196 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err); |
| 4197 | return NGX_CONF_ERROR; |
| 4198 | } |
| 4199 | |
Igor Sysoev | dfd5511 | 2008-03-04 10:42:05 +0000 | [diff] [blame] | 4200 | clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]); |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 4201 | if (clcf->resolver == NULL) { |
| 4202 | return NGX_OK; |
| 4203 | } |
| 4204 | |
| 4205 | return NGX_CONF_OK; |
| 4206 | } |
| 4207 | |
| 4208 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4209 | #if (NGX_HTTP_GZIP) |
| 4210 | |
| 4211 | static char * |
| 4212 | ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 4213 | { |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4214 | ngx_http_core_loc_conf_t *clcf = conf; |
| 4215 | |
Igor Sysoev | 54477e4 | 2008-08-26 15:09:28 +0000 | [diff] [blame] | 4216 | #if (NGX_PCRE) |
| 4217 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 4218 | ngx_str_t *value; |
| 4219 | ngx_uint_t i; |
| 4220 | ngx_regex_elt_t *re; |
| 4221 | ngx_regex_compile_t rc; |
| 4222 | u_char errstr[NGX_MAX_CONF_ERRSTR]; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4223 | |
| 4224 | if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) { |
| 4225 | clcf->gzip_disable = ngx_array_create(cf->pool, 2, |
| 4226 | sizeof(ngx_regex_elt_t)); |
| 4227 | if (clcf->gzip_disable == NULL) { |
| 4228 | return NGX_CONF_ERROR; |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | value = cf->args->elts; |
| 4233 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 4234 | ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
| 4235 | |
| 4236 | rc.pool = cf->pool; |
| 4237 | rc.err.len = NGX_MAX_CONF_ERRSTR; |
| 4238 | rc.err.data = errstr; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4239 | |
| 4240 | for (i = 1; i < cf->args->nelts; i++) { |
| 4241 | |
Igor Sysoev | 54477e4 | 2008-08-26 15:09:28 +0000 | [diff] [blame] | 4242 | if (ngx_strcmp(value[1].data, "msie6") == 0) { |
| 4243 | clcf->gzip_disable_msie6 = 1; |
| 4244 | continue; |
| 4245 | } |
| 4246 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4247 | re = ngx_array_push(clcf->gzip_disable); |
| 4248 | if (re == NULL) { |
| 4249 | return NGX_CONF_ERROR; |
| 4250 | } |
| 4251 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 4252 | rc.pattern = value[1]; |
| 4253 | rc.options = NGX_REGEX_CASELESS; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4254 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 4255 | if (ngx_regex_compile(&rc) != NGX_OK) { |
| 4256 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err); |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4257 | return NGX_CONF_ERROR; |
| 4258 | } |
| 4259 | |
Igor Sysoev | c05f20e | 2009-11-16 12:19:02 +0000 | [diff] [blame] | 4260 | re->regex = rc.regex; |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4261 | re->name = value[i].data; |
| 4262 | } |
| 4263 | |
| 4264 | return NGX_CONF_OK; |
| 4265 | |
| 4266 | #else |
Igor Sysoev | 54477e4 | 2008-08-26 15:09:28 +0000 | [diff] [blame] | 4267 | ngx_str_t *value; |
| 4268 | |
| 4269 | value = cf->args->elts; |
| 4270 | |
| 4271 | if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "msie6") == 0) { |
| 4272 | clcf->gzip_disable_msie6 = 1; |
| 4273 | return NGX_CONF_OK; |
| 4274 | } |
| 4275 | |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4276 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 54477e4 | 2008-08-26 15:09:28 +0000 | [diff] [blame] | 4277 | "without PCRE library \"gzip_disable\" supports " |
| 4278 | "builtin \"msie6\" mask only"); |
Igor Sysoev | c16b005 | 2007-12-27 14:21:59 +0000 | [diff] [blame] | 4279 | |
| 4280 | return NGX_CONF_ERROR; |
| 4281 | #endif |
| 4282 | } |
| 4283 | |
| 4284 | #endif |
| 4285 | |
| 4286 | |
Igor Sysoev | 13f5ff9 | 2007-11-27 11:33:52 +0000 | [diff] [blame] | 4287 | static char * |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 4288 | ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data) |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 4289 | { |
Igor Sysoev | c0edbcc | 2004-10-21 15:34:38 +0000 | [diff] [blame] | 4290 | #if (NGX_FREEBSD) |
Igor Sysoev | 42b12b3 | 2004-12-02 18:40:46 +0000 | [diff] [blame] | 4291 | ssize_t *np = data; |
Igor Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame] | 4292 | |
Igor Sysoev | 08e63d4 | 2006-08-14 15:09:38 +0000 | [diff] [blame] | 4293 | if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) { |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 4294 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 4295 | "\"send_lowat\" must be less than %d " |
| 4296 | "(sysctl net.inet.tcp.sendspace)", |
| 4297 | ngx_freebsd_net_inet_tcp_sendspace); |
| 4298 | |
| 4299 | return NGX_CONF_ERROR; |
| 4300 | } |
| 4301 | |
Igor Sysoev | f690604 | 2004-11-25 16:17:31 +0000 | [diff] [blame] | 4302 | #elif !(NGX_HAVE_SO_SNDLOWAT) |
Igor Sysoev | 42b12b3 | 2004-12-02 18:40:46 +0000 | [diff] [blame] | 4303 | ssize_t *np = data; |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 4304 | |
| 4305 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 4306 | "\"send_lowat\" is not supported, ignored"); |
| 4307 | |
Igor Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame] | 4308 | *np = 0; |
| 4309 | |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 4310 | #endif |
| 4311 | |
| 4312 | return NGX_CONF_OK; |
| 4313 | } |
Igor Sysoev | 08d068f | 2007-05-07 09:20:42 +0000 | [diff] [blame] | 4314 | |
| 4315 | |
| 4316 | static char * |
| 4317 | ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data) |
| 4318 | { |
| 4319 | size_t *sp = data; |
| 4320 | |
| 4321 | if (*sp < NGX_MIN_POOL_SIZE) { |
| 4322 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 04799a6 | 2009-12-17 12:25:46 +0000 | [diff] [blame] | 4323 | "the pool size must be no less than %uz", |
| 4324 | NGX_MIN_POOL_SIZE); |
| 4325 | return NGX_CONF_ERROR; |
| 4326 | } |
Igor Sysoev | 08d068f | 2007-05-07 09:20:42 +0000 | [diff] [blame] | 4327 | |
Igor Sysoev | 04799a6 | 2009-12-17 12:25:46 +0000 | [diff] [blame] | 4328 | if (*sp % NGX_POOL_ALIGNMENT) { |
| 4329 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 4330 | "the pool size must be a multiple of %uz", |
| 4331 | NGX_POOL_ALIGNMENT); |
Igor Sysoev | 08d068f | 2007-05-07 09:20:42 +0000 | [diff] [blame] | 4332 | return NGX_CONF_ERROR; |
| 4333 | } |
| 4334 | |
| 4335 | return NGX_CONF_OK; |
| 4336 | } |