nginxtra 1.0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (363) hide show
  1. data/VERSION +1 -0
  2. data/bin/nginxtra +5 -0
  3. data/lib/nginxtra.rb +12 -0
  4. data/lib/nginxtra/action.rb +36 -0
  5. data/lib/nginxtra/actions/compile.rb +60 -0
  6. data/lib/nginxtra/actions/install.rb +99 -0
  7. data/lib/nginxtra/actions/reload.rb +14 -0
  8. data/lib/nginxtra/actions/restart.rb +15 -0
  9. data/lib/nginxtra/actions/start.rb +53 -0
  10. data/lib/nginxtra/actions/status.rb +31 -0
  11. data/lib/nginxtra/actions/stop.rb +14 -0
  12. data/lib/nginxtra/cli.rb +77 -0
  13. data/lib/nginxtra/config.rb +339 -0
  14. data/lib/nginxtra/error.rb +13 -0
  15. data/lib/nginxtra/status.rb +57 -0
  16. data/src/nginx/CHANGES +5630 -0
  17. data/src/nginx/CHANGES.ru +5716 -0
  18. data/src/nginx/LICENSE +25 -0
  19. data/src/nginx/README +3 -0
  20. data/src/nginx/auto/cc/acc +15 -0
  21. data/src/nginx/auto/cc/bcc +72 -0
  22. data/src/nginx/auto/cc/ccc +46 -0
  23. data/src/nginx/auto/cc/conf +189 -0
  24. data/src/nginx/auto/cc/gcc +183 -0
  25. data/src/nginx/auto/cc/icc +121 -0
  26. data/src/nginx/auto/cc/msvc +138 -0
  27. data/src/nginx/auto/cc/name +101 -0
  28. data/src/nginx/auto/cc/owc +104 -0
  29. data/src/nginx/auto/cc/sunc +158 -0
  30. data/src/nginx/auto/define +12 -0
  31. data/src/nginx/auto/endianess +45 -0
  32. data/src/nginx/auto/feature +123 -0
  33. data/src/nginx/auto/have +12 -0
  34. data/src/nginx/auto/have_headers +12 -0
  35. data/src/nginx/auto/headers +13 -0
  36. data/src/nginx/auto/include +61 -0
  37. data/src/nginx/auto/init +51 -0
  38. data/src/nginx/auto/install +184 -0
  39. data/src/nginx/auto/lib/conf +83 -0
  40. data/src/nginx/auto/lib/geoip/conf +79 -0
  41. data/src/nginx/auto/lib/google-perftools/conf +45 -0
  42. data/src/nginx/auto/lib/libatomic/conf +43 -0
  43. data/src/nginx/auto/lib/libatomic/make +14 -0
  44. data/src/nginx/auto/lib/libgd/conf +83 -0
  45. data/src/nginx/auto/lib/libxslt/conf +156 -0
  46. data/src/nginx/auto/lib/make +32 -0
  47. data/src/nginx/auto/lib/md5/conf +103 -0
  48. data/src/nginx/auto/lib/md5/make +96 -0
  49. data/src/nginx/auto/lib/md5/makefile.bcc +22 -0
  50. data/src/nginx/auto/lib/md5/makefile.msvc +22 -0
  51. data/src/nginx/auto/lib/md5/makefile.owc +11 -0
  52. data/src/nginx/auto/lib/openssl/conf +74 -0
  53. data/src/nginx/auto/lib/openssl/make +67 -0
  54. data/src/nginx/auto/lib/openssl/makefile.bcc +18 -0
  55. data/src/nginx/auto/lib/openssl/makefile.msvc +14 -0
  56. data/src/nginx/auto/lib/pcre/conf +180 -0
  57. data/src/nginx/auto/lib/pcre/make +64 -0
  58. data/src/nginx/auto/lib/pcre/makefile.bcc +26 -0
  59. data/src/nginx/auto/lib/pcre/makefile.msvc +22 -0
  60. data/src/nginx/auto/lib/pcre/makefile.owc +24 -0
  61. data/src/nginx/auto/lib/perl/conf +60 -0
  62. data/src/nginx/auto/lib/perl/make +36 -0
  63. data/src/nginx/auto/lib/sha1/conf +79 -0
  64. data/src/nginx/auto/lib/sha1/make +96 -0
  65. data/src/nginx/auto/lib/sha1/makefile.bcc +22 -0
  66. data/src/nginx/auto/lib/sha1/makefile.msvc +22 -0
  67. data/src/nginx/auto/lib/sha1/makefile.owc +11 -0
  68. data/src/nginx/auto/lib/test +40 -0
  69. data/src/nginx/auto/lib/zlib/conf +76 -0
  70. data/src/nginx/auto/lib/zlib/make +114 -0
  71. data/src/nginx/auto/lib/zlib/makefile.bcc +15 -0
  72. data/src/nginx/auto/lib/zlib/makefile.msvc +14 -0
  73. data/src/nginx/auto/lib/zlib/makefile.owc +14 -0
  74. data/src/nginx/auto/lib/zlib/patch.zlib.h +10 -0
  75. data/src/nginx/auto/make +417 -0
  76. data/src/nginx/auto/modules +479 -0
  77. data/src/nginx/auto/nohave +12 -0
  78. data/src/nginx/auto/options +490 -0
  79. data/src/nginx/auto/os/conf +105 -0
  80. data/src/nginx/auto/os/darwin +116 -0
  81. data/src/nginx/auto/os/freebsd +136 -0
  82. data/src/nginx/auto/os/linux +152 -0
  83. data/src/nginx/auto/os/solaris +60 -0
  84. data/src/nginx/auto/os/win32 +29 -0
  85. data/src/nginx/auto/sources +518 -0
  86. data/src/nginx/auto/stubs +8 -0
  87. data/src/nginx/auto/summary +114 -0
  88. data/src/nginx/auto/types/sizeof +83 -0
  89. data/src/nginx/auto/types/typedef +77 -0
  90. data/src/nginx/auto/types/uintptr_t +42 -0
  91. data/src/nginx/auto/types/value +12 -0
  92. data/src/nginx/auto/unix +719 -0
  93. data/src/nginx/conf/fastcgi.conf +24 -0
  94. data/src/nginx/conf/fastcgi_params +23 -0
  95. data/src/nginx/conf/koi-utf +109 -0
  96. data/src/nginx/conf/koi-win +103 -0
  97. data/src/nginx/conf/mime.types +80 -0
  98. data/src/nginx/conf/nginx.conf +118 -0
  99. data/src/nginx/conf/scgi_params +15 -0
  100. data/src/nginx/conf/uwsgi_params +15 -0
  101. data/src/nginx/conf/win-utf +126 -0
  102. data/src/nginx/configure +108 -0
  103. data/src/nginx/contrib/README +15 -0
  104. data/src/nginx/contrib/geo2nginx.pl +58 -0
  105. data/src/nginx/contrib/unicode2nginx/koi-utf +131 -0
  106. data/src/nginx/contrib/unicode2nginx/unicode-to-nginx.pl +45 -0
  107. data/src/nginx/contrib/unicode2nginx/win-utf +130 -0
  108. data/src/nginx/html/50x.html +18 -0
  109. data/src/nginx/html/index.html +8 -0
  110. data/src/nginx/man/nginx.8 +202 -0
  111. data/src/nginx/src/core/nginx.c +1333 -0
  112. data/src/nginx/src/core/nginx.h +20 -0
  113. data/src/nginx/src/core/ngx_array.c +147 -0
  114. data/src/nginx/src/core/ngx_array.h +53 -0
  115. data/src/nginx/src/core/ngx_buf.c +218 -0
  116. data/src/nginx/src/core/ngx_buf.h +162 -0
  117. data/src/nginx/src/core/ngx_conf_file.c +1506 -0
  118. data/src/nginx/src/core/ngx_conf_file.h +348 -0
  119. data/src/nginx/src/core/ngx_config.h +134 -0
  120. data/src/nginx/src/core/ngx_connection.c +1074 -0
  121. data/src/nginx/src/core/ngx_connection.h +195 -0
  122. data/src/nginx/src/core/ngx_core.h +95 -0
  123. data/src/nginx/src/core/ngx_cpuinfo.c +139 -0
  124. data/src/nginx/src/core/ngx_crc.h +39 -0
  125. data/src/nginx/src/core/ngx_crc32.c +129 -0
  126. data/src/nginx/src/core/ngx_crc32.h +79 -0
  127. data/src/nginx/src/core/ngx_crypt.c +238 -0
  128. data/src/nginx/src/core/ngx_crypt.h +20 -0
  129. data/src/nginx/src/core/ngx_cycle.c +1379 -0
  130. data/src/nginx/src/core/ngx_cycle.h +142 -0
  131. data/src/nginx/src/core/ngx_file.c +993 -0
  132. data/src/nginx/src/core/ngx_file.h +151 -0
  133. data/src/nginx/src/core/ngx_hash.c +976 -0
  134. data/src/nginx/src/core/ngx_hash.h +122 -0
  135. data/src/nginx/src/core/ngx_inet.c +1008 -0
  136. data/src/nginx/src/core/ngx_inet.h +120 -0
  137. data/src/nginx/src/core/ngx_list.c +71 -0
  138. data/src/nginx/src/core/ngx_list.h +83 -0
  139. data/src/nginx/src/core/ngx_log.c +459 -0
  140. data/src/nginx/src/core/ngx_log.h +250 -0
  141. data/src/nginx/src/core/ngx_md5.c +289 -0
  142. data/src/nginx/src/core/ngx_md5.h +60 -0
  143. data/src/nginx/src/core/ngx_murmurhash.c +50 -0
  144. data/src/nginx/src/core/ngx_murmurhash.h +19 -0
  145. data/src/nginx/src/core/ngx_open_file_cache.c +882 -0
  146. data/src/nginx/src/core/ngx_open_file_cache.h +119 -0
  147. data/src/nginx/src/core/ngx_output_chain.c +673 -0
  148. data/src/nginx/src/core/ngx_palloc.c +433 -0
  149. data/src/nginx/src/core/ngx_palloc.h +95 -0
  150. data/src/nginx/src/core/ngx_parse.c +249 -0
  151. data/src/nginx/src/core/ngx_parse.h +24 -0
  152. data/src/nginx/src/core/ngx_queue.c +80 -0
  153. data/src/nginx/src/core/ngx_queue.h +112 -0
  154. data/src/nginx/src/core/ngx_radix_tree.c +291 -0
  155. data/src/nginx/src/core/ngx_radix_tree.h +46 -0
  156. data/src/nginx/src/core/ngx_rbtree.c +383 -0
  157. data/src/nginx/src/core/ngx_rbtree.h +84 -0
  158. data/src/nginx/src/core/ngx_regex.c +206 -0
  159. data/src/nginx/src/core/ngx_regex.h +56 -0
  160. data/src/nginx/src/core/ngx_resolver.c +2201 -0
  161. data/src/nginx/src/core/ngx_resolver.h +149 -0
  162. data/src/nginx/src/core/ngx_sha1.h +31 -0
  163. data/src/nginx/src/core/ngx_shmtx.c +284 -0
  164. data/src/nginx/src/core/ngx_shmtx.h +38 -0
  165. data/src/nginx/src/core/ngx_slab.c +701 -0
  166. data/src/nginx/src/core/ngx_slab.h +54 -0
  167. data/src/nginx/src/core/ngx_spinlock.c +53 -0
  168. data/src/nginx/src/core/ngx_string.c +1837 -0
  169. data/src/nginx/src/core/ngx_string.h +231 -0
  170. data/src/nginx/src/core/ngx_times.c +407 -0
  171. data/src/nginx/src/core/ngx_times.h +51 -0
  172. data/src/nginx/src/event/modules/ngx_aio_module.c +171 -0
  173. data/src/nginx/src/event/modules/ngx_devpoll_module.c +569 -0
  174. data/src/nginx/src/event/modules/ngx_epoll_module.c +833 -0
  175. data/src/nginx/src/event/modules/ngx_eventport_module.c +602 -0
  176. data/src/nginx/src/event/modules/ngx_kqueue_module.c +785 -0
  177. data/src/nginx/src/event/modules/ngx_poll_module.c +443 -0
  178. data/src/nginx/src/event/modules/ngx_rtsig_module.c +735 -0
  179. data/src/nginx/src/event/modules/ngx_select_module.c +435 -0
  180. data/src/nginx/src/event/modules/ngx_win32_select_module.c +400 -0
  181. data/src/nginx/src/event/ngx_event.c +1275 -0
  182. data/src/nginx/src/event/ngx_event.h +573 -0
  183. data/src/nginx/src/event/ngx_event_accept.c +428 -0
  184. data/src/nginx/src/event/ngx_event_busy_lock.c +286 -0
  185. data/src/nginx/src/event/ngx_event_busy_lock.h +65 -0
  186. data/src/nginx/src/event/ngx_event_connect.c +258 -0
  187. data/src/nginx/src/event/ngx_event_connect.h +76 -0
  188. data/src/nginx/src/event/ngx_event_mutex.c +70 -0
  189. data/src/nginx/src/event/ngx_event_openssl.c +2382 -0
  190. data/src/nginx/src/event/ngx_event_openssl.h +162 -0
  191. data/src/nginx/src/event/ngx_event_pipe.c +996 -0
  192. data/src/nginx/src/event/ngx_event_pipe.h +95 -0
  193. data/src/nginx/src/event/ngx_event_posted.c +173 -0
  194. data/src/nginx/src/event/ngx_event_posted.h +75 -0
  195. data/src/nginx/src/event/ngx_event_timer.c +159 -0
  196. data/src/nginx/src/event/ngx_event_timer.h +102 -0
  197. data/src/nginx/src/http/modules/ngx_http_access_module.c +384 -0
  198. data/src/nginx/src/http/modules/ngx_http_addition_filter_module.c +250 -0
  199. data/src/nginx/src/http/modules/ngx_http_auth_basic_module.c +478 -0
  200. data/src/nginx/src/http/modules/ngx_http_autoindex_module.c +701 -0
  201. data/src/nginx/src/http/modules/ngx_http_browser_module.c +713 -0
  202. data/src/nginx/src/http/modules/ngx_http_charset_filter_module.c +1681 -0
  203. data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +242 -0
  204. data/src/nginx/src/http/modules/ngx_http_dav_module.c +1141 -0
  205. data/src/nginx/src/http/modules/ngx_http_degradation_module.c +243 -0
  206. data/src/nginx/src/http/modules/ngx_http_empty_gif_module.c +140 -0
  207. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +2916 -0
  208. data/src/nginx/src/http/modules/ngx_http_flv_module.c +254 -0
  209. data/src/nginx/src/http/modules/ngx_http_geo_module.c +1441 -0
  210. data/src/nginx/src/http/modules/ngx_http_geoip_module.c +671 -0
  211. data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +1206 -0
  212. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +299 -0
  213. data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +616 -0
  214. data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1489 -0
  215. data/src/nginx/src/http/modules/ngx_http_index_module.c +516 -0
  216. data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +809 -0
  217. data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +553 -0
  218. data/src/nginx/src/http/modules/ngx_http_log_module.c +1357 -0
  219. data/src/nginx/src/http/modules/ngx_http_map_module.c +575 -0
  220. data/src/nginx/src/http/modules/ngx_http_memcached_module.c +624 -0
  221. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +3000 -0
  222. data/src/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +143 -0
  223. data/src/nginx/src/http/modules/ngx_http_proxy_module.c +2831 -0
  224. data/src/nginx/src/http/modules/ngx_http_random_index_module.c +317 -0
  225. data/src/nginx/src/http/modules/ngx_http_range_filter_module.c +855 -0
  226. data/src/nginx/src/http/modules/ngx_http_realip_module.c +476 -0
  227. data/src/nginx/src/http/modules/ngx_http_referer_module.c +613 -0
  228. data/src/nginx/src/http/modules/ngx_http_rewrite_module.c +1019 -0
  229. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +1714 -0
  230. data/src/nginx/src/http/modules/ngx_http_secure_link_module.c +355 -0
  231. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +242 -0
  232. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +2913 -0
  233. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.h +114 -0
  234. data/src/nginx/src/http/modules/ngx_http_ssl_module.c +652 -0
  235. data/src/nginx/src/http/modules/ngx_http_ssl_module.h +52 -0
  236. data/src/nginx/src/http/modules/ngx_http_static_module.c +278 -0
  237. data/src/nginx/src/http/modules/ngx_http_stub_status_module.c +144 -0
  238. data/src/nginx/src/http/modules/ngx_http_sub_filter_module.c +716 -0
  239. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +237 -0
  240. data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +846 -0
  241. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +1774 -0
  242. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +984 -0
  243. data/src/nginx/src/http/modules/perl/Makefile.PL +42 -0
  244. data/src/nginx/src/http/modules/perl/nginx.pm +137 -0
  245. data/src/nginx/src/http/modules/perl/nginx.xs +986 -0
  246. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.c +1076 -0
  247. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.h +67 -0
  248. data/src/nginx/src/http/modules/perl/typemap +3 -0
  249. data/src/nginx/src/http/ngx_http.c +2073 -0
  250. data/src/nginx/src/http/ngx_http.h +160 -0
  251. data/src/nginx/src/http/ngx_http_busy_lock.c +307 -0
  252. data/src/nginx/src/http/ngx_http_busy_lock.h +54 -0
  253. data/src/nginx/src/http/ngx_http_cache.h +148 -0
  254. data/src/nginx/src/http/ngx_http_config.h +75 -0
  255. data/src/nginx/src/http/ngx_http_copy_filter_module.c +300 -0
  256. data/src/nginx/src/http/ngx_http_core_module.c +4736 -0
  257. data/src/nginx/src/http/ngx_http_core_module.h +541 -0
  258. data/src/nginx/src/http/ngx_http_file_cache.c +1715 -0
  259. data/src/nginx/src/http/ngx_http_header_filter_module.c +623 -0
  260. data/src/nginx/src/http/ngx_http_parse.c +1734 -0
  261. data/src/nginx/src/http/ngx_http_parse_time.c +276 -0
  262. data/src/nginx/src/http/ngx_http_postpone_filter_module.c +178 -0
  263. data/src/nginx/src/http/ngx_http_request.c +3181 -0
  264. data/src/nginx/src/http/ngx_http_request.h +573 -0
  265. data/src/nginx/src/http/ngx_http_request_body.c +644 -0
  266. data/src/nginx/src/http/ngx_http_script.c +1752 -0
  267. data/src/nginx/src/http/ngx_http_script.h +257 -0
  268. data/src/nginx/src/http/ngx_http_special_response.c +789 -0
  269. data/src/nginx/src/http/ngx_http_upstream.c +4555 -0
  270. data/src/nginx/src/http/ngx_http_upstream.h +350 -0
  271. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +791 -0
  272. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +85 -0
  273. data/src/nginx/src/http/ngx_http_variables.c +2053 -0
  274. data/src/nginx/src/http/ngx_http_variables.h +115 -0
  275. data/src/nginx/src/http/ngx_http_write_filter_module.c +315 -0
  276. data/src/nginx/src/mail/ngx_mail.c +542 -0
  277. data/src/nginx/src/mail/ngx_mail.h +407 -0
  278. data/src/nginx/src/mail/ngx_mail_auth_http_module.c +1452 -0
  279. data/src/nginx/src/mail/ngx_mail_core_module.c +553 -0
  280. data/src/nginx/src/mail/ngx_mail_handler.c +773 -0
  281. data/src/nginx/src/mail/ngx_mail_imap_handler.c +457 -0
  282. data/src/nginx/src/mail/ngx_mail_imap_module.c +253 -0
  283. data/src/nginx/src/mail/ngx_mail_imap_module.h +39 -0
  284. data/src/nginx/src/mail/ngx_mail_parse.c +885 -0
  285. data/src/nginx/src/mail/ngx_mail_pop3_handler.c +500 -0
  286. data/src/nginx/src/mail/ngx_mail_pop3_module.c +264 -0
  287. data/src/nginx/src/mail/ngx_mail_pop3_module.h +38 -0
  288. data/src/nginx/src/mail/ngx_mail_proxy_module.c +1089 -0
  289. data/src/nginx/src/mail/ngx_mail_smtp_handler.c +872 -0
  290. data/src/nginx/src/mail/ngx_mail_smtp_module.c +308 -0
  291. data/src/nginx/src/mail/ngx_mail_smtp_module.h +45 -0
  292. data/src/nginx/src/mail/ngx_mail_ssl_module.c +491 -0
  293. data/src/nginx/src/mail/ngx_mail_ssl_module.h +52 -0
  294. data/src/nginx/src/misc/ngx_cpp_test_module.cpp +27 -0
  295. data/src/nginx/src/misc/ngx_google_perftools_module.c +126 -0
  296. data/src/nginx/src/os/unix/ngx_aio_read.c +109 -0
  297. data/src/nginx/src/os/unix/ngx_aio_read_chain.c +78 -0
  298. data/src/nginx/src/os/unix/ngx_aio_write.c +109 -0
  299. data/src/nginx/src/os/unix/ngx_aio_write_chain.c +100 -0
  300. data/src/nginx/src/os/unix/ngx_alloc.c +90 -0
  301. data/src/nginx/src/os/unix/ngx_alloc.h +45 -0
  302. data/src/nginx/src/os/unix/ngx_atomic.h +311 -0
  303. data/src/nginx/src/os/unix/ngx_channel.c +258 -0
  304. data/src/nginx/src/os/unix/ngx_channel.h +34 -0
  305. data/src/nginx/src/os/unix/ngx_daemon.c +69 -0
  306. data/src/nginx/src/os/unix/ngx_darwin.h +20 -0
  307. data/src/nginx/src/os/unix/ngx_darwin_config.h +96 -0
  308. data/src/nginx/src/os/unix/ngx_darwin_init.c +166 -0
  309. data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +366 -0
  310. data/src/nginx/src/os/unix/ngx_errno.c +87 -0
  311. data/src/nginx/src/os/unix/ngx_errno.h +68 -0
  312. data/src/nginx/src/os/unix/ngx_file_aio_read.c +208 -0
  313. data/src/nginx/src/os/unix/ngx_files.c +566 -0
  314. data/src/nginx/src/os/unix/ngx_files.h +343 -0
  315. data/src/nginx/src/os/unix/ngx_freebsd.h +24 -0
  316. data/src/nginx/src/os/unix/ngx_freebsd_config.h +119 -0
  317. data/src/nginx/src/os/unix/ngx_freebsd_init.c +259 -0
  318. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +756 -0
  319. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +122 -0
  320. data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +436 -0
  321. data/src/nginx/src/os/unix/ngx_gcc_atomic_amd64.h +82 -0
  322. data/src/nginx/src/os/unix/ngx_gcc_atomic_ppc.h +155 -0
  323. data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +82 -0
  324. data/src/nginx/src/os/unix/ngx_gcc_atomic_x86.h +127 -0
  325. data/src/nginx/src/os/unix/ngx_linux.h +18 -0
  326. data/src/nginx/src/os/unix/ngx_linux_aio_read.c +137 -0
  327. data/src/nginx/src/os/unix/ngx_linux_config.h +117 -0
  328. data/src/nginx/src/os/unix/ngx_linux_init.c +91 -0
  329. data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +378 -0
  330. data/src/nginx/src/os/unix/ngx_os.h +84 -0
  331. data/src/nginx/src/os/unix/ngx_posix_config.h +153 -0
  332. data/src/nginx/src/os/unix/ngx_posix_init.c +124 -0
  333. data/src/nginx/src/os/unix/ngx_process.c +590 -0
  334. data/src/nginx/src/os/unix/ngx_process.h +87 -0
  335. data/src/nginx/src/os/unix/ngx_process_cycle.c +1390 -0
  336. data/src/nginx/src/os/unix/ngx_process_cycle.h +61 -0
  337. data/src/nginx/src/os/unix/ngx_pthread_thread.c +278 -0
  338. data/src/nginx/src/os/unix/ngx_readv_chain.c +258 -0
  339. data/src/nginx/src/os/unix/ngx_recv.c +180 -0
  340. data/src/nginx/src/os/unix/ngx_send.c +73 -0
  341. data/src/nginx/src/os/unix/ngx_setproctitle.c +135 -0
  342. data/src/nginx/src/os/unix/ngx_setproctitle.h +52 -0
  343. data/src/nginx/src/os/unix/ngx_shmem.c +126 -0
  344. data/src/nginx/src/os/unix/ngx_shmem.h +29 -0
  345. data/src/nginx/src/os/unix/ngx_socket.c +116 -0
  346. data/src/nginx/src/os/unix/ngx_socket.h +64 -0
  347. data/src/nginx/src/os/unix/ngx_solaris.h +16 -0
  348. data/src/nginx/src/os/unix/ngx_solaris_config.h +107 -0
  349. data/src/nginx/src/os/unix/ngx_solaris_init.c +75 -0
  350. data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +251 -0
  351. data/src/nginx/src/os/unix/ngx_sunpro_amd64.il +43 -0
  352. data/src/nginx/src/os/unix/ngx_sunpro_atomic_sparc64.h +61 -0
  353. data/src/nginx/src/os/unix/ngx_sunpro_sparc64.il +36 -0
  354. data/src/nginx/src/os/unix/ngx_sunpro_x86.il +44 -0
  355. data/src/nginx/src/os/unix/ngx_thread.h +128 -0
  356. data/src/nginx/src/os/unix/ngx_time.c +104 -0
  357. data/src/nginx/src/os/unix/ngx_time.h +66 -0
  358. data/src/nginx/src/os/unix/ngx_udp_recv.c +115 -0
  359. data/src/nginx/src/os/unix/ngx_user.c +109 -0
  360. data/src/nginx/src/os/unix/ngx_user.h +24 -0
  361. data/src/nginx/src/os/unix/ngx_writev_chain.c +181 -0
  362. data/src/nginx/src/os/unix/rfork_thread.S +73 -0
  363. metadata +419 -0
