nginxtra 1.8.1.12 → 1.10.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +363 -25
  6. data/vendor/nginx/CHANGES.ru +365 -21
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/conf +32 -0
  9. data/vendor/nginx/auto/cc/gcc +1 -1
  10. data/vendor/nginx/auto/cc/icc +2 -2
  11. data/vendor/nginx/auto/cc/msvc +29 -8
  12. data/vendor/nginx/auto/cc/name +2 -25
  13. data/vendor/nginx/auto/cc/sunc +3 -0
  14. data/vendor/nginx/auto/endianness +7 -2
  15. data/vendor/nginx/auto/install +60 -26
  16. data/vendor/nginx/auto/lib/conf +4 -4
  17. data/vendor/nginx/auto/lib/geoip/conf +6 -1
  18. data/vendor/nginx/auto/lib/libgd/conf +6 -1
  19. data/vendor/nginx/auto/lib/libxslt/conf +11 -2
  20. data/vendor/nginx/auto/lib/make +1 -1
  21. data/vendor/nginx/auto/lib/md5/conf +2 -2
  22. data/vendor/nginx/auto/lib/md5/make +2 -2
  23. data/vendor/nginx/auto/lib/openssl/conf +52 -3
  24. data/vendor/nginx/auto/lib/openssl/make +1 -1
  25. data/vendor/nginx/auto/lib/pcre/conf +2 -2
  26. data/vendor/nginx/auto/lib/pcre/make +2 -2
  27. data/vendor/nginx/auto/lib/perl/conf +6 -3
  28. data/vendor/nginx/auto/lib/perl/make +4 -1
  29. data/vendor/nginx/auto/lib/sha1/conf +2 -2
  30. data/vendor/nginx/auto/lib/sha1/make +2 -2
  31. data/vendor/nginx/auto/lib/zlib/conf +2 -2
  32. data/vendor/nginx/auto/lib/zlib/make +2 -2
  33. data/vendor/nginx/auto/make +281 -16
  34. data/vendor/nginx/auto/module +122 -0
  35. data/vendor/nginx/auto/modules +909 -178
  36. data/vendor/nginx/auto/options +81 -19
  37. data/vendor/nginx/auto/os/conf +9 -0
  38. data/vendor/nginx/auto/os/darwin +3 -0
  39. data/vendor/nginx/auto/os/freebsd +0 -20
  40. data/vendor/nginx/auto/os/linux +0 -12
  41. data/vendor/nginx/auto/os/win32 +5 -1
  42. data/vendor/nginx/auto/sources +11 -311
  43. data/vendor/nginx/auto/summary +1 -0
  44. data/vendor/nginx/auto/types/sizeof +5 -3
  45. data/vendor/nginx/auto/types/typedef +9 -4
  46. data/vendor/nginx/auto/types/uintptr_t +7 -2
  47. data/vendor/nginx/auto/unix +72 -12
  48. data/vendor/nginx/conf/fastcgi.conf +1 -0
  49. data/vendor/nginx/conf/fastcgi_params +1 -0
  50. data/vendor/nginx/conf/scgi_params +1 -0
  51. data/vendor/nginx/conf/uwsgi_params +1 -0
  52. data/vendor/nginx/configure +1 -1
  53. data/vendor/nginx/contrib/vim/syntax/nginx.vim +2 -2
  54. data/vendor/nginx/man/nginx.8 +6 -2
  55. data/vendor/nginx/src/core/nginx.c +281 -114
  56. data/vendor/nginx/src/core/nginx.h +2 -2
  57. data/vendor/nginx/src/core/ngx_conf_file.c +54 -13
  58. data/vendor/nginx/src/core/ngx_conf_file.h +8 -52
  59. data/vendor/nginx/src/core/ngx_config.h +0 -5
  60. data/vendor/nginx/src/core/ngx_connection.c +270 -37
  61. data/vendor/nginx/src/core/ngx_connection.h +35 -12
  62. data/vendor/nginx/src/core/ngx_core.h +4 -0
  63. data/vendor/nginx/src/core/ngx_crypt.c +2 -2
  64. data/vendor/nginx/src/core/ngx_cycle.c +72 -25
  65. data/vendor/nginx/src/core/ngx_cycle.h +28 -39
  66. data/vendor/nginx/src/core/ngx_file.c +14 -5
  67. data/vendor/nginx/src/core/ngx_file.h +2 -0
  68. data/vendor/nginx/src/core/ngx_hash.c +13 -1
  69. data/vendor/nginx/src/core/ngx_inet.c +20 -18
  70. data/vendor/nginx/src/core/ngx_log.c +12 -12
  71. data/vendor/nginx/src/core/ngx_log.h +13 -6
  72. data/vendor/nginx/src/core/ngx_module.c +360 -0
  73. data/vendor/nginx/src/core/ngx_module.h +307 -0
  74. data/vendor/nginx/src/core/ngx_open_file_cache.c +2 -2
  75. data/vendor/nginx/src/core/ngx_output_chain.c +8 -4
  76. data/vendor/nginx/src/core/ngx_palloc.c +42 -44
  77. data/vendor/nginx/src/{http/ngx_http_parse_time.c → core/ngx_parse_time.c} +2 -3
  78. data/vendor/nginx/src/core/ngx_parse_time.h +22 -0
  79. data/vendor/nginx/src/core/ngx_proxy_protocol.c +50 -1
  80. data/vendor/nginx/src/core/ngx_proxy_protocol.h +3 -1
  81. data/vendor/nginx/src/core/ngx_regex.c +1 -38
  82. data/vendor/nginx/src/core/ngx_resolver.c +1814 -320
  83. data/vendor/nginx/src/core/ngx_resolver.h +67 -10
  84. data/vendor/nginx/src/core/ngx_rwlock.c +120 -0
  85. data/vendor/nginx/src/core/ngx_rwlock.h +21 -0
  86. data/vendor/nginx/src/core/ngx_slab.c +6 -5
  87. data/vendor/nginx/src/core/ngx_string.c +1 -1
  88. data/vendor/nginx/src/core/ngx_syslog.c +11 -3
  89. data/vendor/nginx/src/core/ngx_syslog.h +2 -1
  90. data/vendor/nginx/src/core/ngx_thread_pool.c +4 -0
  91. data/vendor/nginx/src/core/ngx_times.c +2 -2
  92. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +3 -1
  93. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +5 -2
  94. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +5 -5
  95. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +15 -8
  96. data/vendor/nginx/src/event/modules/ngx_poll_module.c +0 -10
  97. data/vendor/nginx/src/event/modules/ngx_select_module.c +0 -10
  98. data/vendor/nginx/src/event/ngx_event.c +60 -103
  99. data/vendor/nginx/src/event/ngx_event.h +22 -26
  100. data/vendor/nginx/src/event/ngx_event_accept.c +414 -88
  101. data/vendor/nginx/src/event/ngx_event_connect.c +27 -18
  102. data/vendor/nginx/src/event/ngx_event_connect.h +1 -0
  103. data/vendor/nginx/src/event/ngx_event_openssl.c +65 -25
  104. data/vendor/nginx/src/event/ngx_event_openssl.h +17 -0
  105. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +73 -7
  106. data/vendor/nginx/src/event/ngx_event_pipe.c +85 -27
  107. data/vendor/nginx/src/event/ngx_event_pipe.h +10 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_auth_basic_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_auth_request_module.c +2 -2
  110. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +2 -2
  111. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +6 -6
  112. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +17 -11
  113. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +2 -2
  114. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +9 -9
  115. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +2 -2
  116. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +2 -2
  117. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +0 -7
  118. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +6 -6
  119. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +2 -1
  120. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +13 -13
  121. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +2 -2
  122. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +26 -21
  123. data/vendor/nginx/src/http/modules/ngx_http_random_index_module.c +1 -1
  124. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +26 -8
  125. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +73 -3
  126. data/vendor/nginx/src/http/modules/ngx_http_referer_module.c +1 -1
  127. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -6
  128. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +5 -3
  129. data/vendor/nginx/src/http/modules/ngx_http_slice_filter_module.c +526 -0
  130. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +7 -7
  131. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +19 -16
  132. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +1 -1
  133. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  134. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +373 -173
  135. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +72 -46
  136. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +18 -30
  137. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +50 -39
  138. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +38 -129
  139. data/vendor/nginx/src/http/modules/ngx_http_upstream_zone_module.c +246 -0
  140. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +6 -5
  141. data/vendor/nginx/src/http/modules/perl/nginx.xs +9 -9
  142. data/vendor/nginx/src/http/ngx_http.c +46 -43
  143. data/vendor/nginx/src/http/ngx_http.h +4 -9
  144. data/vendor/nginx/src/http/ngx_http_cache.h +4 -0
  145. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +13 -5
  146. data/vendor/nginx/src/http/ngx_http_core_module.c +92 -91
  147. data/vendor/nginx/src/http/ngx_http_core_module.h +12 -8
  148. data/vendor/nginx/src/http/ngx_http_file_cache.c +61 -10
  149. data/vendor/nginx/src/http/ngx_http_request.c +37 -50
  150. data/vendor/nginx/src/http/ngx_http_request.h +10 -15
  151. data/vendor/nginx/src/http/ngx_http_request_body.c +64 -88
  152. data/vendor/nginx/src/http/ngx_http_script.c +3 -3
  153. data/vendor/nginx/src/http/ngx_http_special_response.c +1 -4
  154. data/vendor/nginx/src/http/ngx_http_upstream.c +245 -109
  155. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -5
  156. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +212 -65
  157. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +66 -5
  158. data/vendor/nginx/src/http/ngx_http_variables.c +28 -15
  159. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +1 -1
  160. data/vendor/nginx/src/http/v2/ngx_http_v2.c +4349 -0
  161. data/vendor/nginx/src/http/v2/ngx_http_v2.h +337 -0
  162. data/vendor/nginx/src/http/v2/ngx_http_v2_filter_module.c +1391 -0
  163. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_decode.c +2714 -0
  164. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_encode.c +254 -0
  165. data/vendor/nginx/src/http/v2/ngx_http_v2_module.c +469 -0
  166. data/vendor/nginx/src/http/{ngx_http_spdy_module.h → v2/ngx_http_v2_module.h} +10 -9
  167. data/vendor/nginx/src/http/v2/ngx_http_v2_table.c +349 -0
  168. data/vendor/nginx/src/mail/ngx_mail.c +49 -82
  169. data/vendor/nginx/src/mail/ngx_mail.h +16 -23
  170. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +1 -1
  171. data/vendor/nginx/src/mail/ngx_mail_core_module.c +60 -34
  172. data/vendor/nginx/src/mail/ngx_mail_handler.c +17 -12
  173. data/vendor/nginx/src/mail/ngx_mail_proxy_module.c +1 -14
  174. data/vendor/nginx/src/mail/ngx_mail_smtp_handler.c +1 -1
  175. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +5 -5
  176. data/vendor/nginx/src/os/unix/ngx_atomic.h +10 -10
  177. data/vendor/nginx/src/os/unix/ngx_channel.h +4 -4
  178. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +2 -0
  179. data/vendor/nginx/src/os/unix/ngx_darwin_init.c +1 -0
  180. data/vendor/nginx/src/os/unix/ngx_dlopen.c +28 -0
  181. data/vendor/nginx/src/os/unix/ngx_dlopen.h +31 -0
  182. data/vendor/nginx/src/os/unix/ngx_errno.h +1 -0
  183. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +1 -1
  184. data/vendor/nginx/src/os/unix/ngx_files.c +313 -80
  185. data/vendor/nginx/src/os/unix/ngx_files.h +5 -2
  186. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +3 -1
  187. data/vendor/nginx/src/os/unix/ngx_freebsd_init.c +1 -0
  188. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +13 -0
  189. data/vendor/nginx/src/os/unix/ngx_linux.h +0 -2
  190. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +1 -1
  191. data/vendor/nginx/src/os/unix/ngx_linux_config.h +2 -6
  192. data/vendor/nginx/src/os/unix/ngx_linux_init.c +1 -33
  193. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +55 -12
  194. data/vendor/nginx/src/os/unix/ngx_os.h +3 -9
  195. data/vendor/nginx/src/os/unix/ngx_posix_config.h +14 -1
  196. data/vendor/nginx/src/os/unix/ngx_posix_init.c +2 -1
  197. data/vendor/nginx/src/os/unix/ngx_process.c +1 -1
  198. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +25 -51
  199. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +1 -0
  200. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +24 -28
  201. data/vendor/nginx/src/os/unix/ngx_recv.c +30 -79
  202. data/vendor/nginx/src/os/unix/ngx_send.c +1 -1
  203. data/vendor/nginx/src/os/unix/ngx_setaffinity.c +14 -30
  204. data/vendor/nginx/src/os/unix/ngx_setaffinity.h +15 -1
  205. data/vendor/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  206. data/vendor/nginx/src/os/unix/ngx_solaris_init.c +1 -0
  207. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +23 -0
  208. data/vendor/nginx/src/os/unix/ngx_sunpro_amd64.il +3 -3
  209. data/vendor/nginx/src/os/unix/ngx_sunpro_x86.il +3 -3
  210. data/vendor/nginx/src/os/unix/ngx_udp_recv.c +5 -48
  211. data/vendor/nginx/src/os/unix/ngx_udp_send.c +56 -0
  212. data/vendor/nginx/src/stream/ngx_stream.c +564 -0
  213. data/vendor/nginx/src/stream/ngx_stream.h +212 -0
  214. data/vendor/nginx/src/stream/ngx_stream_access_module.c +451 -0
  215. data/vendor/nginx/src/stream/ngx_stream_core_module.c +562 -0
  216. data/vendor/nginx/src/stream/ngx_stream_handler.c +344 -0
  217. data/vendor/nginx/src/stream/ngx_stream_limit_conn_module.c +632 -0
  218. data/vendor/nginx/src/stream/ngx_stream_proxy_module.c +1674 -0
  219. data/vendor/nginx/src/stream/ngx_stream_ssl_module.c +460 -0
  220. data/vendor/nginx/src/stream/ngx_stream_ssl_module.h +49 -0
  221. data/vendor/nginx/src/stream/ngx_stream_upstream.c +464 -0
  222. data/vendor/nginx/src/stream/ngx_stream_upstream.h +107 -0
  223. data/vendor/nginx/src/stream/ngx_stream_upstream_hash_module.c +656 -0
  224. data/vendor/nginx/src/stream/ngx_stream_upstream_least_conn_module.c +307 -0
  225. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.c +702 -0
  226. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.h +139 -0
  227. data/vendor/nginx/src/stream/ngx_stream_upstream_zone_module.c +242 -0
  228. metadata +39 -15
  229. data/vendor/nginx/src/event/modules/ngx_aio_module.c +0 -171
  230. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +0 -735
  231. data/vendor/nginx/src/http/ngx_http_spdy.c +0 -3701
  232. data/vendor/nginx/src/http/ngx_http_spdy.h +0 -261
  233. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +0 -1222
  234. data/vendor/nginx/src/http/ngx_http_spdy_module.c +0 -408
  235. data/vendor/nginx/src/os/unix/ngx_aio_read.c +0 -109
  236. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +0 -78
  237. data/vendor/nginx/src/os/unix/ngx_aio_write.c +0 -109
  238. data/vendor/nginx/src/os/unix/ngx_aio_write_chain.c +0 -100