@@ -0,0 +1,143 @@
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_http.h>
11
+
12
+
13
+ static ngx_int_t ngx_http_test_precondition(ngx_http_request_t *r);
14
+ static ngx_int_t ngx_http_test_not_modified(ngx_http_request_t *r);
15
+ static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf);
16
+
17
+
18
+ static ngx_http_module_t ngx_http_not_modified_filter_module_ctx = {
19
+ NULL, /* preconfiguration */
20
+ ngx_http_not_modified_filter_init, /* postconfiguration */
21
+
22
+ NULL, /* create main configuration */
23
+ NULL, /* init main configuration */
24
+
25
+ NULL, /* create server configuration */
26
+ NULL, /* merge server configuration */
27
+
28
+ NULL, /* create location configuration */
29
+ NULL /* merge location configuration */
30
+ };
31
+
32
+
33
+ ngx_module_t ngx_http_not_modified_filter_module = {
34
+ NGX_MODULE_V1,
35
+ &ngx_http_not_modified_filter_module_ctx, /* module context */
36
+ NULL, /* module directives */
37
+ NGX_HTTP_MODULE, /* module type */
38
+ NULL, /* init master */
39
+ NULL, /* init module */
40
+ NULL, /* init process */
41
+ NULL, /* init thread */
42
+ NULL, /* exit thread */
43
+ NULL, /* exit process */
44
+ NULL, /* exit master */
45
+ NGX_MODULE_V1_PADDING
46
+ };
47
+
48
+
49
+ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
50
+
51
+
52
+ static ngx_int_t
53
+ ngx_http_not_modified_header_filter(ngx_http_request_t *r)
54
+ {
55
+ if (r->headers_out.status != NGX_HTTP_OK
56
+ || r != r->main
57
+ || r->headers_out.last_modified_time == -1)
58
+ {
59
+ return ngx_http_next_header_filter(r);
60
+ }
61
+
62
+ if (r->headers_in.if_unmodified_since) {
63
+ return ngx_http_test_precondition(r);
64
+ }
65
+
66
+ if (r->headers_in.if_modified_since) {
67
+ return ngx_http_test_not_modified(r);
68
+ }
69
+
70
+ return ngx_http_next_header_filter(r);
71
+ }
72
+
73
+
74
+ static ngx_int_t
75
+ ngx_http_test_precondition(ngx_http_request_t *r)
76
+ {
77
+ time_t iums;
78
+
79
+ iums = ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data,
80
+ r->headers_in.if_unmodified_since->value.len);
81
+
82
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
83
+ "http iums:%d lm:%d", iums, r->headers_out.last_modified_time);
84
+
85
+ if (iums >= r->headers_out.last_modified_time) {
86
+ return ngx_http_next_header_filter(r);
87
+ }
88
+
89
+ return ngx_http_filter_finalize_request(r, NULL,
90
+ NGX_HTTP_PRECONDITION_FAILED);
91
+ }
92
+
93
+
94
+ static ngx_int_t
95
+ ngx_http_test_not_modified(ngx_http_request_t *r)
96
+ {
97
+ time_t ims;
98
+ ngx_http_core_loc_conf_t *clcf;
99
+
100
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
101
+
102
+ if (clcf->if_modified_since == NGX_HTTP_IMS_OFF) {
103
+ return ngx_http_next_header_filter(r);
104
+ }
105
+
106
+ ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data,
107
+ r->headers_in.if_modified_since->value.len);
108
+
109
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
110
+ "http ims:%d lm:%d", ims, r->headers_out.last_modified_time);
111
+
112
+ if (ims != r->headers_out.last_modified_time) {
113
+
114
+ if (clcf->if_modified_since == NGX_HTTP_IMS_EXACT
115
+ || ims < r->headers_out.last_modified_time)
116
+ {
117
+ return ngx_http_next_header_filter(r);
118
+ }
119
+ }
120
+
121
+ r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
122
+ r->headers_out.status_line.len = 0;
123
+ r->headers_out.content_type.len = 0;
124
+ ngx_http_clear_content_length(r);
125
+ ngx_http_clear_accept_ranges(r);
126
+
127
+ if (r->headers_out.content_encoding) {
128
+ r->headers_out.content_encoding->hash = 0;
129
+ r->headers_out.content_encoding = NULL;
130
+ }
131
+
132
+ return ngx_http_next_header_filter(r);
133
+ }
134
+
135
+
136
+ static ngx_int_t
137
+ ngx_http_not_modified_filter_init(ngx_conf_t *cf)
138
+ {
139
+ ngx_http_next_header_filter = ngx_http_top_header_filter;
140
+ ngx_http_top_header_filter = ngx_http_not_modified_header_filter;
141
+
142
+ return NGX_OK;
143
+ }
@@ -0,0 +1,2831 @@
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_http.h>
11
+
12
+
13
+ typedef struct ngx_http_proxy_redirect_s ngx_http_proxy_redirect_t;
14
+
15
+ typedef ngx_int_t (*ngx_http_proxy_redirect_pt)(ngx_http_request_t *r,
16
+ ngx_table_elt_t *h, size_t prefix, ngx_http_proxy_redirect_t *pr);
17
+
18
+ struct ngx_http_proxy_redirect_s {
19
+ ngx_http_proxy_redirect_pt handler;
20
+ ngx_str_t redirect;
21
+
22
+ union {
23
+ ngx_str_t text;
24
+
25
+ struct {
26
+ void *lengths;
27
+ void *values;
28
+ } vars;
29
+
30
+ void *regex;
31
+ } replacement;
32
+ };
33
+
34
+
35
+ typedef struct {
36
+ ngx_str_t key_start;
37
+ ngx_str_t schema;
38
+ ngx_str_t host_header;
39
+ ngx_str_t port;
40
+ ngx_str_t uri;
41
+ } ngx_http_proxy_vars_t;
42
+
43
+
44
+ typedef struct {
45
+ ngx_http_upstream_conf_t upstream;
46
+
47
+ ngx_array_t *flushes;
48
+ ngx_array_t *body_set_len;
49
+ ngx_array_t *body_set;
50
+ ngx_array_t *headers_set_len;
51
+ ngx_array_t *headers_set;
52
+ ngx_hash_t headers_set_hash;
53
+
54
+ ngx_array_t *headers_source;
55
+
56
+ ngx_array_t *proxy_lengths;
57
+ ngx_array_t *proxy_values;
58
+
59
+ ngx_array_t *redirects;
60
+
61
+ ngx_str_t body_source;
62
+
63
+ ngx_str_t method;
64
+ ngx_str_t location;
65
+ ngx_str_t url;
66
+
67
+ #if (NGX_HTTP_CACHE)
68
+ ngx_http_complex_value_t cache_key;
69
+ #endif
70
+
71
+ ngx_http_proxy_vars_t vars;
72
+
73
+ ngx_flag_t redirect;
74
+
75
+ ngx_uint_t headers_hash_max_size;
76
+ ngx_uint_t headers_hash_bucket_size;
77
+ } ngx_http_proxy_loc_conf_t;
78
+
79
+
80
+ typedef struct {
81
+ ngx_http_status_t status;
82
+ ngx_http_proxy_vars_t vars;
83
+ size_t internal_body_length;
84
+ } ngx_http_proxy_ctx_t;
85
+
86
+
87
+ static ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r,
88
+ ngx_http_proxy_ctx_t *ctx, ngx_http_proxy_loc_conf_t *plcf);
89
+ #if (NGX_HTTP_CACHE)
90
+ static ngx_int_t ngx_http_proxy_create_key(ngx_http_request_t *r);
91
+ #endif
92
+ static ngx_int_t ngx_http_proxy_create_request(ngx_http_request_t *r);
93
+ static ngx_int_t ngx_http_proxy_reinit_request(ngx_http_request_t *r);
94
+ static ngx_int_t ngx_http_proxy_process_status_line(ngx_http_request_t *r);
95
+ static ngx_int_t ngx_http_proxy_process_header(ngx_http_request_t *r);
96
+ static void ngx_http_proxy_abort_request(ngx_http_request_t *r);
97
+ static void ngx_http_proxy_finalize_request(ngx_http_request_t *r,
98
+ ngx_int_t rc);
99
+
100
+ static ngx_int_t ngx_http_proxy_host_variable(ngx_http_request_t *r,
101
+ ngx_http_variable_value_t *v, uintptr_t data);
102
+ static ngx_int_t ngx_http_proxy_port_variable(ngx_http_request_t *r,
103
+ ngx_http_variable_value_t *v, uintptr_t data);
104
+ static ngx_int_t
105
+ ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r,
106
+ ngx_http_variable_value_t *v, uintptr_t data);
107
+ static ngx_int_t
108
+ ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r,
109
+ ngx_http_variable_value_t *v, uintptr_t data);
110
+ static ngx_int_t ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r,
111
+ ngx_table_elt_t *h, size_t prefix);
112
+
113
+ static ngx_int_t ngx_http_proxy_add_variables(ngx_conf_t *cf);
114
+ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf);
115
+ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
116
+ void *parent, void *child);
117
+ static ngx_int_t ngx_http_proxy_merge_headers(ngx_conf_t *cf,
118
+ ngx_http_proxy_loc_conf_t *conf, ngx_http_proxy_loc_conf_t *prev);
119
+
120
+ static char *ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd,
121
+ void *conf);
122
+ static char *ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd,
123
+ void *conf);
124
+ static char *ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd,
125
+ void *conf);
126
+ #if (NGX_HTTP_CACHE)
127
+ static char *ngx_http_proxy_cache(ngx_conf_t *cf, ngx_command_t *cmd,
128
+ void *conf);
129
+ static char *ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
130
+ void *conf);
131
+ #endif
132
+
133
+ static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data);
134
+
135
+ #if (NGX_HTTP_SSL)
136
+ static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf,
137
+ ngx_http_proxy_loc_conf_t *plcf);
138
+ #endif
139
+ static void ngx_http_proxy_set_vars(ngx_url_t *u, ngx_http_proxy_vars_t *v);
140
+
141
+
142
+ static ngx_conf_post_t ngx_http_proxy_lowat_post =
143
+ { ngx_http_proxy_lowat_check };
144
+
145
+
146
+ static ngx_conf_bitmask_t ngx_http_proxy_next_upstream_masks[] = {
147
+ { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
148
+ { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
149
+ { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
150
+ { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
151
+ { ngx_string("http_502"), NGX_HTTP_UPSTREAM_FT_HTTP_502 },
152
+ { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
153
+ { ngx_string("http_504"), NGX_HTTP_UPSTREAM_FT_HTTP_504 },
154
+ { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
155
+ { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
156
+ { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
157
+ { ngx_null_string, 0 }
158
+ };
159
+
160
+
161
+ ngx_module_t ngx_http_proxy_module;
162
+
163
+
164
+ static ngx_command_t ngx_http_proxy_commands[] = {
165
+
166
+ { ngx_string("proxy_pass"),
167
+ NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1,
168
+ ngx_http_proxy_pass,
169
+ NGX_HTTP_LOC_CONF_OFFSET,
170
+ 0,
171
+ NULL },
172
+
173
+ { ngx_string("proxy_redirect"),
174
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
175
+ ngx_http_proxy_redirect,
176
+ NGX_HTTP_LOC_CONF_OFFSET,
177
+ 0,
178
+ NULL },
179
+
180
+ { ngx_string("proxy_store"),
181
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
182
+ ngx_http_proxy_store,
183
+ NGX_HTTP_LOC_CONF_OFFSET,
184
+ 0,
185
+ NULL },
186
+
187
+ { ngx_string("proxy_store_access"),
188
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
189
+ ngx_conf_set_access_slot,
190
+ NGX_HTTP_LOC_CONF_OFFSET,
191
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.store_access),
192
+ NULL },
193
+
194
+ { ngx_string("proxy_buffering"),
195
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
196
+ ngx_conf_set_flag_slot,
197
+ NGX_HTTP_LOC_CONF_OFFSET,
198
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.buffering),
199
+ NULL },
200
+
201
+ { ngx_string("proxy_ignore_client_abort"),
202
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
203
+ ngx_conf_set_flag_slot,
204
+ NGX_HTTP_LOC_CONF_OFFSET,
205
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_client_abort),
206
+ NULL },
207
+
208
+ { ngx_string("proxy_bind"),
209
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
210
+ ngx_http_upstream_bind_set_slot,
211
+ NGX_HTTP_LOC_CONF_OFFSET,
212
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.local),
213
+ NULL },
214
+
215
+ { ngx_string("proxy_connect_timeout"),
216
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
217
+ ngx_conf_set_msec_slot,
218
+ NGX_HTTP_LOC_CONF_OFFSET,
219
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.connect_timeout),
220
+ NULL },
221
+
222
+ { ngx_string("proxy_send_timeout"),
223
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
224
+ ngx_conf_set_msec_slot,
225
+ NGX_HTTP_LOC_CONF_OFFSET,
226
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.send_timeout),
227
+ NULL },
228
+
229
+ { ngx_string("proxy_send_lowat"),
230
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
231
+ ngx_conf_set_size_slot,
232
+ NGX_HTTP_LOC_CONF_OFFSET,
233
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.send_lowat),
234
+ &ngx_http_proxy_lowat_post },
235
+
236
+ { ngx_string("proxy_intercept_errors"),
237
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
238
+ ngx_conf_set_flag_slot,
239
+ NGX_HTTP_LOC_CONF_OFFSET,
240
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.intercept_errors),
241
+ NULL },
242
+
243
+ { ngx_string("proxy_set_header"),
244
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
245
+ ngx_conf_set_keyval_slot,
246
+ NGX_HTTP_LOC_CONF_OFFSET,
247
+ offsetof(ngx_http_proxy_loc_conf_t, headers_source),
248
+ NULL },
249
+
250
+ { ngx_string("proxy_headers_hash_max_size"),
251
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
252
+ ngx_conf_set_num_slot,
253
+ NGX_HTTP_LOC_CONF_OFFSET,
254
+ offsetof(ngx_http_proxy_loc_conf_t, headers_hash_max_size),
255
+ NULL },
256
+
257
+ { ngx_string("proxy_headers_hash_bucket_size"),
258
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
259
+ ngx_conf_set_num_slot,
260
+ NGX_HTTP_LOC_CONF_OFFSET,
261
+ offsetof(ngx_http_proxy_loc_conf_t, headers_hash_bucket_size),
262
+ NULL },
263
+
264
+ { ngx_string("proxy_set_body"),
265
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
266
+ ngx_conf_set_str_slot,
267
+ NGX_HTTP_LOC_CONF_OFFSET,
268
+ offsetof(ngx_http_proxy_loc_conf_t, body_source),
269
+ NULL },
270
+
271
+ { ngx_string("proxy_method"),
272
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
273
+ ngx_conf_set_str_slot,
274
+ NGX_HTTP_LOC_CONF_OFFSET,
275
+ offsetof(ngx_http_proxy_loc_conf_t, method),
276
+ NULL },
277
+
278
+ { ngx_string("proxy_pass_request_headers"),
279
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
280
+ ngx_conf_set_flag_slot,
281
+ NGX_HTTP_LOC_CONF_OFFSET,
282
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_request_headers),
283
+ NULL },
284
+
285
+ { ngx_string("proxy_pass_request_body"),
286
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
287
+ ngx_conf_set_flag_slot,
288
+ NGX_HTTP_LOC_CONF_OFFSET,
289
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_request_body),
290
+ NULL },
291
+
292
+ { ngx_string("proxy_buffer_size"),
293
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
294
+ ngx_conf_set_size_slot,
295
+ NGX_HTTP_LOC_CONF_OFFSET,
296
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.buffer_size),
297
+ NULL },
298
+
299
+ { ngx_string("proxy_read_timeout"),
300
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
301
+ ngx_conf_set_msec_slot,
302
+ NGX_HTTP_LOC_CONF_OFFSET,
303
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.read_timeout),
304
+ NULL },
305
+
306
+ { ngx_string("proxy_buffers"),
307
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
308
+ ngx_conf_set_bufs_slot,
309
+ NGX_HTTP_LOC_CONF_OFFSET,
310
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.bufs),
311
+ NULL },
312
+
313
+ { ngx_string("proxy_busy_buffers_size"),
314
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
315
+ ngx_conf_set_size_slot,
316
+ NGX_HTTP_LOC_CONF_OFFSET,
317
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.busy_buffers_size_conf),
318
+ NULL },
319
+
320
+ #if (NGX_HTTP_CACHE)
321
+
322
+ { ngx_string("proxy_cache"),
323
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
324
+ ngx_http_proxy_cache,
325
+ NGX_HTTP_LOC_CONF_OFFSET,
326
+ 0,
327
+ NULL },
328
+
329
+ { ngx_string("proxy_cache_key"),
330
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
331
+ ngx_http_proxy_cache_key,
332
+ NGX_HTTP_LOC_CONF_OFFSET,
333
+ 0,
334
+ NULL },
335
+
336
+ { ngx_string("proxy_cache_path"),
337
+ NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
338
+ ngx_http_file_cache_set_slot,
339
+ 0,
340
+ 0,
341
+ &ngx_http_proxy_module },
342
+
343
+ { ngx_string("proxy_cache_bypass"),
344
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
345
+ ngx_http_set_predicate_slot,
346
+ NGX_HTTP_LOC_CONF_OFFSET,
347
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_bypass),
348
+ NULL },
349
+
350
+ { ngx_string("proxy_no_cache"),
351
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
352
+ ngx_http_set_predicate_slot,
353
+ NGX_HTTP_LOC_CONF_OFFSET,
354
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.no_cache),
355
+ NULL },
356
+
357
+ { ngx_string("proxy_cache_valid"),
358
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
359
+ ngx_http_file_cache_valid_set_slot,
360
+ NGX_HTTP_LOC_CONF_OFFSET,
361
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_valid),
362
+ NULL },
363
+
364
+ { ngx_string("proxy_cache_min_uses"),
365
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
366
+ ngx_conf_set_num_slot,
367
+ NGX_HTTP_LOC_CONF_OFFSET,
368
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_min_uses),
369
+ NULL },
370
+
371
+ { ngx_string("proxy_cache_use_stale"),
372
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
373
+ ngx_conf_set_bitmask_slot,
374
+ NGX_HTTP_LOC_CONF_OFFSET,
375
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_use_stale),
376
+ &ngx_http_proxy_next_upstream_masks },
377
+
378
+ { ngx_string("proxy_cache_methods"),
379
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
380
+ ngx_conf_set_bitmask_slot,
381
+ NGX_HTTP_LOC_CONF_OFFSET,
382
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_methods),
383
+ &ngx_http_upstream_cache_method_mask },
384
+
385
+ #endif
386
+
387
+ { ngx_string("proxy_temp_path"),
388
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
389
+ ngx_conf_set_path_slot,
390
+ NGX_HTTP_LOC_CONF_OFFSET,
391
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.temp_path),
392
+ NULL },
393
+
394
+ { ngx_string("proxy_max_temp_file_size"),
395
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
396
+ ngx_conf_set_size_slot,
397
+ NGX_HTTP_LOC_CONF_OFFSET,
398
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.max_temp_file_size_conf),
399
+ NULL },
400
+
401
+ { ngx_string("proxy_temp_file_write_size"),
402
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
403
+ ngx_conf_set_size_slot,
404
+ NGX_HTTP_LOC_CONF_OFFSET,
405
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.temp_file_write_size_conf),
406
+ NULL },
407
+
408
+ { ngx_string("proxy_next_upstream"),
409
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
410
+ ngx_conf_set_bitmask_slot,
411
+ NGX_HTTP_LOC_CONF_OFFSET,
412
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.next_upstream),
413
+ &ngx_http_proxy_next_upstream_masks },
414
+
415
+ { ngx_string("proxy_pass_header"),
416
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
417
+ ngx_conf_set_str_array_slot,
418
+ NGX_HTTP_LOC_CONF_OFFSET,
419
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_headers),
420
+ NULL },
421
+
422
+ { ngx_string("proxy_hide_header"),
423
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
424
+ ngx_conf_set_str_array_slot,
425
+ NGX_HTTP_LOC_CONF_OFFSET,
426
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.hide_headers),
427
+ NULL },
428
+
429
+ { ngx_string("proxy_ignore_headers"),
430
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
431
+ ngx_conf_set_bitmask_slot,
432
+ NGX_HTTP_LOC_CONF_OFFSET,
433
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_headers),
434
+ &ngx_http_upstream_ignore_headers_masks },
435
+
436
+ #if (NGX_HTTP_SSL)
437
+
438
+ { ngx_string("proxy_ssl_session_reuse"),
439
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
440
+ ngx_conf_set_flag_slot,
441
+ NGX_HTTP_LOC_CONF_OFFSET,
442
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.ssl_session_reuse),
443
+ NULL },
444
+
445
+ #endif
446
+
447
+ ngx_null_command
448
+ };
449
+
450
+
451
+ static ngx_http_module_t ngx_http_proxy_module_ctx = {
452
+ ngx_http_proxy_add_variables, /* preconfiguration */
453
+ NULL, /* postconfiguration */
454
+
455
+ NULL, /* create main configuration */
456
+ NULL, /* init main configuration */
457
+
458
+ NULL, /* create server configuration */
459
+ NULL, /* merge server configuration */
460
+
461
+ ngx_http_proxy_create_loc_conf, /* create location configuration */
462
+ ngx_http_proxy_merge_loc_conf /* merge location configuration */
463
+ };
464
+
465
+
466
+ ngx_module_t ngx_http_proxy_module = {
467
+ NGX_MODULE_V1,
468
+ &ngx_http_proxy_module_ctx, /* module context */
469
+ ngx_http_proxy_commands, /* module directives */
470
+ NGX_HTTP_MODULE, /* module type */
471
+ NULL, /* init master */
472
+ NULL, /* init module */
473
+ NULL, /* init process */
474
+ NULL, /* init thread */
475
+ NULL, /* exit thread */
476
+ NULL, /* exit process */
477
+ NULL, /* exit master */
478
+ NGX_MODULE_V1_PADDING
479
+ };
480
+
481
+
482
+ static char ngx_http_proxy_version[] = " HTTP/1.0" CRLF;
483
+
484
+
485
+ static ngx_keyval_t ngx_http_proxy_headers[] = {
486
+ { ngx_string("Host"), ngx_string("$proxy_host") },
487
+ { ngx_string("Connection"), ngx_string("close") },
488
+ { ngx_string("Keep-Alive"), ngx_string("") },
489
+ { ngx_string("Expect"), ngx_string("") },
490
+ { ngx_null_string, ngx_null_string }
491
+ };
492
+
493
+
494
+ static ngx_str_t ngx_http_proxy_hide_headers[] = {
495
+ ngx_string("Date"),
496
+ ngx_string("Server"),
497
+ ngx_string("X-Pad"),
498
+ ngx_string("X-Accel-Expires"),
499
+ ngx_string("X-Accel-Redirect"),
500
+ ngx_string("X-Accel-Limit-Rate"),
501
+ ngx_string("X-Accel-Buffering"),
502
+ ngx_string("X-Accel-Charset"),
503
+ ngx_null_string
504
+ };
505
+
506
+
507
+ #if (NGX_HTTP_CACHE)
508
+
509
+ static ngx_keyval_t ngx_http_proxy_cache_headers[] = {
510
+ { ngx_string("Host"), ngx_string("$proxy_host") },
511
+ { ngx_string("Connection"), ngx_string("close") },
512
+ { ngx_string("Keep-Alive"), ngx_string("") },
513
+ { ngx_string("Expect"), ngx_string("") },
514
+ { ngx_string("If-Modified-Since"), ngx_string("") },
515
+ { ngx_string("If-Unmodified-Since"), ngx_string("") },
516
+ { ngx_string("If-None-Match"), ngx_string("") },
517
+ { ngx_string("If-Match"), ngx_string("") },
518
+ { ngx_string("Range"), ngx_string("") },
519
+ { ngx_string("If-Range"), ngx_string("") },
520
+ { ngx_null_string, ngx_null_string }
521
+ };
522
+
523
+ #endif
524
+
525
+
526
+ static ngx_http_variable_t ngx_http_proxy_vars[] = {
527
+
528
+ { ngx_string("proxy_host"), NULL, ngx_http_proxy_host_variable, 0,
529
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
530
+
531
+ { ngx_string("proxy_port"), NULL, ngx_http_proxy_port_variable, 0,
532
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
533
+
534
+ { ngx_string("proxy_add_x_forwarded_for"), NULL,
535
+ ngx_http_proxy_add_x_forwarded_for_variable, 0, NGX_HTTP_VAR_NOHASH, 0 },
536
+
537
+ #if 0
538
+ { ngx_string("proxy_add_via"), NULL, NULL, 0, NGX_HTTP_VAR_NOHASH, 0 },
539
+ #endif
540
+
541
+ { ngx_string("proxy_internal_body_length"), NULL,
542
+ ngx_http_proxy_internal_body_length_variable, 0, NGX_HTTP_VAR_NOHASH, 0 },
543
+
544
+ { ngx_null_string, NULL, NULL, 0, 0, 0 }
545
+ };
546
+
547
+
548
+ static ngx_path_init_t ngx_http_proxy_temp_path = {
549
+ ngx_string(NGX_HTTP_PROXY_TEMP_PATH), { 1, 2, 0 }
550
+ };
551
+
552
+
553
+ static ngx_int_t
554
+ ngx_http_proxy_handler(ngx_http_request_t *r)
555
+ {
556
+ ngx_int_t rc;
557
+ ngx_http_upstream_t *u;
558
+ ngx_http_proxy_ctx_t *ctx;
559
+ ngx_http_proxy_loc_conf_t *plcf;
560
+
561
+ if (ngx_http_upstream_create(r) != NGX_OK) {
562
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
563
+ }
564
+
565
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_ctx_t));
566
+ if (ctx == NULL) {
567
+ return NGX_ERROR;
568
+ }
569
+
570
+ ngx_http_set_ctx(r, ctx, ngx_http_proxy_module);
571
+
572
+ plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
573
+
574
+ u = r->upstream;
575
+
576
+ if (plcf->proxy_lengths == NULL) {
577
+ ctx->vars = plcf->vars;
578
+ u->schema = plcf->vars.schema;
579
+ #if (NGX_HTTP_SSL)
580
+ u->ssl = (plcf->upstream.ssl != NULL);
581
+ #endif
582
+
583
+ } else {
584
+ if (ngx_http_proxy_eval(r, ctx, plcf) != NGX_OK) {
585
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
586
+ }
587
+ }
588
+
589
+ u->output.tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
590
+
591
+ u->conf = &plcf->upstream;
592
+
593
+ #if (NGX_HTTP_CACHE)
594
+ u->create_key = ngx_http_proxy_create_key;
595
+ #endif
596
+ u->create_request = ngx_http_proxy_create_request;
597
+ u->reinit_request = ngx_http_proxy_reinit_request;
598
+ u->process_header = ngx_http_proxy_process_status_line;
599
+ u->abort_request = ngx_http_proxy_abort_request;
600
+ u->finalize_request = ngx_http_proxy_finalize_request;
601
+ r->state = 0;
602
+
603
+ if (plcf->redirects) {
604
+ u->rewrite_redirect = ngx_http_proxy_rewrite_redirect;
605
+ }
606
+
607
+ u->buffering = plcf->upstream.buffering;
608
+
609
+ u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
610
+ if (u->pipe == NULL) {
611
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
612
+ }
613
+
614
+ u->pipe->input_filter = ngx_event_pipe_copy_input_filter;
615
+
616
+ u->accel = 1;
617
+
618
+ rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
619
+
620
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
621
+ return rc;
622
+ }
623
+
624
+ return NGX_DONE;
625
+ }
626
+
627
+
628
+ static ngx_int_t
629
+ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
630
+ ngx_http_proxy_loc_conf_t *plcf)
631
+ {
632
+ u_char *p;
633
+ size_t add;
634
+ u_short port;
635
+ ngx_str_t proxy;
636
+ ngx_url_t url;
637
+ ngx_http_upstream_t *u;
638
+
639
+ if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0,
640
+ plcf->proxy_values->elts)
641
+ == NULL)
642
+ {
643
+ return NGX_ERROR;
644
+ }
645
+
646
+ if (proxy.len > 7
647
+ && ngx_strncasecmp(proxy.data, (u_char *) "http://", 7) == 0)
648
+ {
649
+ add = 7;
650
+ port = 80;
651
+
652
+ #if (NGX_HTTP_SSL)
653
+
654
+ } else if (proxy.len > 8
655
+ && ngx_strncasecmp(proxy.data, (u_char *) "https://", 8) == 0)
656
+ {
657
+ add = 8;
658
+ port = 443;
659
+ r->upstream->ssl = 1;
660
+
661
+ #endif
662
+
663
+ } else {
664
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
665
+ "invalid URL prefix in \"%V\"", &proxy);
666
+ return NGX_ERROR;
667
+ }
668
+
669
+ u = r->upstream;
670
+
671
+ u->schema.len = add;
672
+ u->schema.data = proxy.data;
673
+
674
+ ngx_memzero(&url, sizeof(ngx_url_t));
675
+
676
+ url.url.len = proxy.len - add;
677
+ url.url.data = proxy.data + add;
678
+ url.default_port = port;
679
+ url.uri_part = 1;
680
+ url.no_resolve = 1;
681
+
682
+ if (ngx_parse_url(r->pool, &url) != NGX_OK) {
683
+ if (url.err) {
684
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
685
+ "%s in upstream \"%V\"", url.err, &url.url);
686
+ }
687
+
688
+ return NGX_ERROR;
689
+ }
690
+
691
+ if (url.uri.len) {
692
+ if (url.uri.data[0] == '?') {
693
+ p = ngx_pnalloc(r->pool, url.uri.len + 1);
694
+ if (p == NULL) {
695
+ return NGX_ERROR;
696
+ }
697
+
698
+ *p++ = '/';
699
+ ngx_memcpy(p, url.uri.data, url.uri.len);
700
+
701
+ url.uri.len++;
702
+ url.uri.data = p - 1;
703
+ }
704
+
705
+ } else {
706
+ url.uri = r->unparsed_uri;
707
+ }
708
+
709
+ ctx->vars.key_start = u->schema;
710
+
711
+ ngx_http_proxy_set_vars(&url, &ctx->vars);
712
+
713
+ u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));
714
+ if (u->resolved == NULL) {
715
+ return NGX_ERROR;
716
+ }
717
+
718
+ if (url.addrs && url.addrs[0].sockaddr) {
719
+ u->resolved->sockaddr = url.addrs[0].sockaddr;
720
+ u->resolved->socklen = url.addrs[0].socklen;
721
+ u->resolved->naddrs = 1;
722
+ u->resolved->host = url.addrs[0].name;
723
+
724
+ } else {
725
+ u->resolved->host = url.host;
726
+ u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
727
+ u->resolved->no_port = url.no_port;
728
+ }
729
+
730
+ return NGX_OK;
731
+ }
732
+
733
+
734
+ #if (NGX_HTTP_CACHE)
735
+
736
+ static ngx_int_t
737
+ ngx_http_proxy_create_key(ngx_http_request_t *r)
738
+ {
739
+ size_t len, loc_len;
740
+ u_char *p;
741
+ uintptr_t escape;
742
+ ngx_str_t *key;
743
+ ngx_http_upstream_t *u;
744
+ ngx_http_proxy_ctx_t *ctx;
745
+ ngx_http_proxy_loc_conf_t *plcf;
746
+
747
+ u = r->upstream;
748
+
749
+ plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
750
+
751
+ ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
752
+
753
+ key = ngx_array_push(&r->cache->keys);
754
+ if (key == NULL) {
755
+ return NGX_ERROR;
756
+ }
757
+
758
+ if (plcf->cache_key.value.len) {
759
+
760
+ if (ngx_http_complex_value(r, &plcf->cache_key, key) != NGX_OK) {
761
+ return NGX_ERROR;
762
+ }
763
+
764
+ return NGX_OK;
765
+ }
766
+
767
+ *key = ctx->vars.key_start;
768
+
769
+ key = ngx_array_push(&r->cache->keys);
770
+ if (key == NULL) {
771
+ return NGX_ERROR;
772
+ }
773
+
774
+ if (plcf->proxy_lengths) {
775
+
776
+ *key = ctx->vars.uri;
777
+ u->uri = ctx->vars.uri;
778
+
779
+ return NGX_OK;
780
+
781
+ } else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main)
782
+ {
783
+ *key = r->unparsed_uri;
784
+ u->uri = r->unparsed_uri;
785
+
786
+ return NGX_OK;
787
+ }
788
+
789
+ loc_len = (r->valid_location && ctx->vars.uri.len) ? plcf->location.len : 0;
790
+
791
+ if (r->quoted_uri || r->internal) {
792
+ escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len,
793
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
794
+ } else {
795
+ escape = 0;
796
+ }
797
+
798
+ len = ctx->vars.uri.len + r->uri.len - loc_len + escape
799
+ + sizeof("?") - 1 + r->args.len;
800
+
801
+ p = ngx_pnalloc(r->pool, len);
802
+ if (p == NULL) {
803
+ return NGX_ERROR;
804
+ }
805
+
806
+ key->data = p;
807
+
808
+ if (r->valid_location) {
809
+ p = ngx_copy(p, ctx->vars.uri.data, ctx->vars.uri.len);
810
+ }
811
+
812
+ if (escape) {
813
+ ngx_escape_uri(p, r->uri.data + loc_len,
814
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
815
+ p += r->uri.len - loc_len + escape;
816
+
817
+ } else {
818
+ p = ngx_copy(p, r->uri.data + loc_len, r->uri.len - loc_len);
819
+ }
820
+
821
+ if (r->args.len > 0) {
822
+ *p++ = '?';
823
+ p = ngx_copy(p, r->args.data, r->args.len);
824
+ }
825
+
826
+ key->len = p - key->data;
827
+ u->uri = *key;
828
+
829
+ return NGX_OK;
830
+ }
831
+
832
+ #endif
833
+
834
+
835
+ static ngx_int_t
836
+ ngx_http_proxy_create_request(ngx_http_request_t *r)
837
+ {
838
+ size_t len, uri_len, loc_len, body_len;
839
+ uintptr_t escape;
840
+ ngx_buf_t *b;
841
+ ngx_str_t method;
842
+ ngx_uint_t i, unparsed_uri;
843
+ ngx_chain_t *cl, *body;
844
+ ngx_list_part_t *part;
845
+ ngx_table_elt_t *header;
846
+ ngx_http_upstream_t *u;
847
+ ngx_http_proxy_ctx_t *ctx;
848
+ ngx_http_script_code_pt code;
849
+ ngx_http_script_engine_t e, le;
850
+ ngx_http_proxy_loc_conf_t *plcf;
851
+ ngx_http_script_len_code_pt lcode;
852
+
853
+ u = r->upstream;
854
+
855
+ plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
856
+
857
+ if (u->method.len) {
858
+ /* HEAD was changed to GET to cache response */
859
+ method = u->method;
860
+ method.len++;
861
+
862
+ } else if (plcf->method.len) {
863
+ method = plcf->method;
864
+
865
+ } else {
866
+ method = r->method_name;
867
+ method.len++;
868
+ }
869
+
870
+ len = method.len + sizeof(ngx_http_proxy_version) - 1 + sizeof(CRLF) - 1;
871
+
872
+ escape = 0;
873
+ loc_len = 0;
874
+ unparsed_uri = 0;
875
+
876
+ ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
877
+
878
+ if (plcf->proxy_lengths) {
879
+ uri_len = ctx->vars.uri.len;
880
+
881
+ } else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main)
882
+ {
883
+ unparsed_uri = 1;
884
+ uri_len = r->unparsed_uri.len;
885
+
886
+ } else {
887
+ loc_len = (r->valid_location && ctx->vars.uri.len) ?
888
+ plcf->location.len : 0;
889
+
890
+ if (r->quoted_uri || r->space_in_uri || r->internal) {
891
+ escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len,
892
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
893
+ }
894
+
895
+ uri_len = ctx->vars.uri.len + r->uri.len - loc_len + escape
896
+ + sizeof("?") - 1 + r->args.len;
897
+ }
898
+
899
+ if (uri_len == 0) {
900
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
901
+ "zero length URI to proxy");
902
+ return NGX_ERROR;
903
+ }
904
+
905
+ len += uri_len;
906
+
907
+ ngx_http_script_flush_no_cacheable_variables(r, plcf->flushes);
908
+
909
+ if (plcf->body_set_len) {
910
+ le.ip = plcf->body_set_len->elts;
911
+ le.request = r;
912
+ le.flushed = 1;
913
+ body_len = 0;
914
+
915
+ while (*(uintptr_t *) le.ip) {
916
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
917
+ body_len += lcode(&le);
918
+ }
919
+
920
+ ctx->internal_body_length = body_len;
921
+ len += body_len;
922
+ }
923
+
924
+ le.ip = plcf->headers_set_len->elts;
925
+ le.request = r;
926
+ le.flushed = 1;
927
+
928
+ while (*(uintptr_t *) le.ip) {
929
+ while (*(uintptr_t *) le.ip) {
930
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
931
+ len += lcode(&le);
932
+ }
933
+ le.ip += sizeof(uintptr_t);
934
+ }
935
+
936
+
937
+ if (plcf->upstream.pass_request_headers) {
938
+ part = &r->headers_in.headers.part;
939
+ header = part->elts;
940
+
941
+ for (i = 0; /* void */; i++) {
942
+
943
+ if (i >= part->nelts) {
944
+ if (part->next == NULL) {
945
+ break;
946
+ }
947
+
948
+ part = part->next;
949
+ header = part->elts;
950
+ i = 0;
951
+ }
952
+
953
+ if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash,
954
+ header[i].lowcase_key, header[i].key.len))
955
+ {
956
+ continue;
957
+ }
958
+
959
+ len += header[i].key.len + sizeof(": ") - 1
960
+ + header[i].value.len + sizeof(CRLF) - 1;
961
+ }
962
+ }
963
+
964
+
965
+ b = ngx_create_temp_buf(r->pool, len);
966
+ if (b == NULL) {
967
+ return NGX_ERROR;
968
+ }
969
+
970
+ cl = ngx_alloc_chain_link(r->pool);
971
+ if (cl == NULL) {
972
+ return NGX_ERROR;
973
+ }
974
+
975
+ cl->buf = b;
976
+
977
+
978
+ /* the request line */
979
+
980
+ b->last = ngx_copy(b->last, method.data, method.len);
981
+
982
+ u->uri.data = b->last;
983
+
984
+ if (plcf->proxy_lengths) {
985
+ b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len);
986
+
987
+ } else if (unparsed_uri) {
988
+ b->last = ngx_copy(b->last, r->unparsed_uri.data, r->unparsed_uri.len);
989
+
990
+ } else {
991
+ if (r->valid_location) {
992
+ b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len);
993
+ }
994
+
995
+ if (escape) {
996
+ ngx_escape_uri(b->last, r->uri.data + loc_len,
997
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
998
+ b->last += r->uri.len - loc_len + escape;
999
+
1000
+ } else {
1001
+ b->last = ngx_copy(b->last, r->uri.data + loc_len,
1002
+ r->uri.len - loc_len);
1003
+ }
1004
+
1005
+ if (r->args.len > 0) {
1006
+ *b->last++ = '?';
1007
+ b->last = ngx_copy(b->last, r->args.data, r->args.len);
1008
+ }
1009
+ }
1010
+
1011
+ u->uri.len = b->last - u->uri.data;
1012
+
1013
+ b->last = ngx_cpymem(b->last, ngx_http_proxy_version,
1014
+ sizeof(ngx_http_proxy_version) - 1);
1015
+
1016
+ ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
1017
+
1018
+ e.ip = plcf->headers_set->elts;
1019
+ e.pos = b->last;
1020
+ e.request = r;
1021
+ e.flushed = 1;
1022
+
1023
+ le.ip = plcf->headers_set_len->elts;
1024
+
1025
+ while (*(uintptr_t *) le.ip) {
1026
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
1027
+
1028
+ /* skip the header line name length */
1029
+ (void) lcode(&le);
1030
+
1031
+ if (*(ngx_http_script_len_code_pt *) le.ip) {
1032
+
1033
+ for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) {
1034
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
1035
+ }
1036
+
1037
+ e.skip = (len == sizeof(CRLF) - 1) ? 1 : 0;
1038
+
1039
+ } else {
1040
+ e.skip = 0;
1041
+ }
1042
+
1043
+ le.ip += sizeof(uintptr_t);
1044
+
1045
+ while (*(uintptr_t *) e.ip) {
1046
+ code = *(ngx_http_script_code_pt *) e.ip;
1047
+ code((ngx_http_script_engine_t *) &e);
1048
+ }
1049
+ e.ip += sizeof(uintptr_t);
1050
+ }
1051
+
1052
+ b->last = e.pos;
1053
+
1054
+
1055
+ if (plcf->upstream.pass_request_headers) {
1056
+ part = &r->headers_in.headers.part;
1057
+ header = part->elts;
1058
+
1059
+ for (i = 0; /* void */; i++) {
1060
+
1061
+ if (i >= part->nelts) {
1062
+ if (part->next == NULL) {
1063
+ break;
1064
+ }
1065
+
1066
+ part = part->next;
1067
+ header = part->elts;
1068
+ i = 0;
1069
+ }
1070
+
1071
+ if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash,
1072
+ header[i].lowcase_key, header[i].key.len))
1073
+ {
1074
+ continue;
1075
+ }
1076
+
1077
+ b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len);
1078
+
1079
+ *b->last++ = ':'; *b->last++ = ' ';
1080
+
1081
+ b->last = ngx_copy(b->last, header[i].value.data,
1082
+ header[i].value.len);
1083
+
1084
+ *b->last++ = CR; *b->last++ = LF;
1085
+
1086
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1087
+ "http proxy header: \"%V: %V\"",
1088
+ &header[i].key, &header[i].value);
1089
+ }
1090
+ }
1091
+
1092
+
1093
+ /* add "\r\n" at the header end */
1094
+ *b->last++ = CR; *b->last++ = LF;
1095
+
1096
+ if (plcf->body_set) {
1097
+ e.ip = plcf->body_set->elts;
1098
+ e.pos = b->last;
1099
+
1100
+ while (*(uintptr_t *) e.ip) {
1101
+ code = *(ngx_http_script_code_pt *) e.ip;
1102
+ code((ngx_http_script_engine_t *) &e);
1103
+ }
1104
+
1105
+ b->last = e.pos;
1106
+ }
1107
+
1108
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1109
+ "http proxy header:\n\"%*s\"",
1110
+ (size_t) (b->last - b->pos), b->pos);
1111
+
1112
+ if (plcf->body_set == NULL && plcf->upstream.pass_request_body) {
1113
+
1114
+ body = u->request_bufs;
1115
+ u->request_bufs = cl;
1116
+
1117
+ while (body) {
1118
+ b = ngx_alloc_buf(r->pool);
1119
+ if (b == NULL) {
1120
+ return NGX_ERROR;
1121
+ }
1122
+
1123
+ ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
1124
+
1125
+ cl->next = ngx_alloc_chain_link(r->pool);
1126
+ if (cl->next == NULL) {
1127
+ return NGX_ERROR;
1128
+ }
1129
+
1130
+ cl = cl->next;
1131
+ cl->buf = b;
1132
+
1133
+ body = body->next;
1134
+ }
1135
+
1136
+ } else {
1137
+ u->request_bufs = cl;
1138
+ }
1139
+
1140
+ b->flush = 1;
1141
+ cl->next = NULL;
1142
+
1143
+ return NGX_OK;
1144
+ }
1145
+
1146
+
1147
+ static ngx_int_t
1148
+ ngx_http_proxy_reinit_request(ngx_http_request_t *r)
1149
+ {
1150
+ ngx_http_proxy_ctx_t *ctx;
1151
+
1152
+ ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1153
+
1154
+ if (ctx == NULL) {
1155
+ return NGX_OK;
1156
+ }
1157
+
1158
+ ctx->status.code = 0;
1159
+ ctx->status.count = 0;
1160
+ ctx->status.start = NULL;
1161
+ ctx->status.end = NULL;
1162
+
1163
+ r->upstream->process_header = ngx_http_proxy_process_status_line;
1164
+ r->state = 0;
1165
+
1166
+ return NGX_OK;
1167
+ }
1168
+
1169
+
1170
+ static ngx_int_t
1171
+ ngx_http_proxy_process_status_line(ngx_http_request_t *r)
1172
+ {
1173
+ size_t len;
1174
+ ngx_int_t rc;
1175
+ ngx_http_upstream_t *u;
1176
+ ngx_http_proxy_ctx_t *ctx;
1177
+
1178
+ ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1179
+
1180
+ if (ctx == NULL) {
1181
+ return NGX_ERROR;
1182
+ }
1183
+
1184
+ u = r->upstream;
1185
+
1186
+ rc = ngx_http_parse_status_line(r, &u->buffer, &ctx->status);
1187
+
1188
+ if (rc == NGX_AGAIN) {
1189
+ return rc;
1190
+ }
1191
+
1192
+ if (rc == NGX_ERROR) {
1193
+
1194
+ #if (NGX_HTTP_CACHE)
1195
+
1196
+ if (r->cache) {
1197
+ r->http_version = NGX_HTTP_VERSION_9;
1198
+ return NGX_OK;
1199
+ }
1200
+
1201
+ #endif
1202
+
1203
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1204
+ "upstream sent no valid HTTP/1.0 header");
1205
+
1206
+ #if 0
1207
+ if (u->accel) {
1208
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1209
+ }
1210
+ #endif
1211
+
1212
+ r->http_version = NGX_HTTP_VERSION_9;
1213
+ u->state->status = NGX_HTTP_OK;
1214
+
1215
+ return NGX_OK;
1216
+ }
1217
+
1218
+ if (u->state) {
1219
+ u->state->status = ctx->status.code;
1220
+ }
1221
+
1222
+ u->headers_in.status_n = ctx->status.code;
1223
+
1224
+ len = ctx->status.end - ctx->status.start;
1225
+ u->headers_in.status_line.len = len;
1226
+
1227
+ u->headers_in.status_line.data = ngx_pnalloc(r->pool, len);
1228
+ if (u->headers_in.status_line.data == NULL) {
1229
+ return NGX_ERROR;
1230
+ }
1231
+
1232
+ ngx_memcpy(u->headers_in.status_line.data, ctx->status.start, len);
1233
+
1234
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1235
+ "http proxy status %ui \"%V\"",
1236
+ u->headers_in.status_n, &u->headers_in.status_line);
1237
+
1238
+ u->process_header = ngx_http_proxy_process_header;
1239
+
1240
+ return ngx_http_proxy_process_header(r);
1241
+ }
1242
+
1243
+
1244
+ static ngx_int_t
1245
+ ngx_http_proxy_process_header(ngx_http_request_t *r)
1246
+ {
1247
+ ngx_int_t rc;
1248
+ ngx_table_elt_t *h;
1249
+ ngx_http_upstream_header_t *hh;
1250
+ ngx_http_upstream_main_conf_t *umcf;
1251
+
1252
+ umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
1253
+
1254
+ for ( ;; ) {
1255
+
1256
+ rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1);
1257
+
1258
+ if (rc == NGX_OK) {
1259
+
1260
+ /* a header line has been parsed successfully */
1261
+
1262
+ h = ngx_list_push(&r->upstream->headers_in.headers);
1263
+ if (h == NULL) {
1264
+ return NGX_ERROR;
1265
+ }
1266
+
1267
+ h->hash = r->header_hash;
1268
+
1269
+ h->key.len = r->header_name_end - r->header_name_start;
1270
+ h->value.len = r->header_end - r->header_start;
1271
+
1272
+ h->key.data = ngx_pnalloc(r->pool,
1273
+ h->key.len + 1 + h->value.len + 1 + h->key.len);
1274
+ if (h->key.data == NULL) {
1275
+ return NGX_ERROR;
1276
+ }
1277
+
1278
+ h->value.data = h->key.data + h->key.len + 1;
1279
+ h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;
1280
+
1281
+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);
1282
+ h->key.data[h->key.len] = '\0';
1283
+ ngx_memcpy(h->value.data, r->header_start, h->value.len);
1284
+ h->value.data[h->value.len] = '\0';
1285
+
1286
+ if (h->key.len == r->lowcase_index) {
1287
+ ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
1288
+
1289
+ } else {
1290
+ ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
1291
+ }
1292
+
1293
+ hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
1294
+ h->lowcase_key, h->key.len);
1295
+
1296
+ if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
1297
+ return NGX_ERROR;
1298
+ }
1299
+
1300
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1301
+ "http proxy header: \"%V: %V\"",
1302
+ &h->key, &h->value);
1303
+
1304
+ continue;
1305
+ }
1306
+
1307
+ if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
1308
+
1309
+ /* a whole header has been parsed successfully */
1310
+
1311
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1312
+ "http proxy header done");
1313
+
1314
+ /*
1315
+ * if no "Server" and "Date" in header line,
1316
+ * then add the special empty headers
1317
+ */
1318
+
1319
+ if (r->upstream->headers_in.server == NULL) {
1320
+ h = ngx_list_push(&r->upstream->headers_in.headers);
1321
+ if (h == NULL) {
1322
+ return NGX_ERROR;
1323
+ }
1324
+
1325
+ h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
1326
+ ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r');
1327
+
1328
+ ngx_str_set(&h->key, "Server");
1329
+ ngx_str_null(&h->value);
1330
+ h->lowcase_key = (u_char *) "server";
1331
+ }
1332
+
1333
+ if (r->upstream->headers_in.date == NULL) {
1334
+ h = ngx_list_push(&r->upstream->headers_in.headers);
1335
+ if (h == NULL) {
1336
+ return NGX_ERROR;
1337
+ }
1338
+
1339
+ h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e');
1340
+
1341
+ ngx_str_set(&h->key, "Date");
1342
+ ngx_str_null(&h->value);
1343
+ h->lowcase_key = (u_char *) "date";
1344
+ }
1345
+
1346
+ return NGX_OK;
1347
+ }
1348
+
1349
+ if (rc == NGX_AGAIN) {
1350
+ return NGX_AGAIN;
1351
+ }
1352
+
1353
+ /* there was error while a header line parsing */
1354
+
1355
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1356
+ "upstream sent invalid header");
1357
+
1358
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1359
+ }
1360
+ }
1361
+
1362
+
1363
+ static void
1364
+ ngx_http_proxy_abort_request(ngx_http_request_t *r)
1365
+ {
1366
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1367
+ "abort http proxy request");
1368
+
1369
+ return;
1370
+ }
1371
+
1372
+
1373
+ static void
1374
+ ngx_http_proxy_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
1375
+ {
1376
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1377
+ "finalize http proxy request");
1378
+
1379
+ return;
1380
+ }
1381
+
1382
+
1383
+ static ngx_int_t
1384
+ ngx_http_proxy_host_variable(ngx_http_request_t *r,
1385
+ ngx_http_variable_value_t *v, uintptr_t data)
1386
+ {
1387
+ ngx_http_proxy_ctx_t *ctx;
1388
+
1389
+ ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1390
+
1391
+ if (ctx == NULL) {
1392
+ v->not_found = 1;
1393
+ return NGX_OK;
1394
+ }
1395
+
1396
+ v->len = ctx->vars.host_header.len;
1397
+ v->valid = 1;
1398
+ v->no_cacheable = 0;
1399
+ v->not_found = 0;
1400
+ v->data = ctx->vars.host_header.data;
1401
+
1402
+ return NGX_OK;
1403
+ }
1404
+
1405
+
1406
+ static ngx_int_t
1407
+ ngx_http_proxy_port_variable(ngx_http_request_t *r,
1408
+ ngx_http_variable_value_t *v, uintptr_t data)
1409
+ {
1410
+ ngx_http_proxy_ctx_t *ctx;
1411
+
1412
+ ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1413
+
1414
+ if (ctx == NULL) {
1415
+ v->not_found = 1;
1416
+ return NGX_OK;
1417
+ }
1418
+
1419
+ v->len = ctx->vars.port.len;
1420
+ v->valid = 1;
1421
+ v->no_cacheable = 0;
1422
+ v->not_found = 0;
1423
+ v->data = ctx->vars.port.data;
1424
+
1425
+ return NGX_OK;
1426
+ }
1427
+
1428
+
1429
+ static ngx_int_t
1430
+ ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r,
1431
+ ngx_http_variable_value_t *v, uintptr_t data)
1432
+ {
1433
+ u_char *p;
1434
+
1435
+ v->valid = 1;
1436
+ v->no_cacheable = 0;
1437
+ v->not_found = 0;
1438
+
1439
+ if (r->headers_in.x_forwarded_for == NULL) {
1440
+ v->len = r->connection->addr_text.len;
1441
+ v->data = r->connection->addr_text.data;
1442
+ return NGX_OK;
1443
+ }
1444
+
1445
+ v->len = r->headers_in.x_forwarded_for->value.len
1446
+ + sizeof(", ") - 1 + r->connection->addr_text.len;
1447
+
1448
+ p = ngx_pnalloc(r->pool, v->len);
1449
+ if (p == NULL) {
1450
+ return NGX_ERROR;
1451
+ }
1452
+
1453
+ v->data = p;
1454
+
1455
+ p = ngx_copy(p, r->headers_in.x_forwarded_for->value.data,
1456
+ r->headers_in.x_forwarded_for->value.len);
1457
+
1458
+ *p++ = ','; *p++ = ' ';
1459
+
1460
+ ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len);
1461
+
1462
+ return NGX_OK;
1463
+ }
1464
+
1465
+
1466
+ static ngx_int_t
1467
+ ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r,
1468
+ ngx_http_variable_value_t *v, uintptr_t data)
1469
+ {
1470
+ ngx_http_proxy_ctx_t *ctx;
1471
+
1472
+ ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1473
+
1474
+ if (ctx == NULL) {
1475
+ v->not_found = 1;
1476
+ return NGX_OK;
1477
+ }
1478
+
1479
+ v->valid = 1;
1480
+ v->no_cacheable = 0;
1481
+ v->not_found = 0;
1482
+
1483
+ v->data = ngx_pnalloc(r->connection->pool, NGX_SIZE_T_LEN);
1484
+
1485
+ if (v->data == NULL) {
1486
+ return NGX_ERROR;
1487
+ }
1488
+
1489
+ v->len = ngx_sprintf(v->data, "%uz", ctx->internal_body_length) - v->data;
1490
+
1491
+ return NGX_OK;
1492
+ }
1493
+
1494
+
1495
+ static ngx_int_t
1496
+ ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, ngx_table_elt_t *h,
1497
+ size_t prefix)
1498
+ {
1499
+ ngx_int_t rc;
1500
+ ngx_uint_t i;
1501
+ ngx_http_proxy_loc_conf_t *plcf;
1502
+ ngx_http_proxy_redirect_t *pr;
1503
+
1504
+ plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
1505
+
1506
+ pr = plcf->redirects->elts;
1507
+
1508
+ if (pr == NULL) {
1509
+ return NGX_DECLINED;
1510
+ }
1511
+
1512
+ for (i = 0; i < plcf->redirects->nelts; i++) {
1513
+ rc = pr[i].handler(r, h, prefix, &pr[i]);
1514
+
1515
+ if (rc != NGX_DECLINED) {
1516
+ return rc;
1517
+ }
1518
+ }
1519
+
1520
+ return NGX_DECLINED;
1521
+ }
1522
+
1523
+
1524
+ static ngx_int_t
1525
+ ngx_http_proxy_rewrite_redirect_text(ngx_http_request_t *r, ngx_table_elt_t *h,
1526
+ size_t prefix, ngx_http_proxy_redirect_t *pr)
1527
+ {
1528
+ size_t len;
1529
+ u_char *data, *p;
1530
+
1531
+ if (pr->redirect.len > h->value.len - prefix
1532
+ || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data,
1533
+ pr->redirect.len) != 0)
1534
+ {
1535
+ return NGX_DECLINED;
1536
+ }
1537
+
1538
+ len = pr->replacement.text.len + h->value.len - pr->redirect.len;
1539
+
1540
+ data = ngx_pnalloc(r->pool, len);
1541
+ if (data == NULL) {
1542
+ return NGX_ERROR;
1543
+ }
1544
+
1545
+ p = ngx_copy(data, h->value.data, prefix);
1546
+
1547
+ if (pr->replacement.text.len) {
1548
+ p = ngx_copy(p, pr->replacement.text.data, pr->replacement.text.len);
1549
+ }
1550
+
1551
+ ngx_memcpy(p, h->value.data + prefix + pr->redirect.len,
1552
+ h->value.len - pr->redirect.len - prefix);
1553
+
1554
+ h->value.len = len;
1555
+ h->value.data = data;
1556
+
1557
+ return NGX_OK;
1558
+ }
1559
+
1560
+
1561
+ static ngx_int_t
1562
+ ngx_http_proxy_rewrite_redirect_vars(ngx_http_request_t *r, ngx_table_elt_t *h,
1563
+ size_t prefix, ngx_http_proxy_redirect_t *pr)
1564
+ {
1565
+ size_t len;
1566
+ u_char *data, *p;
1567
+ ngx_http_script_code_pt code;
1568
+ ngx_http_script_engine_t e;
1569
+ ngx_http_script_len_code_pt lcode;
1570
+
1571
+ if (pr->redirect.len > h->value.len - prefix
1572
+ || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data,
1573
+ pr->redirect.len) != 0)
1574
+ {
1575
+ return NGX_DECLINED;
1576
+ }
1577
+
1578
+ ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
1579
+
1580
+ e.ip = pr->replacement.vars.lengths;
1581
+ e.request = r;
1582
+
1583
+ len = h->value.len - pr->redirect.len;
1584
+
1585
+ while (*(uintptr_t *) e.ip) {
1586
+ lcode = *(ngx_http_script_len_code_pt *) e.ip;
1587
+ len += lcode(&e);
1588
+ }
1589
+
1590
+ data = ngx_pnalloc(r->pool, len);
1591
+ if (data == NULL) {
1592
+ return NGX_ERROR;
1593
+ }
1594
+
1595
+ p = ngx_copy(data, h->value.data, prefix);
1596
+
1597
+ e.ip = pr->replacement.vars.values;
1598
+ e.pos = p;
1599
+
1600
+ while (*(uintptr_t *) e.ip) {
1601
+ code = *(ngx_http_script_code_pt *) e.ip;
1602
+ code(&e);
1603
+ }
1604
+
1605
+ ngx_memcpy(e.pos, h->value.data + prefix + pr->redirect.len,
1606
+ h->value.len - pr->redirect.len - prefix);
1607
+
1608
+ h->value.len = len;
1609
+ h->value.data = data;
1610
+
1611
+ return NGX_OK;
1612
+ }
1613
+
1614
+
1615
+ static ngx_int_t
1616
+ ngx_http_proxy_add_variables(ngx_conf_t *cf)
1617
+ {
1618
+ ngx_http_variable_t *var, *v;
1619
+
1620
+ for (v = ngx_http_proxy_vars; v->name.len; v++) {
1621
+ var = ngx_http_add_variable(cf, &v->name, v->flags);
1622
+ if (var == NULL) {
1623
+ return NGX_ERROR;
1624
+ }
1625
+
1626
+ var->get_handler = v->get_handler;
1627
+ var->data = v->data;
1628
+ }
1629
+
1630
+ return NGX_OK;
1631
+ }
1632
+
1633
+
1634
+ static void *
1635
+ ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
1636
+ {
1637
+ ngx_http_proxy_loc_conf_t *conf;
1638
+
1639
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t));
1640
+ if (conf == NULL) {
1641
+ return NULL;
1642
+ }
1643
+
1644
+ /*
1645
+ * set by ngx_pcalloc():
1646
+ *
1647
+ * conf->upstream.bufs.num = 0;
1648
+ * conf->upstream.ignore_headers = 0;
1649
+ * conf->upstream.next_upstream = 0;
1650
+ * conf->upstream.cache_use_stale = 0;
1651
+ * conf->upstream.cache_methods = 0;
1652
+ * conf->upstream.temp_path = NULL;
1653
+ * conf->upstream.hide_headers_hash = { NULL, 0 };
1654
+ * conf->upstream.uri = { 0, NULL };
1655
+ * conf->upstream.location = NULL;
1656
+ * conf->upstream.store_lengths = NULL;
1657
+ * conf->upstream.store_values = NULL;
1658
+ *
1659
+ * conf->method = NULL;
1660
+ * conf->headers_source = NULL;
1661
+ * conf->headers_set_len = NULL;
1662
+ * conf->headers_set = NULL;
1663
+ * conf->headers_set_hash = NULL;
1664
+ * conf->body_set_len = NULL;
1665
+ * conf->body_set = NULL;
1666
+ * conf->body_source = { 0, NULL };
1667
+ * conf->redirects = NULL;
1668
+ */
1669
+
1670
+ conf->upstream.store = NGX_CONF_UNSET;
1671
+ conf->upstream.store_access = NGX_CONF_UNSET_UINT;
1672
+ conf->upstream.buffering = NGX_CONF_UNSET;
1673
+ conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
1674
+
1675
+ conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
1676
+ conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
1677
+ conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
1678
+
1679
+ conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
1680
+ conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
1681
+
1682
+ conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
1683
+ conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
1684
+ conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
1685
+
1686
+ conf->upstream.pass_request_headers = NGX_CONF_UNSET;
1687
+ conf->upstream.pass_request_body = NGX_CONF_UNSET;
1688
+
1689
+ #if (NGX_HTTP_CACHE)
1690
+ conf->upstream.cache = NGX_CONF_UNSET_PTR;
1691
+ conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
1692
+ conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
1693
+ conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
1694
+ conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
1695
+ #endif
1696
+
1697
+ conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
1698
+ conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
1699
+
1700
+ conf->upstream.intercept_errors = NGX_CONF_UNSET;
1701
+ #if (NGX_HTTP_SSL)
1702
+ conf->upstream.ssl_session_reuse = NGX_CONF_UNSET;
1703
+ #endif
1704
+
1705
+ /* "proxy_cyclic_temp_file" is disabled */
1706
+ conf->upstream.cyclic_temp_file = 0;
1707
+
1708
+ conf->redirect = NGX_CONF_UNSET;
1709
+ conf->upstream.change_buffering = 1;
1710
+
1711
+ conf->headers_hash_max_size = NGX_CONF_UNSET_UINT;
1712
+ conf->headers_hash_bucket_size = NGX_CONF_UNSET_UINT;
1713
+
1714
+ ngx_str_set(&conf->upstream.module, "proxy");
1715
+
1716
+ return conf;
1717
+ }
1718
+
1719
+
1720
+ static char *
1721
+ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
1722
+ {
1723
+ ngx_http_proxy_loc_conf_t *prev = parent;
1724
+ ngx_http_proxy_loc_conf_t *conf = child;
1725
+
1726
+ u_char *p;
1727
+ size_t size;
1728
+ ngx_hash_init_t hash;
1729
+ ngx_http_core_loc_conf_t *clcf;
1730
+ ngx_http_proxy_redirect_t *pr;
1731
+ ngx_http_script_compile_t sc;
1732
+
1733
+ if (conf->upstream.store != 0) {
1734
+ ngx_conf_merge_value(conf->upstream.store,
1735
+ prev->upstream.store, 0);
1736
+
1737
+ if (conf->upstream.store_lengths == NULL) {
1738
+ conf->upstream.store_lengths = prev->upstream.store_lengths;
1739
+ conf->upstream.store_values = prev->upstream.store_values;
1740
+ }
1741
+ }
1742
+
1743
+ ngx_conf_merge_uint_value(conf->upstream.store_access,
1744
+ prev->upstream.store_access, 0600);
1745
+
1746
+ ngx_conf_merge_value(conf->upstream.buffering,
1747
+ prev->upstream.buffering, 1);
1748
+
1749
+ ngx_conf_merge_value(conf->upstream.ignore_client_abort,
1750
+ prev->upstream.ignore_client_abort, 0);
1751
+
1752
+ ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
1753
+ prev->upstream.connect_timeout, 60000);
1754
+
1755
+ ngx_conf_merge_msec_value(conf->upstream.send_timeout,
1756
+ prev->upstream.send_timeout, 60000);
1757
+
1758
+ ngx_conf_merge_msec_value(conf->upstream.read_timeout,
1759
+ prev->upstream.read_timeout, 60000);
1760
+
1761
+ ngx_conf_merge_size_value(conf->upstream.send_lowat,
1762
+ prev->upstream.send_lowat, 0);
1763
+
1764
+ ngx_conf_merge_size_value(conf->upstream.buffer_size,
1765
+ prev->upstream.buffer_size,
1766
+ (size_t) ngx_pagesize);
1767
+
1768
+ ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
1769
+ 8, ngx_pagesize);
1770
+
1771
+ if (conf->upstream.bufs.num < 2) {
1772
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1773
+ "there must be at least 2 \"proxy_buffers\"");
1774
+ return NGX_CONF_ERROR;
1775
+ }
1776
+
1777
+
1778
+ size = conf->upstream.buffer_size;
1779
+ if (size < conf->upstream.bufs.size) {
1780
+ size = conf->upstream.bufs.size;
1781
+ }
1782
+
1783
+
1784
+ ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
1785
+ prev->upstream.busy_buffers_size_conf,
1786
+ NGX_CONF_UNSET_SIZE);
1787
+
1788
+ if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
1789
+ conf->upstream.busy_buffers_size = 2 * size;
1790
+ } else {
1791
+ conf->upstream.busy_buffers_size =
1792
+ conf->upstream.busy_buffers_size_conf;
1793
+ }
1794
+
1795
+ if (conf->upstream.busy_buffers_size < size) {
1796
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1797
+ "\"proxy_busy_buffers_size\" must be equal or bigger than "
1798
+ "maximum of the value of \"proxy_buffer_size\" and "
1799
+ "one of the \"proxy_buffers\"");
1800
+
1801
+ return NGX_CONF_ERROR;
1802
+ }
1803
+
1804
+ if (conf->upstream.busy_buffers_size
1805
+ > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
1806
+ {
1807
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1808
+ "\"proxy_busy_buffers_size\" must be less than "
1809
+ "the size of all \"proxy_buffers\" minus one buffer");
1810
+
1811
+ return NGX_CONF_ERROR;
1812
+ }
1813
+
1814
+
1815
+ ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
1816
+ prev->upstream.temp_file_write_size_conf,
1817
+ NGX_CONF_UNSET_SIZE);
1818
+
1819
+ if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
1820
+ conf->upstream.temp_file_write_size = 2 * size;
1821
+ } else {
1822
+ conf->upstream.temp_file_write_size =
1823
+ conf->upstream.temp_file_write_size_conf;
1824
+ }
1825
+
1826
+ if (conf->upstream.temp_file_write_size < size) {
1827
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1828
+ "\"proxy_temp_file_write_size\" must be equal or bigger than "
1829
+ "maximum of the value of \"proxy_buffer_size\" and "
1830
+ "one of the \"proxy_buffers\"");
1831
+
1832
+ return NGX_CONF_ERROR;
1833
+ }
1834
+
1835
+ ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
1836
+ prev->upstream.max_temp_file_size_conf,
1837
+ NGX_CONF_UNSET_SIZE);
1838
+
1839
+ if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
1840
+ conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
1841
+ } else {
1842
+ conf->upstream.max_temp_file_size =
1843
+ conf->upstream.max_temp_file_size_conf;
1844
+ }
1845
+
1846
+ if (conf->upstream.max_temp_file_size != 0
1847
+ && conf->upstream.max_temp_file_size < size)
1848
+ {
1849
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1850
+ "\"proxy_max_temp_file_size\" must be equal to zero to disable "
1851
+ "the temporary files usage or must be equal or bigger than "
1852
+ "maximum of the value of \"proxy_buffer_size\" and "
1853
+ "one of the \"proxy_buffers\"");
1854
+
1855
+ return NGX_CONF_ERROR;
1856
+ }
1857
+
1858
+
1859
+ ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,
1860
+ prev->upstream.ignore_headers,
1861
+ NGX_CONF_BITMASK_SET);
1862
+
1863
+
1864
+ ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
1865
+ prev->upstream.next_upstream,
1866
+ (NGX_CONF_BITMASK_SET
1867
+ |NGX_HTTP_UPSTREAM_FT_ERROR
1868
+ |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
1869
+
1870
+ if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
1871
+ conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
1872
+ |NGX_HTTP_UPSTREAM_FT_OFF;
1873
+ }
1874
+
1875
+ if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
1876
+ prev->upstream.temp_path,
1877
+ &ngx_http_proxy_temp_path)
1878
+ != NGX_OK)
1879
+ {
1880
+ return NGX_CONF_ERROR;
1881
+ }
1882
+
1883
+
1884
+ #if (NGX_HTTP_CACHE)
1885
+
1886
+ ngx_conf_merge_ptr_value(conf->upstream.cache,
1887
+ prev->upstream.cache, NULL);
1888
+
1889
+ if (conf->upstream.cache && conf->upstream.cache->data == NULL) {
1890
+ ngx_shm_zone_t *shm_zone;
1891
+
1892
+ shm_zone = conf->upstream.cache;
1893
+
1894
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1895
+ "\"proxy_cache\" zone \"%V\" is unknown",
1896
+ &shm_zone->shm.name);
1897
+
1898
+ return NGX_CONF_ERROR;
1899
+ }
1900
+
1901
+ ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
1902
+ prev->upstream.cache_min_uses, 1);
1903
+
1904
+ ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,
1905
+ prev->upstream.cache_use_stale,
1906
+ (NGX_CONF_BITMASK_SET
1907
+ |NGX_HTTP_UPSTREAM_FT_OFF));
1908
+
1909
+ if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {
1910
+ conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
1911
+ |NGX_HTTP_UPSTREAM_FT_OFF;
1912
+ }
1913
+
1914
+ if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_ERROR) {
1915
+ conf->upstream.cache_use_stale |= NGX_HTTP_UPSTREAM_FT_NOLIVE;
1916
+ }
1917
+
1918
+ if (conf->upstream.cache_methods == 0) {
1919
+ conf->upstream.cache_methods = prev->upstream.cache_methods;
1920
+ }
1921
+
1922
+ conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;
1923
+
1924
+ ngx_conf_merge_ptr_value(conf->upstream.cache_bypass,
1925
+ prev->upstream.cache_bypass, NULL);
1926
+
1927
+ ngx_conf_merge_ptr_value(conf->upstream.no_cache,
1928
+ prev->upstream.no_cache, NULL);
1929
+
1930
+ if (conf->upstream.no_cache && conf->upstream.cache_bypass == NULL) {
1931
+ ngx_log_error(NGX_LOG_WARN, cf->log, 0,
1932
+ "\"proxy_no_cache\" functionality has been changed in 0.8.46, "
1933
+ "now it should be used together with \"proxy_cache_bypass\"");
1934
+ }
1935
+
1936
+ ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
1937
+ prev->upstream.cache_valid, NULL);
1938
+
1939
+ if (conf->cache_key.value.data == NULL) {
1940
+ conf->cache_key = prev->cache_key;
1941
+ }
1942
+
1943
+ #endif
1944
+
1945
+ if (conf->method.len == 0) {
1946
+ conf->method = prev->method;
1947
+
1948
+ } else {
1949
+ conf->method.data[conf->method.len] = ' ';
1950
+ conf->method.len++;
1951
+ }
1952
+
1953
+ ngx_conf_merge_value(conf->upstream.pass_request_headers,
1954
+ prev->upstream.pass_request_headers, 1);
1955
+ ngx_conf_merge_value(conf->upstream.pass_request_body,
1956
+ prev->upstream.pass_request_body, 1);
1957
+
1958
+ ngx_conf_merge_value(conf->upstream.intercept_errors,
1959
+ prev->upstream.intercept_errors, 0);
1960
+
1961
+ #if (NGX_HTTP_SSL)
1962
+ ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
1963
+ prev->upstream.ssl_session_reuse, 1);
1964
+ #endif
1965
+
1966
+ ngx_conf_merge_value(conf->redirect, prev->redirect, 1);
1967
+
1968
+ if (conf->redirect) {
1969
+
1970
+ if (conf->redirects == NULL) {
1971
+ conf->redirects = prev->redirects;
1972
+ }
1973
+
1974
+ if (conf->redirects == NULL && conf->url.data) {
1975
+
1976
+ conf->redirects = ngx_array_create(cf->pool, 1,
1977
+ sizeof(ngx_http_proxy_redirect_t));
1978
+ if (conf->redirects == NULL) {
1979
+ return NGX_CONF_ERROR;
1980
+ }
1981
+
1982
+ pr = ngx_array_push(conf->redirects);
1983
+ if (pr == NULL) {
1984
+ return NGX_CONF_ERROR;
1985
+ }
1986
+
1987
+ pr->handler = ngx_http_proxy_rewrite_redirect_text;
1988
+
1989
+ if (conf->vars.uri.len) {
1990
+ pr->redirect = conf->url;
1991
+ pr->replacement.text = conf->location;
1992
+
1993
+ } else {
1994
+ pr->redirect.len = conf->url.len + sizeof("/") - 1;
1995
+
1996
+ p = ngx_pnalloc(cf->pool, pr->redirect.len);
1997
+ if (p == NULL) {
1998
+ return NGX_CONF_ERROR;
1999
+ }
2000
+
2001
+ pr->redirect.data = p;
2002
+
2003
+ p = ngx_cpymem(p, conf->url.data, conf->url.len);
2004
+ *p = '/';
2005
+
2006
+ ngx_str_set(&pr->replacement.text, "/");
2007
+ }
2008
+ }
2009
+ }
2010
+
2011
+ #if (NGX_HTTP_SSL)
2012
+ if (conf->upstream.ssl == NULL) {
2013
+ conf->upstream.ssl = prev->upstream.ssl;
2014
+ }
2015
+ #endif
2016
+
2017
+ ngx_conf_merge_uint_value(conf->headers_hash_max_size,
2018
+ prev->headers_hash_max_size, 512);
2019
+
2020
+ ngx_conf_merge_uint_value(conf->headers_hash_bucket_size,
2021
+ prev->headers_hash_bucket_size, 64);
2022
+
2023
+ conf->headers_hash_bucket_size = ngx_align(conf->headers_hash_bucket_size,
2024
+ ngx_cacheline_size);
2025
+
2026
+ hash.max_size = conf->headers_hash_max_size;
2027
+ hash.bucket_size = conf->headers_hash_bucket_size;
2028
+ hash.name = "proxy_headers_hash";
2029
+
2030
+ if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
2031
+ &prev->upstream, ngx_http_proxy_hide_headers, &hash)
2032
+ != NGX_OK)
2033
+ {
2034
+ return NGX_CONF_ERROR;
2035
+ }
2036
+
2037
+ if (conf->upstream.upstream == NULL) {
2038
+ conf->upstream.upstream = prev->upstream.upstream;
2039
+ conf->vars = prev->vars;
2040
+ }
2041
+
2042
+ if (conf->proxy_lengths == NULL) {
2043
+ conf->proxy_lengths = prev->proxy_lengths;
2044
+ conf->proxy_values = prev->proxy_values;
2045
+ }
2046
+
2047
+ if (conf->upstream.upstream || conf->proxy_lengths) {
2048
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
2049
+ if (clcf->handler == NULL && clcf->lmt_excpt) {
2050
+ clcf->handler = ngx_http_proxy_handler;
2051
+ conf->location = prev->location;
2052
+ }
2053
+ }
2054
+
2055
+ if (conf->body_source.data == NULL) {
2056
+ conf->body_source = prev->body_source;
2057
+ conf->body_set_len = prev->body_set_len;
2058
+ conf->body_set = prev->body_set;
2059
+ }
2060
+
2061
+ if (conf->body_source.data && conf->body_set_len == NULL) {
2062
+
2063
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2064
+
2065
+ sc.cf = cf;
2066
+ sc.source = &conf->body_source;
2067
+ sc.flushes = &conf->flushes;
2068
+ sc.lengths = &conf->body_set_len;
2069
+ sc.values = &conf->body_set;
2070
+ sc.complete_lengths = 1;
2071
+ sc.complete_values = 1;
2072
+
2073
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2074
+ return NGX_CONF_ERROR;
2075
+ }
2076
+ }
2077
+
2078
+ if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) {
2079
+ return NGX_CONF_ERROR;
2080
+ }
2081
+
2082
+ return NGX_CONF_OK;
2083
+ }
2084
+
2085
+
2086
+ static ngx_int_t
2087
+ ngx_http_proxy_merge_headers(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *conf,
2088
+ ngx_http_proxy_loc_conf_t *prev)
2089
+ {
2090
+ u_char *p;
2091
+ size_t size;
2092
+ uintptr_t *code;
2093
+ ngx_uint_t i;
2094
+ ngx_array_t headers_names, headers_merged;
2095
+ ngx_keyval_t *src, *s, *h;
2096
+ ngx_hash_key_t *hk;
2097
+ ngx_hash_init_t hash;
2098
+ ngx_http_script_compile_t sc;
2099
+ ngx_http_script_copy_code_t *copy;
2100
+
2101
+ if (conf->headers_source == NULL) {
2102
+ conf->flushes = prev->flushes;
2103
+ conf->headers_set_len = prev->headers_set_len;
2104
+ conf->headers_set = prev->headers_set;
2105
+ conf->headers_set_hash = prev->headers_set_hash;
2106
+ conf->headers_source = prev->headers_source;
2107
+ }
2108
+
2109
+ if (conf->headers_set_hash.buckets
2110
+ && ((conf->body_source.data == NULL)
2111
+ == (prev->body_source.data == NULL))
2112
+ #if (NGX_HTTP_CACHE)
2113
+ && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
2114
+ #endif
2115
+ )
2116
+ {
2117
+ return NGX_OK;
2118
+ }
2119
+
2120
+
2121
+ if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
2122
+ != NGX_OK)
2123
+ {
2124
+ return NGX_ERROR;
2125
+ }
2126
+
2127
+ if (ngx_array_init(&headers_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
2128
+ != NGX_OK)
2129
+ {
2130
+ return NGX_ERROR;
2131
+ }
2132
+
2133
+ if (conf->headers_source == NULL) {
2134
+ conf->headers_source = ngx_array_create(cf->pool, 4,
2135
+ sizeof(ngx_keyval_t));
2136
+ if (conf->headers_source == NULL) {
2137
+ return NGX_ERROR;
2138
+ }
2139
+ }
2140
+
2141
+ conf->headers_set_len = ngx_array_create(cf->pool, 64, 1);
2142
+ if (conf->headers_set_len == NULL) {
2143
+ return NGX_ERROR;
2144
+ }
2145
+
2146
+ conf->headers_set = ngx_array_create(cf->pool, 512, 1);
2147
+ if (conf->headers_set == NULL) {
2148
+ return NGX_ERROR;
2149
+ }
2150
+
2151
+
2152
+ #if (NGX_HTTP_CACHE)
2153
+
2154
+ h = conf->upstream.cache ? ngx_http_proxy_cache_headers:
2155
+ ngx_http_proxy_headers;
2156
+ #else
2157
+
2158
+ h = ngx_http_proxy_headers;
2159
+
2160
+ #endif
2161
+
2162
+ src = conf->headers_source->elts;
2163
+ for (i = 0; i < conf->headers_source->nelts; i++) {
2164
+
2165
+ s = ngx_array_push(&headers_merged);
2166
+ if (s == NULL) {
2167
+ return NGX_ERROR;
2168
+ }
2169
+
2170
+ *s = src[i];
2171
+ }
2172
+
2173
+ while (h->key.len) {
2174
+
2175
+ src = headers_merged.elts;
2176
+ for (i = 0; i < headers_merged.nelts; i++) {
2177
+ if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
2178
+ goto next;
2179
+ }
2180
+ }
2181
+
2182
+ s = ngx_array_push(&headers_merged);
2183
+ if (s == NULL) {
2184
+ return NGX_ERROR;
2185
+ }
2186
+
2187
+ *s = *h;
2188
+
2189
+ next:
2190
+
2191
+ h++;
2192
+ }
2193
+
2194
+ if (conf->body_source.data) {
2195
+ s = ngx_array_push(&headers_merged);
2196
+ if (s == NULL) {
2197
+ return NGX_ERROR;
2198
+ }
2199
+
2200
+ ngx_str_set(&s->key, "Content-Length");
2201
+ ngx_str_set(&s->value, "$proxy_internal_body_length");
2202
+ }
2203
+
2204
+
2205
+ src = headers_merged.elts;
2206
+ for (i = 0; i < headers_merged.nelts; i++) {
2207
+
2208
+ hk = ngx_array_push(&headers_names);
2209
+ if (hk == NULL) {
2210
+ return NGX_ERROR;
2211
+ }
2212
+
2213
+ hk->key = src[i].key;
2214
+ hk->key_hash = ngx_hash_key_lc(src[i].key.data, src[i].key.len);
2215
+ hk->value = (void *) 1;
2216
+
2217
+ if (src[i].value.len == 0) {
2218
+ continue;
2219
+ }
2220
+
2221
+ if (ngx_http_script_variables_count(&src[i].value) == 0) {
2222
+ copy = ngx_array_push_n(conf->headers_set_len,
2223
+ sizeof(ngx_http_script_copy_code_t));
2224
+ if (copy == NULL) {
2225
+ return NGX_ERROR;
2226
+ }
2227
+
2228
+ copy->code = (ngx_http_script_code_pt)
2229
+ ngx_http_script_copy_len_code;
2230
+ copy->len = src[i].key.len + sizeof(": ") - 1
2231
+ + src[i].value.len + sizeof(CRLF) - 1;
2232
+
2233
+
2234
+ size = (sizeof(ngx_http_script_copy_code_t)
2235
+ + src[i].key.len + sizeof(": ") - 1
2236
+ + src[i].value.len + sizeof(CRLF) - 1
2237
+ + sizeof(uintptr_t) - 1)
2238
+ & ~(sizeof(uintptr_t) - 1);
2239
+
2240
+ copy = ngx_array_push_n(conf->headers_set, size);
2241
+ if (copy == NULL) {
2242
+ return NGX_ERROR;
2243
+ }
2244
+
2245
+ copy->code = ngx_http_script_copy_code;
2246
+ copy->len = src[i].key.len + sizeof(": ") - 1
2247
+ + src[i].value.len + sizeof(CRLF) - 1;
2248
+
2249
+ p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
2250
+
2251
+ p = ngx_cpymem(p, src[i].key.data, src[i].key.len);
2252
+ *p++ = ':'; *p++ = ' ';
2253
+ p = ngx_cpymem(p, src[i].value.data, src[i].value.len);
2254
+ *p++ = CR; *p = LF;
2255
+
2256
+ } else {
2257
+ copy = ngx_array_push_n(conf->headers_set_len,
2258
+ sizeof(ngx_http_script_copy_code_t));
2259
+ if (copy == NULL) {
2260
+ return NGX_ERROR;
2261
+ }
2262
+
2263
+ copy->code = (ngx_http_script_code_pt)
2264
+ ngx_http_script_copy_len_code;
2265
+ copy->len = src[i].key.len + sizeof(": ") - 1;
2266
+
2267
+
2268
+ size = (sizeof(ngx_http_script_copy_code_t)
2269
+ + src[i].key.len + sizeof(": ") - 1 + sizeof(uintptr_t) - 1)
2270
+ & ~(sizeof(uintptr_t) - 1);
2271
+
2272
+ copy = ngx_array_push_n(conf->headers_set, size);
2273
+ if (copy == NULL) {
2274
+ return NGX_ERROR;
2275
+ }
2276
+
2277
+ copy->code = ngx_http_script_copy_code;
2278
+ copy->len = src[i].key.len + sizeof(": ") - 1;
2279
+
2280
+ p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
2281
+ p = ngx_cpymem(p, src[i].key.data, src[i].key.len);
2282
+ *p++ = ':'; *p = ' ';
2283
+
2284
+
2285
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2286
+
2287
+ sc.cf = cf;
2288
+ sc.source = &src[i].value;
2289
+ sc.flushes = &conf->flushes;
2290
+ sc.lengths = &conf->headers_set_len;
2291
+ sc.values = &conf->headers_set;
2292
+
2293
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2294
+ return NGX_ERROR;
2295
+ }
2296
+
2297
+
2298
+ copy = ngx_array_push_n(conf->headers_set_len,
2299
+ sizeof(ngx_http_script_copy_code_t));
2300
+ if (copy == NULL) {
2301
+ return NGX_ERROR;
2302
+ }
2303
+
2304
+ copy->code = (ngx_http_script_code_pt)
2305
+ ngx_http_script_copy_len_code;
2306
+ copy->len = sizeof(CRLF) - 1;
2307
+
2308
+
2309
+ size = (sizeof(ngx_http_script_copy_code_t)
2310
+ + sizeof(CRLF) - 1 + sizeof(uintptr_t) - 1)
2311
+ & ~(sizeof(uintptr_t) - 1);
2312
+
2313
+ copy = ngx_array_push_n(conf->headers_set, size);
2314
+ if (copy == NULL) {
2315
+ return NGX_ERROR;
2316
+ }
2317
+
2318
+ copy->code = ngx_http_script_copy_code;
2319
+ copy->len = sizeof(CRLF) - 1;
2320
+
2321
+ p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
2322
+ *p++ = CR; *p = LF;
2323
+ }
2324
+
2325
+ code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t));
2326
+ if (code == NULL) {
2327
+ return NGX_ERROR;
2328
+ }
2329
+
2330
+ *code = (uintptr_t) NULL;
2331
+
2332
+ code = ngx_array_push_n(conf->headers_set, sizeof(uintptr_t));
2333
+ if (code == NULL) {
2334
+ return NGX_ERROR;
2335
+ }
2336
+
2337
+ *code = (uintptr_t) NULL;
2338
+ }
2339
+
2340
+ code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t));
2341
+ if (code == NULL) {
2342
+ return NGX_ERROR;
2343
+ }
2344
+
2345
+ *code = (uintptr_t) NULL;
2346
+
2347
+
2348
+ hash.hash = &conf->headers_set_hash;
2349
+ hash.key = ngx_hash_key_lc;
2350
+ hash.max_size = conf->headers_hash_max_size;
2351
+ hash.bucket_size = conf->headers_hash_bucket_size;
2352
+ hash.name = "proxy_headers_hash";
2353
+ hash.pool = cf->pool;
2354
+ hash.temp_pool = NULL;
2355
+
2356
+ return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
2357
+ }
2358
+
2359
+
2360
+ static char *
2361
+ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2362
+ {
2363
+ ngx_http_proxy_loc_conf_t *plcf = conf;
2364
+
2365
+ size_t add;
2366
+ u_short port;
2367
+ ngx_str_t *value, *url;
2368
+ ngx_url_t u;
2369
+ ngx_uint_t n;
2370
+ ngx_http_core_loc_conf_t *clcf;
2371
+ ngx_http_script_compile_t sc;
2372
+
2373
+ if (plcf->upstream.upstream || plcf->proxy_lengths) {
2374
+ return "is duplicate";
2375
+ }
2376
+
2377
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
2378
+
2379
+ clcf->handler = ngx_http_proxy_handler;
2380
+
2381
+ if (clcf->name.data[clcf->name.len - 1] == '/') {
2382
+ clcf->auto_redirect = 1;
2383
+ }
2384
+
2385
+ value = cf->args->elts;
2386
+
2387
+ url = &value[1];
2388
+
2389
+ n = ngx_http_script_variables_count(url);
2390
+
2391
+ if (n) {
2392
+
2393
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2394
+
2395
+ sc.cf = cf;
2396
+ sc.source = url;
2397
+ sc.lengths = &plcf->proxy_lengths;
2398
+ sc.values = &plcf->proxy_values;
2399
+ sc.variables = n;
2400
+ sc.complete_lengths = 1;
2401
+ sc.complete_values = 1;
2402
+
2403
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2404
+ return NGX_CONF_ERROR;
2405
+ }
2406
+
2407
+ #if (NGX_HTTP_SSL)
2408
+ if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) {
2409
+ return NGX_CONF_ERROR;
2410
+ }
2411
+ #endif
2412
+
2413
+ return NGX_CONF_OK;
2414
+ }
2415
+
2416
+ if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) {
2417
+ add = 7;
2418
+ port = 80;
2419
+
2420
+ } else if (ngx_strncasecmp(url->data, (u_char *) "https://", 8) == 0) {
2421
+
2422
+ #if (NGX_HTTP_SSL)
2423
+ if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) {
2424
+ return NGX_CONF_ERROR;
2425
+ }
2426
+
2427
+ add = 8;
2428
+ port = 443;
2429
+ #else
2430
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2431
+ "https protocol requires SSL support");
2432
+ return NGX_CONF_ERROR;
2433
+ #endif
2434
+
2435
+ } else {
2436
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix");
2437
+ return NGX_CONF_ERROR;
2438
+ }
2439
+
2440
+ ngx_memzero(&u, sizeof(ngx_url_t));
2441
+
2442
+ u.url.len = url->len - add;
2443
+ u.url.data = url->data + add;
2444
+ u.default_port = port;
2445
+ u.uri_part = 1;
2446
+ u.no_resolve = 1;
2447
+
2448
+ plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
2449
+ if (plcf->upstream.upstream == NULL) {
2450
+ return NGX_CONF_ERROR;
2451
+ }
2452
+
2453
+ plcf->vars.schema.len = add;
2454
+ plcf->vars.schema.data = url->data;
2455
+ plcf->vars.key_start = plcf->vars.schema;
2456
+
2457
+ ngx_http_proxy_set_vars(&u, &plcf->vars);
2458
+
2459
+ plcf->location = clcf->name;
2460
+
2461
+ if (clcf->named
2462
+ #if (NGX_PCRE)
2463
+ || clcf->regex
2464
+ #endif
2465
+ || clcf->noname)
2466
+ {
2467
+ if (plcf->vars.uri.len) {
2468
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2469
+ "\"proxy_pass\" may not have URI part in "
2470
+ "location given by regular expression, "
2471
+ "or inside named location, "
2472
+ "or inside the \"if\" statement, "
2473
+ "or inside the \"limit_except\" block");
2474
+ return NGX_CONF_ERROR;
2475
+ }
2476
+
2477
+ plcf->location.len = 0;
2478
+ }
2479
+
2480
+ plcf->url = *url;
2481
+
2482
+ return NGX_CONF_OK;
2483
+ }
2484
+
2485
+
2486
+ static char *
2487
+ ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2488
+ {
2489
+ ngx_http_proxy_loc_conf_t *plcf = conf;
2490
+
2491
+ u_char *p;
2492
+ ngx_str_t *value;
2493
+ ngx_array_t *vars_lengths, *vars_values;
2494
+ ngx_http_script_compile_t sc;
2495
+ ngx_http_proxy_redirect_t *pr;
2496
+
2497
+ if (plcf->redirect == 0) {
2498
+ return NGX_CONF_OK;
2499
+ }
2500
+
2501
+ plcf->redirect = 1;
2502
+
2503
+ value = cf->args->elts;
2504
+
2505
+ if (cf->args->nelts == 2) {
2506
+ if (ngx_strcmp(value[1].data, "off") == 0) {
2507
+ plcf->redirect = 0;
2508
+ plcf->redirects = NULL;
2509
+ return NGX_CONF_OK;
2510
+ }
2511
+
2512
+ if (ngx_strcmp(value[1].data, "false") == 0) {
2513
+ ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
2514
+ "invalid parameter \"false\", use \"off\" instead");
2515
+ plcf->redirect = 0;
2516
+ plcf->redirects = NULL;
2517
+ return NGX_CONF_OK;
2518
+ }
2519
+
2520
+ if (ngx_strcmp(value[1].data, "default") != 0) {
2521
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2522
+ "invalid parameter \"%V\"", &value[1]);
2523
+ return NGX_CONF_ERROR;
2524
+ }
2525
+ }
2526
+
2527
+ if (plcf->redirects == NULL) {
2528
+ plcf->redirects = ngx_array_create(cf->pool, 1,
2529
+ sizeof(ngx_http_proxy_redirect_t));
2530
+ if (plcf->redirects == NULL) {
2531
+ return NGX_CONF_ERROR;
2532
+ }
2533
+ }
2534
+
2535
+ pr = ngx_array_push(plcf->redirects);
2536
+ if (pr == NULL) {
2537
+ return NGX_CONF_ERROR;
2538
+ }
2539
+
2540
+ if (ngx_strcmp(value[1].data, "default") == 0) {
2541
+ if (plcf->proxy_lengths) {
2542
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2543
+ "\"proxy_redirect default\" may not be used "
2544
+ "with \"proxy_pass\" directive with variables");
2545
+ return NGX_CONF_ERROR;
2546
+ }
2547
+
2548
+ if (plcf->url.data == NULL) {
2549
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2550
+ "\"proxy_redirect default\" must go "
2551
+ "after the \"proxy_pass\" directive");
2552
+ return NGX_CONF_ERROR;
2553
+ }
2554
+
2555
+ pr->handler = ngx_http_proxy_rewrite_redirect_text;
2556
+
2557
+ if (plcf->vars.uri.len) {
2558
+ pr->redirect = plcf->url;
2559
+ pr->replacement.text = plcf->location;
2560
+
2561
+ } else {
2562
+ pr->redirect.len = plcf->url.len + sizeof("/") - 1;
2563
+
2564
+ p = ngx_pnalloc(cf->pool, pr->redirect.len);
2565
+ if (p == NULL) {
2566
+ return NGX_CONF_ERROR;
2567
+ }
2568
+
2569
+ pr->redirect.data = p;
2570
+
2571
+ p = ngx_cpymem(p, plcf->url.data, plcf->url.len);
2572
+ *p = '/';
2573
+
2574
+ ngx_str_set(&pr->replacement.text, "/");
2575
+ }
2576
+
2577
+ return NGX_CONF_OK;
2578
+ }
2579
+
2580
+ if (ngx_http_script_variables_count(&value[2]) == 0) {
2581
+ pr->handler = ngx_http_proxy_rewrite_redirect_text;
2582
+ pr->redirect = value[1];
2583
+ pr->replacement.text = value[2];
2584
+
2585
+ return NGX_CONF_OK;
2586
+ }
2587
+
2588
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2589
+
2590
+ vars_lengths = NULL;
2591
+ vars_values = NULL;
2592
+
2593
+ sc.cf = cf;
2594
+ sc.source = &value[2];
2595
+ sc.lengths = &vars_lengths;
2596
+ sc.values = &vars_values;
2597
+ sc.complete_lengths = 1;
2598
+ sc.complete_values = 1;
2599
+
2600
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2601
+ return NGX_CONF_ERROR;
2602
+ }
2603
+
2604
+ pr->handler = ngx_http_proxy_rewrite_redirect_vars;
2605
+ pr->redirect = value[1];
2606
+ pr->replacement.vars.lengths = vars_lengths->elts;
2607
+ pr->replacement.vars.values = vars_values->elts;
2608
+
2609
+ return NGX_CONF_OK;
2610
+ }
2611
+
2612
+
2613
+ static char *
2614
+ ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2615
+ {
2616
+ ngx_http_proxy_loc_conf_t *plcf = conf;
2617
+
2618
+ ngx_str_t *value;
2619
+ ngx_http_script_compile_t sc;
2620
+
2621
+ if (plcf->upstream.store != NGX_CONF_UNSET
2622
+ || plcf->upstream.store_lengths)
2623
+ {
2624
+ return "is duplicate";
2625
+ }
2626
+
2627
+ value = cf->args->elts;
2628
+
2629
+ if (ngx_strcmp(value[1].data, "off") == 0) {
2630
+ plcf->upstream.store = 0;
2631
+ return NGX_CONF_OK;
2632
+ }
2633
+
2634
+ #if (NGX_HTTP_CACHE)
2635
+
2636
+ if (plcf->upstream.cache != NGX_CONF_UNSET_PTR
2637
+ && plcf->upstream.cache != NULL)
2638
+ {
2639
+ return "is incompatible with \"proxy_cache\"";
2640
+ }
2641
+
2642
+ #endif
2643
+
2644
+ if (ngx_strcmp(value[1].data, "on") == 0) {
2645
+ plcf->upstream.store = 1;
2646
+ return NGX_CONF_OK;
2647
+ }
2648
+
2649
+ /* include the terminating '\0' into script */
2650
+ value[1].len++;
2651
+
2652
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2653
+
2654
+ sc.cf = cf;
2655
+ sc.source = &value[1];
2656
+ sc.lengths = &plcf->upstream.store_lengths;
2657
+ sc.values = &plcf->upstream.store_values;
2658
+ sc.variables = ngx_http_script_variables_count(&value[1]);
2659
+ sc.complete_lengths = 1;
2660
+ sc.complete_values = 1;
2661
+
2662
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2663
+ return NGX_CONF_ERROR;
2664
+ }
2665
+
2666
+ return NGX_CONF_OK;
2667
+ }
2668
+
2669
+
2670
+ #if (NGX_HTTP_CACHE)
2671
+
2672
+ static char *
2673
+ ngx_http_proxy_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2674
+ {
2675
+ ngx_http_proxy_loc_conf_t *plcf = conf;
2676
+
2677
+ ngx_str_t *value;
2678
+
2679
+ value = cf->args->elts;
2680
+
2681
+ if (plcf->upstream.cache != NGX_CONF_UNSET_PTR) {
2682
+ return "is duplicate";
2683
+ }
2684
+
2685
+ if (ngx_strcmp(value[1].data, "off") == 0) {
2686
+ plcf->upstream.cache = NULL;
2687
+ return NGX_CONF_OK;
2688
+ }
2689
+
2690
+ if (plcf->upstream.store > 0 || plcf->upstream.store_lengths) {
2691
+ return "is incompatible with \"proxy_store\"";
2692
+ }
2693
+
2694
+ plcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
2695
+ &ngx_http_proxy_module);
2696
+ if (plcf->upstream.cache == NULL) {
2697
+ return NGX_CONF_ERROR;
2698
+ }
2699
+
2700
+ return NGX_CONF_OK;
2701
+ }
2702
+
2703
+
2704
+ static char *
2705
+ ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2706
+ {
2707
+ ngx_http_proxy_loc_conf_t *plcf = conf;
2708
+
2709
+ ngx_str_t *value;
2710
+ ngx_http_compile_complex_value_t ccv;
2711
+
2712
+ value = cf->args->elts;
2713
+
2714
+ if (plcf->cache_key.value.len) {
2715
+ return "is duplicate";
2716
+ }
2717
+
2718
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
2719
+
2720
+ ccv.cf = cf;
2721
+ ccv.value = &value[1];
2722
+ ccv.complex_value = &plcf->cache_key;
2723
+
2724
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
2725
+ return NGX_CONF_ERROR;
2726
+ }
2727
+
2728
+ return NGX_CONF_OK;
2729
+ }
2730
+
2731
+ #endif
2732
+
2733
+
2734
+ static char *
2735
+ ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data)
2736
+ {
2737
+ #if (NGX_FREEBSD)
2738
+ ssize_t *np = data;
2739
+
2740
+ if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
2741
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2742
+ "\"proxy_send_lowat\" must be less than %d "
2743
+ "(sysctl net.inet.tcp.sendspace)",
2744
+ ngx_freebsd_net_inet_tcp_sendspace);
2745
+
2746
+ return NGX_CONF_ERROR;
2747
+ }
2748
+
2749
+ #elif !(NGX_HAVE_SO_SNDLOWAT)
2750
+ ssize_t *np = data;
2751
+
2752
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2753
+ "\"proxy_send_lowat\" is not supported, ignored");
2754
+
2755
+ *np = 0;
2756
+
2757
+ #endif
2758
+
2759
+ return NGX_CONF_OK;
2760
+ }
2761
+
2762
+
2763
+ #if (NGX_HTTP_SSL)
2764
+
2765
+ static ngx_int_t
2766
+ ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf)
2767
+ {
2768
+ ngx_pool_cleanup_t *cln;
2769
+
2770
+ plcf->upstream.ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t));
2771
+ if (plcf->upstream.ssl == NULL) {
2772
+ return NGX_ERROR;
2773
+ }
2774
+
2775
+ plcf->upstream.ssl->log = cf->log;
2776
+
2777
+ if (ngx_ssl_create(plcf->upstream.ssl,
2778
+ NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1
2779
+ |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2,
2780
+ NULL)
2781
+ != NGX_OK)
2782
+ {
2783
+ return NGX_ERROR;
2784
+ }
2785
+
2786
+ cln = ngx_pool_cleanup_add(cf->pool, 0);
2787
+ if (cln == NULL) {
2788
+ return NGX_ERROR;
2789
+ }
2790
+
2791
+ cln->handler = ngx_ssl_cleanup_ctx;
2792
+ cln->data = plcf->upstream.ssl;
2793
+
2794
+ return NGX_OK;
2795
+ }
2796
+
2797
+ #endif
2798
+
2799
+
2800
+ static void
2801
+ ngx_http_proxy_set_vars(ngx_url_t *u, ngx_http_proxy_vars_t *v)
2802
+ {
2803
+ if (u->family != AF_UNIX) {
2804
+
2805
+ if (u->no_port || u->port == u->default_port) {
2806
+
2807
+ v->host_header = u->host;
2808
+
2809
+ if (u->default_port == 80) {
2810
+ ngx_str_set(&v->port, "80");
2811
+
2812
+ } else {
2813
+ ngx_str_set(&v->port, "443");
2814
+ }
2815
+
2816
+ } else {
2817
+ v->host_header.len = u->host.len + 1 + u->port_text.len;
2818
+ v->host_header.data = u->host.data;
2819
+ v->port = u->port_text;
2820
+ }
2821
+
2822
+ v->key_start.len += v->host_header.len;
2823
+
2824
+ } else {
2825
+ ngx_str_set(&v->host_header, "localhost");
2826
+ ngx_str_null(&v->port);
2827
+ v->key_start.len += sizeof("unix:") - 1 + u->host.len + 1;
2828
+ }
2829
+
2830
+ v->uri = u->uri;
2831
+ }