@@ -0,0 +1,49 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #ifndef _NGX_STREAM_SSL_H_INCLUDED_
9
+ #define _NGX_STREAM_SSL_H_INCLUDED_
10
+
11
+
12
+ #include <ngx_config.h>
13
+ #include <ngx_core.h>
14
+ #include <ngx_stream.h>
15
+
16
+
17
+ typedef struct {
18
+ ngx_msec_t handshake_timeout;
19
+
20
+ ngx_flag_t prefer_server_ciphers;
21
+
22
+ ngx_ssl_t ssl;
23
+
24
+ ngx_uint_t protocols;
25
+
26
+ ssize_t builtin_session_cache;
27
+
28
+ time_t session_timeout;
29
+
30
+ ngx_str_t certificate;
31
+ ngx_str_t certificate_key;
32
+ ngx_str_t dhparam;
33
+ ngx_str_t ecdh_curve;
34
+
35
+ ngx_str_t ciphers;
36
+
37
+ ngx_array_t *passwords;
38
+
39
+ ngx_shm_zone_t *shm_zone;
40
+
41
+ ngx_flag_t session_tickets;
42
+ ngx_array_t *session_ticket_keys;
43
+ } ngx_stream_ssl_conf_t;
44
+
45
+
46
+ extern ngx_module_t ngx_stream_ssl_module;
47
+
48
+
49
+ #endif /* _NGX_STREAM_SSL_H_INCLUDED_ */
@@ -0,0 +1,464 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+ #include <ngx_stream.h>
11
+
12
+
13
+ static char *ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd,
14
+ void *dummy);
15
+ static char *ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
16
+ void *conf);
17
+ static void *ngx_stream_upstream_create_main_conf(ngx_conf_t *cf);
18
+ static char *ngx_stream_upstream_init_main_conf(ngx_conf_t *cf, void *conf);
19
+
20
+
21
+ static ngx_command_t ngx_stream_upstream_commands[] = {
22
+
23
+ { ngx_string("upstream"),
24
+ NGX_STREAM_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
25
+ ngx_stream_upstream,
26
+ 0,
27
+ 0,
28
+ NULL },
29
+
30
+ { ngx_string("server"),
31
+ NGX_STREAM_UPS_CONF|NGX_CONF_1MORE,
32
+ ngx_stream_upstream_server,
33
+ NGX_STREAM_SRV_CONF_OFFSET,
34
+ 0,
35
+ NULL },
36
+
37
+ ngx_null_command
38
+ };
39
+
40
+
41
+ static ngx_stream_module_t ngx_stream_upstream_module_ctx = {
42
+ NULL, /* postconfiguration */
43
+
44
+ ngx_stream_upstream_create_main_conf, /* create main configuration */
45
+ ngx_stream_upstream_init_main_conf, /* init main configuration */
46
+
47
+ NULL, /* create server configuration */
48
+ NULL, /* merge server configuration */
49
+ };
50
+
51
+
52
+ ngx_module_t ngx_stream_upstream_module = {
53
+ NGX_MODULE_V1,
54
+ &ngx_stream_upstream_module_ctx, /* module context */
55
+ ngx_stream_upstream_commands, /* module directives */
56
+ NGX_STREAM_MODULE, /* module type */
57
+ NULL, /* init master */
58
+ NULL, /* init module */
59
+ NULL, /* init process */
60
+ NULL, /* init thread */
61
+ NULL, /* exit thread */
62
+ NULL, /* exit process */
63
+ NULL, /* exit master */
64
+ NGX_MODULE_V1_PADDING
65
+ };
66
+
67
+
68
+ static char *
69
+ ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
70
+ {
71
+ char *rv;
72
+ void *mconf;
73
+ ngx_str_t *value;
74
+ ngx_url_t u;
75
+ ngx_uint_t m;
76
+ ngx_conf_t pcf;
77
+ ngx_stream_module_t *module;
78
+ ngx_stream_conf_ctx_t *ctx, *stream_ctx;
79
+ ngx_stream_upstream_srv_conf_t *uscf;
80
+
81
+ ngx_memzero(&u, sizeof(ngx_url_t));
82
+
83
+ value = cf->args->elts;
84
+ u.host = value[1];
85
+ u.no_resolve = 1;
86
+ u.no_port = 1;
87
+
88
+ uscf = ngx_stream_upstream_add(cf, &u, NGX_STREAM_UPSTREAM_CREATE
89
+ |NGX_STREAM_UPSTREAM_WEIGHT
90
+ |NGX_STREAM_UPSTREAM_MAX_FAILS
91
+ |NGX_STREAM_UPSTREAM_FAIL_TIMEOUT
92
+ |NGX_STREAM_UPSTREAM_DOWN
93
+ |NGX_STREAM_UPSTREAM_BACKUP);
94
+ if (uscf == NULL) {
95
+ return NGX_CONF_ERROR;
96
+ }
97
+
98
+
99
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_stream_conf_ctx_t));
100
+ if (ctx == NULL) {
101
+ return NGX_CONF_ERROR;
102
+ }
103
+
104
+ stream_ctx = cf->ctx;
105
+ ctx->main_conf = stream_ctx->main_conf;
106
+
107
+ /* the upstream{}'s srv_conf */
108
+
109
+ ctx->srv_conf = ngx_pcalloc(cf->pool,
110
+ sizeof(void *) * ngx_stream_max_module);
111
+ if (ctx->srv_conf == NULL) {
112
+ return NGX_CONF_ERROR;
113
+ }
114
+
115
+ ctx->srv_conf[ngx_stream_upstream_module.ctx_index] = uscf;
116
+
117
+ uscf->srv_conf = ctx->srv_conf;
118
+
119
+ for (m = 0; cf->cycle->modules[m]; m++) {
120
+ if (cf->cycle->modules[m]->type != NGX_STREAM_MODULE) {
121
+ continue;
122
+ }
123
+
124
+ module = cf->cycle->modules[m]->ctx;
125
+
126
+ if (module->create_srv_conf) {
127
+ mconf = module->create_srv_conf(cf);
128
+ if (mconf == NULL) {
129
+ return NGX_CONF_ERROR;
130
+ }
131
+
132
+ ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf;
133
+ }
134
+ }
135
+
136
+ uscf->servers = ngx_array_create(cf->pool, 4,
137
+ sizeof(ngx_stream_upstream_server_t));
138
+ if (uscf->servers == NULL) {
139
+ return NGX_CONF_ERROR;
140
+ }
141
+
142
+
143
+ /* parse inside upstream{} */
144
+
145
+ pcf = *cf;
146
+ cf->ctx = ctx;
147
+ cf->cmd_type = NGX_STREAM_UPS_CONF;
148
+
149
+ rv = ngx_conf_parse(cf, NULL);
150
+
151
+ *cf = pcf;
152
+
153
+ if (rv != NGX_CONF_OK) {
154
+ return rv;
155
+ }
156
+
157
+ if (uscf->servers->nelts == 0) {
158
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
159
+ "no servers are inside upstream");
160
+ return NGX_CONF_ERROR;
161
+ }
162
+
163
+ return rv;
164
+ }
165
+
166
+
167
+ static char *
168
+ ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
169
+ {
170
+ ngx_stream_upstream_srv_conf_t *uscf = conf;
171
+
172
+ time_t fail_timeout;
173
+ ngx_str_t *value, s;
174
+ ngx_url_t u;
175
+ ngx_int_t weight, max_fails;
176
+ ngx_uint_t i;
177
+ ngx_stream_upstream_server_t *us;
178
+
179
+ us = ngx_array_push(uscf->servers);
180
+ if (us == NULL) {
181
+ return NGX_CONF_ERROR;
182
+ }
183
+
184
+ ngx_memzero(us, sizeof(ngx_stream_upstream_server_t));
185
+
186
+ value = cf->args->elts;
187
+
188
+ weight = 1;
189
+ max_fails = 1;
190
+ fail_timeout = 10;
191
+
192
+ for (i = 2; i < cf->args->nelts; i++) {
193
+
194
+ if (ngx_strncmp(value[i].data, "weight=", 7) == 0) {
195
+
196
+ if (!(uscf->flags & NGX_STREAM_UPSTREAM_WEIGHT)) {
197
+ goto not_supported;
198
+ }
199
+
200
+ weight = ngx_atoi(&value[i].data[7], value[i].len - 7);
201
+
202
+ if (weight == NGX_ERROR || weight == 0) {
203
+ goto invalid;
204
+ }
205
+
206
+ continue;
207
+ }
208
+
209
+ if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {
210
+
211
+ if (!(uscf->flags & NGX_STREAM_UPSTREAM_MAX_FAILS)) {
212
+ goto not_supported;
213
+ }
214
+
215
+ max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10);
216
+
217
+ if (max_fails == NGX_ERROR) {
218
+ goto invalid;
219
+ }
220
+
221
+ continue;
222
+ }
223
+
224
+ if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) {
225
+
226
+ if (!(uscf->flags & NGX_STREAM_UPSTREAM_FAIL_TIMEOUT)) {
227
+ goto not_supported;
228
+ }
229
+
230
+ s.len = value[i].len - 13;
231
+ s.data = &value[i].data[13];
232
+
233
+ fail_timeout = ngx_parse_time(&s, 1);
234
+
235
+ if (fail_timeout == (time_t) NGX_ERROR) {
236
+ goto invalid;
237
+ }
238
+
239
+ continue;
240
+ }
241
+
242
+ if (ngx_strcmp(value[i].data, "backup") == 0) {
243
+
244
+ if (!(uscf->flags & NGX_STREAM_UPSTREAM_BACKUP)) {
245
+ goto not_supported;
246
+ }
247
+
248
+ us->backup = 1;
249
+
250
+ continue;
251
+ }
252
+
253
+ if (ngx_strcmp(value[i].data, "down") == 0) {
254
+
255
+ if (!(uscf->flags & NGX_STREAM_UPSTREAM_DOWN)) {
256
+ goto not_supported;
257
+ }
258
+
259
+ us->down = 1;
260
+
261
+ continue;
262
+ }
263
+
264
+ goto invalid;
265
+ }
266
+
267
+ ngx_memzero(&u, sizeof(ngx_url_t));
268
+
269
+ u.url = value[1];
270
+
271
+ if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
272
+ if (u.err) {
273
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
274
+ "%s in upstream \"%V\"", u.err, &u.url);
275
+ }
276
+
277
+ return NGX_CONF_ERROR;
278
+ }
279
+
280
+ if (u.no_port) {
281
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
282
+ "no port in upstream \"%V\"", &u.url);
283
+ return NGX_CONF_ERROR;
284
+ }
285
+
286
+ us->name = u.url;
287
+ us->addrs = u.addrs;
288
+ us->naddrs = u.naddrs;
289
+ us->weight = weight;
290
+ us->max_fails = max_fails;
291
+ us->fail_timeout = fail_timeout;
292
+
293
+ return NGX_CONF_OK;
294
+
295
+ invalid:
296
+
297
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
298
+ "invalid parameter \"%V\"", &value[i]);
299
+
300
+ return NGX_CONF_ERROR;
301
+
302
+ not_supported:
303
+
304
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
305
+ "balancing method does not support parameter \"%V\"",
306
+ &value[i]);
307
+
308
+ return NGX_CONF_ERROR;
309
+ }
310
+
311
+
312
+ ngx_stream_upstream_srv_conf_t *
313
+ ngx_stream_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
314
+ {
315
+ ngx_uint_t i;
316
+ ngx_stream_upstream_server_t *us;
317
+ ngx_stream_upstream_srv_conf_t *uscf, **uscfp;
318
+ ngx_stream_upstream_main_conf_t *umcf;
319
+
320
+ if (!(flags & NGX_STREAM_UPSTREAM_CREATE)) {
321
+
322
+ if (ngx_parse_url(cf->pool, u) != NGX_OK) {
323
+ if (u->err) {
324
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
325
+ "%s in upstream \"%V\"", u->err, &u->url);
326
+ }
327
+
328
+ return NULL;
329
+ }
330
+ }
331
+
332
+ umcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_upstream_module);
333
+
334
+ uscfp = umcf->upstreams.elts;
335
+
336
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
337
+
338
+ if (uscfp[i]->host.len != u->host.len
339
+ || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len)
340
+ != 0)
341
+ {
342
+ continue;
343
+ }
344
+
345
+ if ((flags & NGX_STREAM_UPSTREAM_CREATE)
346
+ && (uscfp[i]->flags & NGX_STREAM_UPSTREAM_CREATE))
347
+ {
348
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
349
+ "duplicate upstream \"%V\"", &u->host);
350
+ return NULL;
351
+ }
352
+
353
+ if ((uscfp[i]->flags & NGX_STREAM_UPSTREAM_CREATE) && !u->no_port) {
354
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
355
+ "upstream \"%V\" may not have port %d",
356
+ &u->host, u->port);
357
+ return NULL;
358
+ }
359
+
360
+ if ((flags & NGX_STREAM_UPSTREAM_CREATE) && !uscfp[i]->no_port) {
361
+ ngx_log_error(NGX_LOG_WARN, cf->log, 0,
362
+ "upstream \"%V\" may not have port %d in %s:%ui",
363
+ &u->host, uscfp[i]->port,
364
+ uscfp[i]->file_name, uscfp[i]->line);
365
+ return NULL;
366
+ }
367
+
368
+ if (uscfp[i]->port != u->port) {
369
+ continue;
370
+ }
371
+
372
+ if (flags & NGX_STREAM_UPSTREAM_CREATE) {
373
+ uscfp[i]->flags = flags;
374
+ }
375
+
376
+ return uscfp[i];
377
+ }
378
+
379
+ uscf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_upstream_srv_conf_t));
380
+ if (uscf == NULL) {
381
+ return NULL;
382
+ }
383
+
384
+ uscf->flags = flags;
385
+ uscf->host = u->host;
386
+ uscf->file_name = cf->conf_file->file.name.data;
387
+ uscf->line = cf->conf_file->line;
388
+ uscf->port = u->port;
389
+ uscf->no_port = u->no_port;
390
+
391
+ if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {
392
+ uscf->servers = ngx_array_create(cf->pool, 1,
393
+ sizeof(ngx_stream_upstream_server_t));
394
+ if (uscf->servers == NULL) {
395
+ return NULL;
396
+ }
397
+
398
+ us = ngx_array_push(uscf->servers);
399
+ if (us == NULL) {
400
+ return NULL;
401
+ }
402
+
403
+ ngx_memzero(us, sizeof(ngx_stream_upstream_server_t));
404
+
405
+ us->addrs = u->addrs;
406
+ us->naddrs = 1;
407
+ }
408
+
409
+ uscfp = ngx_array_push(&umcf->upstreams);
410
+ if (uscfp == NULL) {
411
+ return NULL;
412
+ }
413
+
414
+ *uscfp = uscf;
415
+
416
+ return uscf;
417
+ }
418
+
419
+
420
+ static void *
421
+ ngx_stream_upstream_create_main_conf(ngx_conf_t *cf)
422
+ {
423
+ ngx_stream_upstream_main_conf_t *umcf;
424
+
425
+ umcf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_upstream_main_conf_t));
426
+ if (umcf == NULL) {
427
+ return NULL;
428
+ }
429
+
430
+ if (ngx_array_init(&umcf->upstreams, cf->pool, 4,
431
+ sizeof(ngx_stream_upstream_srv_conf_t *))
432
+ != NGX_OK)
433
+ {
434
+ return NULL;
435
+ }
436
+
437
+ return umcf;
438
+ }
439
+
440
+
441
+ static char *
442
+ ngx_stream_upstream_init_main_conf(ngx_conf_t *cf, void *conf)
443
+ {
444
+ ngx_stream_upstream_main_conf_t *umcf = conf;
445
+
446
+ ngx_uint_t i;
447
+ ngx_stream_upstream_init_pt init;
448
+ ngx_stream_upstream_srv_conf_t **uscfp;
449
+
450
+ uscfp = umcf->upstreams.elts;
451
+
452
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
453
+
454
+ init = uscfp[i]->peer.init_upstream
455
+ ? uscfp[i]->peer.init_upstream
456
+ : ngx_stream_upstream_init_round_robin;
457
+
458
+ if (init(cf, uscfp[i]) != NGX_OK) {
459
+ return NGX_CONF_ERROR;
460
+ }
461
+ }
462
+
463
+ return NGX_CONF_OK;
464
+ }