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,243 @@
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 {
14
+ size_t sbrk_size;
15
+ } ngx_http_degradation_main_conf_t;
16
+
17
+
18
+ typedef struct {
19
+ ngx_uint_t degrade;
20
+ } ngx_http_degradation_loc_conf_t;
21
+
22
+
23
+ static ngx_conf_enum_t ngx_http_degrade[] = {
24
+ { ngx_string("204"), 204 },
25
+ { ngx_string("444"), 444 },
26
+ { ngx_null_string, 0 }
27
+ };
28
+
29
+
30
+ static void *ngx_http_degradation_create_main_conf(ngx_conf_t *cf);
31
+ static void *ngx_http_degradation_create_loc_conf(ngx_conf_t *cf);
32
+ static char *ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent,
33
+ void *child);
34
+ static char *ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd,
35
+ void *conf);
36
+ static ngx_int_t ngx_http_degradation_init(ngx_conf_t *cf);
37
+
38
+
39
+ static ngx_command_t ngx_http_degradation_commands[] = {
40
+
41
+ { ngx_string("degradation"),
42
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
43
+ ngx_http_degradation,
44
+ NGX_HTTP_MAIN_CONF_OFFSET,
45
+ 0,
46
+ NULL },
47
+
48
+ { ngx_string("degrade"),
49
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
50
+ ngx_conf_set_enum_slot,
51
+ NGX_HTTP_LOC_CONF_OFFSET,
52
+ offsetof(ngx_http_degradation_loc_conf_t, degrade),
53
+ &ngx_http_degrade },
54
+
55
+ ngx_null_command
56
+ };
57
+
58
+
59
+ static ngx_http_module_t ngx_http_degradation_module_ctx = {
60
+ NULL, /* preconfiguration */
61
+ ngx_http_degradation_init, /* postconfiguration */
62
+
63
+ ngx_http_degradation_create_main_conf, /* create main configuration */
64
+ NULL, /* init main configuration */
65
+
66
+ NULL, /* create server configuration */
67
+ NULL, /* merge server configuration */
68
+
69
+ ngx_http_degradation_create_loc_conf, /* create location configuration */
70
+ ngx_http_degradation_merge_loc_conf /* merge location configuration */
71
+ };
72
+
73
+
74
+ ngx_module_t ngx_http_degradation_module = {
75
+ NGX_MODULE_V1,
76
+ &ngx_http_degradation_module_ctx, /* module context */
77
+ ngx_http_degradation_commands, /* module directives */
78
+ NGX_HTTP_MODULE, /* module type */
79
+ NULL, /* init master */
80
+ NULL, /* init module */
81
+ NULL, /* init process */
82
+ NULL, /* init thread */
83
+ NULL, /* exit thread */
84
+ NULL, /* exit process */
85
+ NULL, /* exit master */
86
+ NGX_MODULE_V1_PADDING
87
+ };
88
+
89
+
90
+ static ngx_int_t
91
+ ngx_http_degradation_handler(ngx_http_request_t *r)
92
+ {
93
+ ngx_http_degradation_loc_conf_t *dlcf;
94
+
95
+ dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module);
96
+
97
+ if (dlcf->degrade && ngx_http_degraded(r)) {
98
+ return dlcf->degrade;
99
+ }
100
+
101
+ return NGX_DECLINED;
102
+ }
103
+
104
+
105
+ ngx_uint_t
106
+ ngx_http_degraded(ngx_http_request_t *r)
107
+ {
108
+ time_t now;
109
+ ngx_uint_t log;
110
+ static size_t sbrk_size;
111
+ static time_t sbrk_time;
112
+ ngx_http_degradation_main_conf_t *dmcf;
113
+
114
+ dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module);
115
+
116
+ if (dmcf->sbrk_size) {
117
+
118
+ log = 0;
119
+ now = ngx_time();
120
+
121
+ /* lock mutex */
122
+
123
+ if (now != sbrk_time) {
124
+
125
+ /*
126
+ * ELF/i386 is loaded at 0x08000000, 128M
127
+ * ELF/amd64 is loaded at 0x00400000, 4M
128
+ *
129
+ * use a function address to substract the loading address
130
+ */
131
+
132
+ sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF);
133
+ sbrk_time = now;
134
+ log = 1;
135
+ }
136
+
137
+ /* unlock mutex */
138
+
139
+ if (sbrk_size >= dmcf->sbrk_size) {
140
+ if (log) {
141
+ ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
142
+ "degradation sbrk:%uzM",
143
+ sbrk_size / (1024 * 1024));
144
+ }
145
+
146
+ return 1;
147
+ }
148
+ }
149
+
150
+ return 0;
151
+ }
152
+
153
+
154
+ static void *
155
+ ngx_http_degradation_create_main_conf(ngx_conf_t *cf)
156
+ {
157
+ ngx_http_degradation_main_conf_t *dmcf;
158
+
159
+ dmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_degradation_main_conf_t));
160
+ if (dmcf == NULL) {
161
+ return NULL;
162
+ }
163
+
164
+ return dmcf;
165
+ }
166
+
167
+
168
+ static void *
169
+ ngx_http_degradation_create_loc_conf(ngx_conf_t *cf)
170
+ {
171
+ ngx_http_degradation_loc_conf_t *conf;
172
+
173
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_degradation_loc_conf_t));
174
+ if (conf == NULL) {
175
+ return NULL;
176
+ }
177
+
178
+ conf->degrade = NGX_CONF_UNSET_UINT;
179
+
180
+ return conf;
181
+ }
182
+
183
+
184
+ static char *
185
+ ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
186
+ {
187
+ ngx_http_degradation_loc_conf_t *prev = parent;
188
+ ngx_http_degradation_loc_conf_t *conf = child;
189
+
190
+ ngx_conf_merge_uint_value(conf->degrade, prev->degrade, 0);
191
+
192
+ return NGX_CONF_OK;
193
+ }
194
+
195
+
196
+ static char *
197
+ ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
198
+ {
199
+ ngx_http_degradation_main_conf_t *dmcf = conf;
200
+
201
+ ngx_str_t *value, s;
202
+
203
+ value = cf->args->elts;
204
+
205
+ if (ngx_strncmp(value[1].data, "sbrk=", 5) == 0) {
206
+
207
+ s.len = value[1].len - 5;
208
+ s.data = value[1].data + 5;
209
+
210
+ dmcf->sbrk_size = ngx_parse_size(&s);
211
+ if (dmcf->sbrk_size == (size_t) NGX_ERROR) {
212
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
213
+ "invalid sbrk size \"%V\"", &value[1]);
214
+ return NGX_CONF_ERROR;
215
+ }
216
+
217
+ return NGX_CONF_OK;
218
+ }
219
+
220
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
221
+ "invalid parameter \"%V\"", &value[1]);
222
+
223
+ return NGX_CONF_ERROR;
224
+ }
225
+
226
+
227
+ static ngx_int_t
228
+ ngx_http_degradation_init(ngx_conf_t *cf)
229
+ {
230
+ ngx_http_handler_pt *h;
231
+ ngx_http_core_main_conf_t *cmcf;
232
+
233
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
234
+
235
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
236
+ if (h == NULL) {
237
+ return NGX_ERROR;
238
+ }
239
+
240
+ *h = ngx_http_degradation_handler;
241
+
242
+ return NGX_OK;
243
+ }
@@ -0,0 +1,140 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+ #include <ngx_config.h>
8
+ #include <ngx_core.h>
9
+ #include <ngx_http.h>
10
+
11
+
12
+ static char *ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd,
13
+ void *conf);
14
+
15
+ static ngx_command_t ngx_http_empty_gif_commands[] = {
16
+
17
+ { ngx_string("empty_gif"),
18
+ NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
19
+ ngx_http_empty_gif,
20
+ 0,
21
+ 0,
22
+ NULL },
23
+
24
+ ngx_null_command
25
+ };
26
+
27
+
28
+ /* the minimal single pixel transparent GIF, 43 bytes */
29
+
30
+ static u_char ngx_empty_gif[] = {
31
+
32
+ 'G', 'I', 'F', '8', '9', 'a', /* header */
33
+
34
+ /* logical screen descriptor */
35
+ 0x01, 0x00, /* logical screen width */
36
+ 0x01, 0x00, /* logical screen height */
37
+ 0x80, /* global 1-bit color table */
38
+ 0x01, /* background color #1 */
39
+ 0x00, /* no aspect ratio */
40
+
41
+ /* global color table */
42
+ 0x00, 0x00, 0x00, /* #0: black */
43
+ 0xff, 0xff, 0xff, /* #1: white */
44
+
45
+ /* graphic control extension */
46
+ 0x21, /* extension introducer */
47
+ 0xf9, /* graphic control label */
48
+ 0x04, /* block size */
49
+ 0x01, /* transparent color is given, */
50
+ /* no disposal specified, */
51
+ /* user input is not expected */
52
+ 0x00, 0x00, /* delay time */
53
+ 0x01, /* transparent color #1 */
54
+ 0x00, /* block terminator */
55
+
56
+ /* image descriptor */
57
+ 0x2c, /* image separator */
58
+ 0x00, 0x00, /* image left position */
59
+ 0x00, 0x00, /* image top position */
60
+ 0x01, 0x00, /* image width */
61
+ 0x01, 0x00, /* image height */
62
+ 0x00, /* no local color table, no interlaced */
63
+
64
+ /* table based image data */
65
+ 0x02, /* LZW minimum code size, */
66
+ /* must be at least 2-bit */
67
+ 0x02, /* block size */
68
+ 0x4c, 0x01, /* compressed bytes 01_001_100, 0000000_1 */
69
+ /* 100: clear code */
70
+ /* 001: 1 */
71
+ /* 101: end of information code */
72
+ 0x00, /* block terminator */
73
+
74
+ 0x3B /* trailer */
75
+ };
76
+
77
+
78
+ static ngx_http_module_t ngx_http_empty_gif_module_ctx = {
79
+ NULL, /* preconfiguration */
80
+ NULL, /* postconfiguration */
81
+
82
+ NULL, /* create main configuration */
83
+ NULL, /* init main configuration */
84
+
85
+ NULL, /* create server configuration */
86
+ NULL, /* merge server configuration */
87
+
88
+ NULL, /* create location configuration */
89
+ NULL /* merge location configuration */
90
+ };
91
+
92
+
93
+ ngx_module_t ngx_http_empty_gif_module = {
94
+ NGX_MODULE_V1,
95
+ &ngx_http_empty_gif_module_ctx, /* module context */
96
+ ngx_http_empty_gif_commands, /* module directives */
97
+ NGX_HTTP_MODULE, /* module type */
98
+ NULL, /* init master */
99
+ NULL, /* init module */
100
+ NULL, /* init process */
101
+ NULL, /* init thread */
102
+ NULL, /* exit thread */
103
+ NULL, /* exit process */
104
+ NULL, /* exit master */
105
+ NGX_MODULE_V1_PADDING
106
+ };
107
+
108
+
109
+ static ngx_str_t ngx_http_gif_type = ngx_string("image/gif");
110
+
111
+
112
+ static ngx_int_t
113
+ ngx_http_empty_gif_handler(ngx_http_request_t *r)
114
+ {
115
+ ngx_http_complex_value_t cv;
116
+
117
+ if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
118
+ return NGX_HTTP_NOT_ALLOWED;
119
+ }
120
+
121
+ ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
122
+
123
+ cv.value.len = sizeof(ngx_empty_gif);
124
+ cv.value.data = ngx_empty_gif;
125
+ r->headers_out.last_modified_time = 23349600;
126
+
127
+ return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_gif_type, &cv);
128
+ }
129
+
130
+
131
+ static char *
132
+ ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
133
+ {
134
+ ngx_http_core_loc_conf_t *clcf;
135
+
136
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
137
+ clcf->handler = ngx_http_empty_gif_handler;
138
+
139
+ return NGX_CONF_OK;
140
+ }
@@ -0,0 +1,2916 @@
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 {
14
+ ngx_http_upstream_conf_t upstream;
15
+
16
+ ngx_str_t index;
17
+
18
+ ngx_array_t *flushes;
19
+ ngx_array_t *params_len;
20
+ ngx_array_t *params;
21
+ ngx_array_t *params_source;
22
+ ngx_array_t *catch_stderr;
23
+
24
+ ngx_array_t *fastcgi_lengths;
25
+ ngx_array_t *fastcgi_values;
26
+
27
+ ngx_hash_t headers_hash;
28
+ ngx_uint_t header_params;
29
+
30
+ #if (NGX_HTTP_CACHE)
31
+ ngx_http_complex_value_t cache_key;
32
+ #endif
33
+
34
+ #if (NGX_PCRE)
35
+ ngx_regex_t *split_regex;
36
+ ngx_str_t split_name;
37
+ #endif
38
+ } ngx_http_fastcgi_loc_conf_t;
39
+
40
+
41
+ typedef enum {
42
+ ngx_http_fastcgi_st_version = 0,
43
+ ngx_http_fastcgi_st_type,
44
+ ngx_http_fastcgi_st_request_id_hi,
45
+ ngx_http_fastcgi_st_request_id_lo,
46
+ ngx_http_fastcgi_st_content_length_hi,
47
+ ngx_http_fastcgi_st_content_length_lo,
48
+ ngx_http_fastcgi_st_padding_length,
49
+ ngx_http_fastcgi_st_reserved,
50
+ ngx_http_fastcgi_st_data,
51
+ ngx_http_fastcgi_st_padding
52
+ } ngx_http_fastcgi_state_e;
53
+
54
+
55
+ typedef struct {
56
+ u_char *start;
57
+ u_char *end;
58
+ } ngx_http_fastcgi_split_part_t;
59
+
60
+
61
+ typedef struct {
62
+ ngx_http_fastcgi_state_e state;
63
+ u_char *pos;
64
+ u_char *last;
65
+ ngx_uint_t type;
66
+ size_t length;
67
+ size_t padding;
68
+
69
+ unsigned fastcgi_stdout:1;
70
+ unsigned large_stderr:1;
71
+
72
+ ngx_array_t *split_parts;
73
+
74
+ ngx_str_t script_name;
75
+ ngx_str_t path_info;
76
+ } ngx_http_fastcgi_ctx_t;
77
+
78
+
79
+ #define NGX_HTTP_FASTCGI_RESPONDER 1
80
+
81
+ #define NGX_HTTP_FASTCGI_BEGIN_REQUEST 1
82
+ #define NGX_HTTP_FASTCGI_ABORT_REQUEST 2
83
+ #define NGX_HTTP_FASTCGI_END_REQUEST 3
84
+ #define NGX_HTTP_FASTCGI_PARAMS 4
85
+ #define NGX_HTTP_FASTCGI_STDIN 5
86
+ #define NGX_HTTP_FASTCGI_STDOUT 6
87
+ #define NGX_HTTP_FASTCGI_STDERR 7
88
+ #define NGX_HTTP_FASTCGI_DATA 8
89
+
90
+
91
+ typedef struct {
92
+ u_char version;
93
+ u_char type;
94
+ u_char request_id_hi;
95
+ u_char request_id_lo;
96
+ u_char content_length_hi;
97
+ u_char content_length_lo;
98
+ u_char padding_length;
99
+ u_char reserved;
100
+ } ngx_http_fastcgi_header_t;
101
+
102
+
103
+ typedef struct {
104
+ u_char role_hi;
105
+ u_char role_lo;
106
+ u_char flags;
107
+ u_char reserved[5];
108
+ } ngx_http_fastcgi_begin_request_t;
109
+
110
+
111
+ typedef struct {
112
+ u_char version;
113
+ u_char type;
114
+ u_char request_id_hi;
115
+ u_char request_id_lo;
116
+ } ngx_http_fastcgi_header_small_t;
117
+
118
+
119
+ typedef struct {
120
+ ngx_http_fastcgi_header_t h0;
121
+ ngx_http_fastcgi_begin_request_t br;
122
+ ngx_http_fastcgi_header_small_t h1;
123
+ } ngx_http_fastcgi_request_start_t;
124
+
125
+
126
+ static ngx_int_t ngx_http_fastcgi_eval(ngx_http_request_t *r,
127
+ ngx_http_fastcgi_loc_conf_t *flcf);
128
+ #if (NGX_HTTP_CACHE)
129
+ static ngx_int_t ngx_http_fastcgi_create_key(ngx_http_request_t *r);
130
+ #endif
131
+ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r);
132
+ static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r);
133
+ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r);
134
+ static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
135
+ ngx_buf_t *buf);
136
+ static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
137
+ ngx_http_fastcgi_ctx_t *f);
138
+ static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r);
139
+ static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
140
+ ngx_int_t rc);
141
+
142
+ static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf);
143
+ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
144
+ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
145
+ void *parent, void *child);
146
+ static ngx_int_t ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
147
+ ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev);
148
+
149
+ static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
150
+ ngx_http_variable_value_t *v, uintptr_t data);
151
+ static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
152
+ ngx_http_variable_value_t *v, uintptr_t data);
153
+ static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r,
154
+ ngx_http_fastcgi_loc_conf_t *flcf);
155
+
156
+ static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
157
+ void *conf);
158
+ static char *ngx_http_fastcgi_split_path_info(ngx_conf_t *cf,
159
+ ngx_command_t *cmd, void *conf);
160
+ static char *ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
161
+ void *conf);
162
+ #if (NGX_HTTP_CACHE)
163
+ static char *ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd,
164
+ void *conf);
165
+ static char *ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
166
+ void *conf);
167
+ #endif
168
+
169
+ static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
170
+ void *data);
171
+
172
+
173
+ static ngx_conf_post_t ngx_http_fastcgi_lowat_post =
174
+ { ngx_http_fastcgi_lowat_check };
175
+
176
+
177
+ static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = {
178
+ { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
179
+ { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
180
+ { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
181
+ { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
182
+ { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
183
+ { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
184
+ { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
185
+ { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
186
+ { ngx_null_string, 0 }
187
+ };
188
+
189
+
190
+ ngx_module_t ngx_http_fastcgi_module;
191
+
192
+
193
+ static ngx_command_t ngx_http_fastcgi_commands[] = {
194
+
195
+ { ngx_string("fastcgi_pass"),
196
+ NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
197
+ ngx_http_fastcgi_pass,
198
+ NGX_HTTP_LOC_CONF_OFFSET,
199
+ 0,
200
+ NULL },
201
+
202
+ { ngx_string("fastcgi_index"),
203
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
204
+ ngx_conf_set_str_slot,
205
+ NGX_HTTP_LOC_CONF_OFFSET,
206
+ offsetof(ngx_http_fastcgi_loc_conf_t, index),
207
+ NULL },
208
+
209
+ { ngx_string("fastcgi_split_path_info"),
210
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
211
+ ngx_http_fastcgi_split_path_info,
212
+ NGX_HTTP_LOC_CONF_OFFSET,
213
+ 0,
214
+ NULL },
215
+
216
+ { ngx_string("fastcgi_store"),
217
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
218
+ ngx_http_fastcgi_store,
219
+ NGX_HTTP_LOC_CONF_OFFSET,
220
+ 0,
221
+ NULL },
222
+
223
+ { ngx_string("fastcgi_store_access"),
224
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
225
+ ngx_conf_set_access_slot,
226
+ NGX_HTTP_LOC_CONF_OFFSET,
227
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.store_access),
228
+ NULL },
229
+
230
+ { ngx_string("fastcgi_ignore_client_abort"),
231
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
232
+ ngx_conf_set_flag_slot,
233
+ NGX_HTTP_LOC_CONF_OFFSET,
234
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_client_abort),
235
+ NULL },
236
+
237
+ { ngx_string("fastcgi_bind"),
238
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
239
+ ngx_http_upstream_bind_set_slot,
240
+ NGX_HTTP_LOC_CONF_OFFSET,
241
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.local),
242
+ NULL },
243
+
244
+ { ngx_string("fastcgi_connect_timeout"),
245
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
246
+ ngx_conf_set_msec_slot,
247
+ NGX_HTTP_LOC_CONF_OFFSET,
248
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.connect_timeout),
249
+ NULL },
250
+
251
+ { ngx_string("fastcgi_send_timeout"),
252
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
253
+ ngx_conf_set_msec_slot,
254
+ NGX_HTTP_LOC_CONF_OFFSET,
255
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_timeout),
256
+ NULL },
257
+
258
+ { ngx_string("fastcgi_send_lowat"),
259
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
260
+ ngx_conf_set_size_slot,
261
+ NGX_HTTP_LOC_CONF_OFFSET,
262
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_lowat),
263
+ &ngx_http_fastcgi_lowat_post },
264
+
265
+ { ngx_string("fastcgi_buffer_size"),
266
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
267
+ ngx_conf_set_size_slot,
268
+ NGX_HTTP_LOC_CONF_OFFSET,
269
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size),
270
+ NULL },
271
+
272
+ { ngx_string("fastcgi_pass_request_headers"),
273
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
274
+ ngx_conf_set_flag_slot,
275
+ NGX_HTTP_LOC_CONF_OFFSET,
276
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_headers),
277
+ NULL },
278
+
279
+ { ngx_string("fastcgi_pass_request_body"),
280
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
281
+ ngx_conf_set_flag_slot,
282
+ NGX_HTTP_LOC_CONF_OFFSET,
283
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_body),
284
+ NULL },
285
+
286
+ { ngx_string("fastcgi_intercept_errors"),
287
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
288
+ ngx_conf_set_flag_slot,
289
+ NGX_HTTP_LOC_CONF_OFFSET,
290
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.intercept_errors),
291
+ NULL },
292
+
293
+ { ngx_string("fastcgi_read_timeout"),
294
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
295
+ ngx_conf_set_msec_slot,
296
+ NGX_HTTP_LOC_CONF_OFFSET,
297
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.read_timeout),
298
+ NULL },
299
+
300
+ { ngx_string("fastcgi_buffers"),
301
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
302
+ ngx_conf_set_bufs_slot,
303
+ NGX_HTTP_LOC_CONF_OFFSET,
304
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.bufs),
305
+ NULL },
306
+
307
+ { ngx_string("fastcgi_busy_buffers_size"),
308
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
309
+ ngx_conf_set_size_slot,
310
+ NGX_HTTP_LOC_CONF_OFFSET,
311
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.busy_buffers_size_conf),
312
+ NULL },
313
+
314
+ #if (NGX_HTTP_CACHE)
315
+
316
+ { ngx_string("fastcgi_cache"),
317
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
318
+ ngx_http_fastcgi_cache,
319
+ NGX_HTTP_LOC_CONF_OFFSET,
320
+ 0,
321
+ NULL },
322
+
323
+ { ngx_string("fastcgi_cache_key"),
324
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
325
+ ngx_http_fastcgi_cache_key,
326
+ NGX_HTTP_LOC_CONF_OFFSET,
327
+ 0,
328
+ NULL },
329
+
330
+ { ngx_string("fastcgi_cache_path"),
331
+ NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
332
+ ngx_http_file_cache_set_slot,
333
+ 0,
334
+ 0,
335
+ &ngx_http_fastcgi_module },
336
+
337
+ { ngx_string("fastcgi_cache_bypass"),
338
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
339
+ ngx_http_set_predicate_slot,
340
+ NGX_HTTP_LOC_CONF_OFFSET,
341
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_bypass),
342
+ NULL },
343
+
344
+ { ngx_string("fastcgi_no_cache"),
345
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
346
+ ngx_http_set_predicate_slot,
347
+ NGX_HTTP_LOC_CONF_OFFSET,
348
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.no_cache),
349
+ NULL },
350
+
351
+ { ngx_string("fastcgi_cache_valid"),
352
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
353
+ ngx_http_file_cache_valid_set_slot,
354
+ NGX_HTTP_LOC_CONF_OFFSET,
355
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_valid),
356
+ NULL },
357
+
358
+ { ngx_string("fastcgi_cache_min_uses"),
359
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
360
+ ngx_conf_set_num_slot,
361
+ NGX_HTTP_LOC_CONF_OFFSET,
362
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_min_uses),
363
+ NULL },
364
+
365
+ { ngx_string("fastcgi_cache_use_stale"),
366
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
367
+ ngx_conf_set_bitmask_slot,
368
+ NGX_HTTP_LOC_CONF_OFFSET,
369
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_use_stale),
370
+ &ngx_http_fastcgi_next_upstream_masks },
371
+
372
+ { ngx_string("fastcgi_cache_methods"),
373
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
374
+ ngx_conf_set_bitmask_slot,
375
+ NGX_HTTP_LOC_CONF_OFFSET,
376
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_methods),
377
+ &ngx_http_upstream_cache_method_mask },
378
+
379
+ #endif
380
+
381
+ { ngx_string("fastcgi_temp_path"),
382
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
383
+ ngx_conf_set_path_slot,
384
+ NGX_HTTP_LOC_CONF_OFFSET,
385
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_path),
386
+ NULL },
387
+
388
+ { ngx_string("fastcgi_max_temp_file_size"),
389
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
390
+ ngx_conf_set_size_slot,
391
+ NGX_HTTP_LOC_CONF_OFFSET,
392
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.max_temp_file_size_conf),
393
+ NULL },
394
+
395
+ { ngx_string("fastcgi_temp_file_write_size"),
396
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
397
+ ngx_conf_set_size_slot,
398
+ NGX_HTTP_LOC_CONF_OFFSET,
399
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_file_write_size_conf),
400
+ NULL },
401
+
402
+ { ngx_string("fastcgi_next_upstream"),
403
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
404
+ ngx_conf_set_bitmask_slot,
405
+ NGX_HTTP_LOC_CONF_OFFSET,
406
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream),
407
+ &ngx_http_fastcgi_next_upstream_masks },
408
+
409
+ { ngx_string("fastcgi_param"),
410
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
411
+ ngx_conf_set_keyval_slot,
412
+ NGX_HTTP_LOC_CONF_OFFSET,
413
+ offsetof(ngx_http_fastcgi_loc_conf_t, params_source),
414
+ NULL },
415
+
416
+ { ngx_string("fastcgi_pass_header"),
417
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
418
+ ngx_conf_set_str_array_slot,
419
+ NGX_HTTP_LOC_CONF_OFFSET,
420
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_headers),
421
+ NULL },
422
+
423
+ { ngx_string("fastcgi_hide_header"),
424
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
425
+ ngx_conf_set_str_array_slot,
426
+ NGX_HTTP_LOC_CONF_OFFSET,
427
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.hide_headers),
428
+ NULL },
429
+
430
+ { ngx_string("fastcgi_ignore_headers"),
431
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
432
+ ngx_conf_set_bitmask_slot,
433
+ NGX_HTTP_LOC_CONF_OFFSET,
434
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_headers),
435
+ &ngx_http_upstream_ignore_headers_masks },
436
+
437
+ { ngx_string("fastcgi_catch_stderr"),
438
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
439
+ ngx_conf_set_str_array_slot,
440
+ NGX_HTTP_LOC_CONF_OFFSET,
441
+ offsetof(ngx_http_fastcgi_loc_conf_t, catch_stderr),
442
+ NULL },
443
+
444
+ ngx_null_command
445
+ };
446
+
447
+
448
+ static ngx_http_module_t ngx_http_fastcgi_module_ctx = {
449
+ ngx_http_fastcgi_add_variables, /* preconfiguration */
450
+ NULL, /* postconfiguration */
451
+
452
+ NULL, /* create main configuration */
453
+ NULL, /* init main configuration */
454
+
455
+ NULL, /* create server configuration */
456
+ NULL, /* merge server configuration */
457
+
458
+ ngx_http_fastcgi_create_loc_conf, /* create location configuration */
459
+ ngx_http_fastcgi_merge_loc_conf /* merge location configuration */
460
+ };
461
+
462
+
463
+ ngx_module_t ngx_http_fastcgi_module = {
464
+ NGX_MODULE_V1,
465
+ &ngx_http_fastcgi_module_ctx, /* module context */
466
+ ngx_http_fastcgi_commands, /* module directives */
467
+ NGX_HTTP_MODULE, /* module type */
468
+ NULL, /* init master */
469
+ NULL, /* init module */
470
+ NULL, /* init process */
471
+ NULL, /* init thread */
472
+ NULL, /* exit thread */
473
+ NULL, /* exit process */
474
+ NULL, /* exit master */
475
+ NGX_MODULE_V1_PADDING
476
+ };
477
+
478
+
479
+ static ngx_http_fastcgi_request_start_t ngx_http_fastcgi_request_start = {
480
+ { 1, /* version */
481
+ NGX_HTTP_FASTCGI_BEGIN_REQUEST, /* type */
482
+ 0, /* request_id_hi */
483
+ 1, /* request_id_lo */
484
+ 0, /* content_length_hi */
485
+ sizeof(ngx_http_fastcgi_begin_request_t), /* content_length_lo */
486
+ 0, /* padding_length */
487
+ 0 }, /* reserved */
488
+
489
+ { 0, /* role_hi */
490
+ NGX_HTTP_FASTCGI_RESPONDER, /* role_lo */
491
+ 0, /* NGX_HTTP_FASTCGI_KEEP_CONN */ /* flags */
492
+ { 0, 0, 0, 0, 0 } }, /* reserved[5] */
493
+
494
+ { 1, /* version */
495
+ NGX_HTTP_FASTCGI_PARAMS, /* type */
496
+ 0, /* request_id_hi */
497
+ 1 }, /* request_id_lo */
498
+
499
+ };
500
+
501
+
502
+ static ngx_http_variable_t ngx_http_fastcgi_vars[] = {
503
+
504
+ { ngx_string("fastcgi_script_name"), NULL,
505
+ ngx_http_fastcgi_script_name_variable, 0,
506
+ NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
507
+
508
+ { ngx_string("fastcgi_path_info"), NULL,
509
+ ngx_http_fastcgi_path_info_variable, 0,
510
+ NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
511
+
512
+ { ngx_null_string, NULL, NULL, 0, 0, 0 }
513
+ };
514
+
515
+
516
+ static ngx_str_t ngx_http_fastcgi_hide_headers[] = {
517
+ ngx_string("Status"),
518
+ ngx_string("X-Accel-Expires"),
519
+ ngx_string("X-Accel-Redirect"),
520
+ ngx_string("X-Accel-Limit-Rate"),
521
+ ngx_string("X-Accel-Buffering"),
522
+ ngx_string("X-Accel-Charset"),
523
+ ngx_null_string
524
+ };
525
+
526
+
527
+ #if (NGX_HTTP_CACHE)
528
+
529
+ static ngx_keyval_t ngx_http_fastcgi_cache_headers[] = {
530
+ { ngx_string("HTTP_IF_MODIFIED_SINCE"), ngx_string("") },
531
+ { ngx_string("HTTP_IF_UNMODIFIED_SINCE"), ngx_string("") },
532
+ { ngx_string("HTTP_IF_NONE_MATCH"), ngx_string("") },
533
+ { ngx_string("HTTP_IF_MATCH"), ngx_string("") },
534
+ { ngx_string("HTTP_RANGE"), ngx_string("") },
535
+ { ngx_string("HTTP_IF_RANGE"), ngx_string("") },
536
+ { ngx_null_string, ngx_null_string }
537
+ };
538
+
539
+ #endif
540
+
541
+
542
+ static ngx_path_init_t ngx_http_fastcgi_temp_path = {
543
+ ngx_string(NGX_HTTP_FASTCGI_TEMP_PATH), { 1, 2, 0 }
544
+ };
545
+
546
+
547
+ static ngx_int_t
548
+ ngx_http_fastcgi_handler(ngx_http_request_t *r)
549
+ {
550
+ ngx_int_t rc;
551
+ ngx_http_upstream_t *u;
552
+ ngx_http_fastcgi_ctx_t *f;
553
+ ngx_http_fastcgi_loc_conf_t *flcf;
554
+
555
+ if (r->subrequest_in_memory) {
556
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
557
+ "ngx_http_fastcgi_module does not support "
558
+ "subrequest in memory");
559
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
560
+ }
561
+
562
+ if (ngx_http_upstream_create(r) != NGX_OK) {
563
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
564
+ }
565
+
566
+ f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
567
+ if (f == NULL) {
568
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
569
+ }
570
+
571
+ ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
572
+
573
+ flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
574
+
575
+ if (flcf->fastcgi_lengths) {
576
+ if (ngx_http_fastcgi_eval(r, flcf) != NGX_OK) {
577
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
578
+ }
579
+ }
580
+
581
+ u = r->upstream;
582
+
583
+ ngx_str_set(&u->schema, "fastcgi://");
584
+ u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module;
585
+
586
+ u->conf = &flcf->upstream;
587
+
588
+ #if (NGX_HTTP_CACHE)
589
+ u->create_key = ngx_http_fastcgi_create_key;
590
+ #endif
591
+ u->create_request = ngx_http_fastcgi_create_request;
592
+ u->reinit_request = ngx_http_fastcgi_reinit_request;
593
+ u->process_header = ngx_http_fastcgi_process_header;
594
+ u->abort_request = ngx_http_fastcgi_abort_request;
595
+ u->finalize_request = ngx_http_fastcgi_finalize_request;
596
+
597
+ u->buffering = 1;
598
+
599
+ u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
600
+ if (u->pipe == NULL) {
601
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
602
+ }
603
+
604
+ u->pipe->input_filter = ngx_http_fastcgi_input_filter;
605
+ u->pipe->input_ctx = r;
606
+
607
+ rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
608
+
609
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
610
+ return rc;
611
+ }
612
+
613
+ return NGX_DONE;
614
+ }
615
+
616
+
617
+ static ngx_int_t
618
+ ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
619
+ {
620
+ ngx_url_t url;
621
+ ngx_http_upstream_t *u;
622
+
623
+ ngx_memzero(&url, sizeof(ngx_url_t));
624
+
625
+ if (ngx_http_script_run(r, &url.url, flcf->fastcgi_lengths->elts, 0,
626
+ flcf->fastcgi_values->elts)
627
+ == NULL)
628
+ {
629
+ return NGX_ERROR;
630
+ }
631
+
632
+ url.no_resolve = 1;
633
+
634
+ if (ngx_parse_url(r->pool, &url) != NGX_OK) {
635
+ if (url.err) {
636
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
637
+ "%s in upstream \"%V\"", url.err, &url.url);
638
+ }
639
+
640
+ return NGX_ERROR;
641
+ }
642
+
643
+ u = r->upstream;
644
+
645
+ u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));
646
+ if (u->resolved == NULL) {
647
+ return NGX_ERROR;
648
+ }
649
+
650
+ if (url.addrs && url.addrs[0].sockaddr) {
651
+ u->resolved->sockaddr = url.addrs[0].sockaddr;
652
+ u->resolved->socklen = url.addrs[0].socklen;
653
+ u->resolved->naddrs = 1;
654
+ u->resolved->host = url.addrs[0].name;
655
+
656
+ } else {
657
+ u->resolved->host = url.host;
658
+ u->resolved->port = url.port;
659
+ u->resolved->no_port = url.no_port;
660
+ }
661
+
662
+ return NGX_OK;
663
+ }
664
+
665
+
666
+ #if (NGX_HTTP_CACHE)
667
+
668
+ static ngx_int_t
669
+ ngx_http_fastcgi_create_key(ngx_http_request_t *r)
670
+ {
671
+ ngx_str_t *key;
672
+ ngx_http_fastcgi_loc_conf_t *flcf;
673
+
674
+ key = ngx_array_push(&r->cache->keys);
675
+ if (key == NULL) {
676
+ return NGX_ERROR;
677
+ }
678
+
679
+ flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
680
+
681
+ if (ngx_http_complex_value(r, &flcf->cache_key, key) != NGX_OK) {
682
+ return NGX_ERROR;
683
+ }
684
+
685
+ return NGX_OK;
686
+ }
687
+
688
+ #endif
689
+
690
+
691
+ static ngx_int_t
692
+ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
693
+ {
694
+ off_t file_pos;
695
+ u_char ch, *pos, *lowcase_key;
696
+ size_t size, len, key_len, val_len, padding,
697
+ allocated;
698
+ ngx_uint_t i, n, next, hash, header_params;
699
+ ngx_buf_t *b;
700
+ ngx_chain_t *cl, *body;
701
+ ngx_list_part_t *part;
702
+ ngx_table_elt_t *header, **ignored;
703
+ ngx_http_script_code_pt code;
704
+ ngx_http_script_engine_t e, le;
705
+ ngx_http_fastcgi_header_t *h;
706
+ ngx_http_fastcgi_loc_conf_t *flcf;
707
+ ngx_http_script_len_code_pt lcode;
708
+
709
+ len = 0;
710
+ header_params = 0;
711
+ ignored = NULL;
712
+
713
+ flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
714
+
715
+ if (flcf->params_len) {
716
+ ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
717
+
718
+ ngx_http_script_flush_no_cacheable_variables(r, flcf->flushes);
719
+ le.flushed = 1;
720
+
721
+ le.ip = flcf->params_len->elts;
722
+ le.request = r;
723
+
724
+ while (*(uintptr_t *) le.ip) {
725
+
726
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
727
+ key_len = lcode(&le);
728
+
729
+ for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
730
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
731
+ }
732
+ le.ip += sizeof(uintptr_t);
733
+
734
+ len += 1 + key_len + ((val_len > 127) ? 4 : 1) + val_len;
735
+ }
736
+ }
737
+
738
+ if (flcf->upstream.pass_request_headers) {
739
+
740
+ allocated = 0;
741
+ lowcase_key = NULL;
742
+
743
+ if (flcf->header_params) {
744
+ n = 0;
745
+ part = &r->headers_in.headers.part;
746
+
747
+ while (part) {
748
+ n += part->nelts;
749
+ part = part->next;
750
+ }
751
+
752
+ ignored = ngx_palloc(r->pool, n * sizeof(void *));
753
+ if (ignored == NULL) {
754
+ return NGX_ERROR;
755
+ }
756
+ }
757
+
758
+ part = &r->headers_in.headers.part;
759
+ header = part->elts;
760
+
761
+ for (i = 0; /* void */; i++) {
762
+
763
+ if (i >= part->nelts) {
764
+ if (part->next == NULL) {
765
+ break;
766
+ }
767
+
768
+ part = part->next;
769
+ header = part->elts;
770
+ i = 0;
771
+ }
772
+
773
+ if (flcf->header_params) {
774
+ if (allocated < header[i].key.len) {
775
+ allocated = header[i].key.len + 16;
776
+ lowcase_key = ngx_pnalloc(r->pool, allocated);
777
+ if (lowcase_key == NULL) {
778
+ return NGX_ERROR;
779
+ }
780
+ }
781
+
782
+ hash = 0;
783
+
784
+ for (n = 0; n < header[i].key.len; n++) {
785
+ ch = header[i].key.data[n];
786
+
787
+ if (ch >= 'A' && ch <= 'Z') {
788
+ ch |= 0x20;
789
+
790
+ } else if (ch == '-') {
791
+ ch = '_';
792
+ }
793
+
794
+ hash = ngx_hash(hash, ch);
795
+ lowcase_key[n] = ch;
796
+ }
797
+
798
+ if (ngx_hash_find(&flcf->headers_hash, hash, lowcase_key, n)) {
799
+ ignored[header_params++] = &header[i];
800
+ continue;
801
+ }
802
+
803
+ n += sizeof("HTTP_") - 1;
804
+
805
+ } else {
806
+ n = sizeof("HTTP_") - 1 + header[i].key.len;
807
+ }
808
+
809
+ len += ((n > 127) ? 4 : 1) + ((header[i].value.len > 127) ? 4 : 1)
810
+ + n + header[i].value.len;
811
+ }
812
+ }
813
+
814
+
815
+ if (len > 65535) {
816
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
817
+ "fastcgi request record is too big: %uz", len);
818
+ return NGX_ERROR;
819
+ }
820
+
821
+
822
+ padding = 8 - len % 8;
823
+ padding = (padding == 8) ? 0 : padding;
824
+
825
+
826
+ size = sizeof(ngx_http_fastcgi_header_t)
827
+ + sizeof(ngx_http_fastcgi_begin_request_t)
828
+
829
+ + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */
830
+ + len + padding
831
+ + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */
832
+
833
+ + sizeof(ngx_http_fastcgi_header_t); /* NGX_HTTP_FASTCGI_STDIN */
834
+
835
+
836
+ b = ngx_create_temp_buf(r->pool, size);
837
+ if (b == NULL) {
838
+ return NGX_ERROR;
839
+ }
840
+
841
+ cl = ngx_alloc_chain_link(r->pool);
842
+ if (cl == NULL) {
843
+ return NGX_ERROR;
844
+ }
845
+
846
+ cl->buf = b;
847
+
848
+ ngx_memcpy(b->pos, &ngx_http_fastcgi_request_start,
849
+ sizeof(ngx_http_fastcgi_request_start_t));
850
+
851
+ h = (ngx_http_fastcgi_header_t *)
852
+ (b->pos + sizeof(ngx_http_fastcgi_header_t)
853
+ + sizeof(ngx_http_fastcgi_begin_request_t));
854
+
855
+ h->content_length_hi = (u_char) ((len >> 8) & 0xff);
856
+ h->content_length_lo = (u_char) (len & 0xff);
857
+ h->padding_length = (u_char) padding;
858
+ h->reserved = 0;
859
+
860
+ b->last = b->pos + sizeof(ngx_http_fastcgi_header_t)
861
+ + sizeof(ngx_http_fastcgi_begin_request_t)
862
+ + sizeof(ngx_http_fastcgi_header_t);
863
+
864
+
865
+ if (flcf->params_len) {
866
+ ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
867
+
868
+ e.ip = flcf->params->elts;
869
+ e.pos = b->last;
870
+ e.request = r;
871
+ e.flushed = 1;
872
+
873
+ le.ip = flcf->params_len->elts;
874
+
875
+ while (*(uintptr_t *) le.ip) {
876
+
877
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
878
+ key_len = (u_char) lcode(&le);
879
+
880
+ for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
881
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
882
+ }
883
+ le.ip += sizeof(uintptr_t);
884
+
885
+ *e.pos++ = (u_char) key_len;
886
+
887
+ if (val_len > 127) {
888
+ *e.pos++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80);
889
+ *e.pos++ = (u_char) ((val_len >> 16) & 0xff);
890
+ *e.pos++ = (u_char) ((val_len >> 8) & 0xff);
891
+ *e.pos++ = (u_char) (val_len & 0xff);
892
+
893
+ } else {
894
+ *e.pos++ = (u_char) val_len;
895
+ }
896
+
897
+ while (*(uintptr_t *) e.ip) {
898
+ code = *(ngx_http_script_code_pt *) e.ip;
899
+ code((ngx_http_script_engine_t *) &e);
900
+ }
901
+ e.ip += sizeof(uintptr_t);
902
+
903
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
904
+ "fastcgi param: \"%*s: %*s\"",
905
+ key_len, e.pos - (key_len + val_len),
906
+ val_len, e.pos - val_len);
907
+ }
908
+
909
+ b->last = e.pos;
910
+ }
911
+
912
+
913
+ if (flcf->upstream.pass_request_headers) {
914
+
915
+ part = &r->headers_in.headers.part;
916
+ header = part->elts;
917
+
918
+ for (i = 0; /* void */; i++) {
919
+
920
+ if (i >= part->nelts) {
921
+ if (part->next == NULL) {
922
+ break;
923
+ }
924
+
925
+ part = part->next;
926
+ header = part->elts;
927
+ i = 0;
928
+ }
929
+
930
+ for (n = 0; n < header_params; n++) {
931
+ if (&header[i] == ignored[n]) {
932
+ goto next;
933
+ }
934
+ }
935
+
936
+ key_len = sizeof("HTTP_") - 1 + header[i].key.len;
937
+ if (key_len > 127) {
938
+ *b->last++ = (u_char) (((key_len >> 24) & 0x7f) | 0x80);
939
+ *b->last++ = (u_char) ((key_len >> 16) & 0xff);
940
+ *b->last++ = (u_char) ((key_len >> 8) & 0xff);
941
+ *b->last++ = (u_char) (key_len & 0xff);
942
+
943
+ } else {
944
+ *b->last++ = (u_char) key_len;
945
+ }
946
+
947
+ val_len = header[i].value.len;
948
+ if (val_len > 127) {
949
+ *b->last++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80);
950
+ *b->last++ = (u_char) ((val_len >> 16) & 0xff);
951
+ *b->last++ = (u_char) ((val_len >> 8) & 0xff);
952
+ *b->last++ = (u_char) (val_len & 0xff);
953
+
954
+ } else {
955
+ *b->last++ = (u_char) val_len;
956
+ }
957
+
958
+ b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1);
959
+
960
+ for (n = 0; n < header[i].key.len; n++) {
961
+ ch = header[i].key.data[n];
962
+
963
+ if (ch >= 'a' && ch <= 'z') {
964
+ ch &= ~0x20;
965
+
966
+ } else if (ch == '-') {
967
+ ch = '_';
968
+ }
969
+
970
+ *b->last++ = ch;
971
+ }
972
+
973
+ b->last = ngx_copy(b->last, header[i].value.data, val_len);
974
+
975
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
976
+ "fastcgi param: \"%*s: %*s\"",
977
+ key_len, b->last - (key_len + val_len),
978
+ val_len, b->last - val_len);
979
+ next:
980
+
981
+ continue;
982
+ }
983
+ }
984
+
985
+
986
+ if (padding) {
987
+ ngx_memzero(b->last, padding);
988
+ b->last += padding;
989
+ }
990
+
991
+
992
+ h = (ngx_http_fastcgi_header_t *) b->last;
993
+ b->last += sizeof(ngx_http_fastcgi_header_t);
994
+
995
+ h->version = 1;
996
+ h->type = NGX_HTTP_FASTCGI_PARAMS;
997
+ h->request_id_hi = 0;
998
+ h->request_id_lo = 1;
999
+ h->content_length_hi = 0;
1000
+ h->content_length_lo = 0;
1001
+ h->padding_length = 0;
1002
+ h->reserved = 0;
1003
+
1004
+ h = (ngx_http_fastcgi_header_t *) b->last;
1005
+ b->last += sizeof(ngx_http_fastcgi_header_t);
1006
+
1007
+ if (flcf->upstream.pass_request_body) {
1008
+ body = r->upstream->request_bufs;
1009
+ r->upstream->request_bufs = cl;
1010
+
1011
+ #if (NGX_SUPPRESS_WARN)
1012
+ file_pos = 0;
1013
+ pos = NULL;
1014
+ #endif
1015
+
1016
+ while (body) {
1017
+
1018
+ if (body->buf->in_file) {
1019
+ file_pos = body->buf->file_pos;
1020
+
1021
+ } else {
1022
+ pos = body->buf->pos;
1023
+ }
1024
+
1025
+ next = 0;
1026
+
1027
+ do {
1028
+ b = ngx_alloc_buf(r->pool);
1029
+ if (b == NULL) {
1030
+ return NGX_ERROR;
1031
+ }
1032
+
1033
+ ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
1034
+
1035
+ if (body->buf->in_file) {
1036
+ b->file_pos = file_pos;
1037
+ file_pos += 32 * 1024;
1038
+
1039
+ if (file_pos >= body->buf->file_last) {
1040
+ file_pos = body->buf->file_last;
1041
+ next = 1;
1042
+ }
1043
+
1044
+ b->file_last = file_pos;
1045
+ len = (ngx_uint_t) (file_pos - b->file_pos);
1046
+
1047
+ } else {
1048
+ b->pos = pos;
1049
+ pos += 32 * 1024;
1050
+
1051
+ if (pos >= body->buf->last) {
1052
+ pos = body->buf->last;
1053
+ next = 1;
1054
+ }
1055
+
1056
+ b->last = pos;
1057
+ len = (ngx_uint_t) (pos - b->pos);
1058
+ }
1059
+
1060
+ padding = 8 - len % 8;
1061
+ padding = (padding == 8) ? 0 : padding;
1062
+
1063
+ h->version = 1;
1064
+ h->type = NGX_HTTP_FASTCGI_STDIN;
1065
+ h->request_id_hi = 0;
1066
+ h->request_id_lo = 1;
1067
+ h->content_length_hi = (u_char) ((len >> 8) & 0xff);
1068
+ h->content_length_lo = (u_char) (len & 0xff);
1069
+ h->padding_length = (u_char) padding;
1070
+ h->reserved = 0;
1071
+
1072
+ cl->next = ngx_alloc_chain_link(r->pool);
1073
+ if (cl->next == NULL) {
1074
+ return NGX_ERROR;
1075
+ }
1076
+
1077
+ cl = cl->next;
1078
+ cl->buf = b;
1079
+
1080
+ b = ngx_create_temp_buf(r->pool,
1081
+ sizeof(ngx_http_fastcgi_header_t)
1082
+ + padding);
1083
+ if (b == NULL) {
1084
+ return NGX_ERROR;
1085
+ }
1086
+
1087
+ if (padding) {
1088
+ ngx_memzero(b->last, padding);
1089
+ b->last += padding;
1090
+ }
1091
+
1092
+ h = (ngx_http_fastcgi_header_t *) b->last;
1093
+ b->last += sizeof(ngx_http_fastcgi_header_t);
1094
+
1095
+ cl->next = ngx_alloc_chain_link(r->pool);
1096
+ if (cl->next == NULL) {
1097
+ return NGX_ERROR;
1098
+ }
1099
+
1100
+ cl = cl->next;
1101
+ cl->buf = b;
1102
+
1103
+ } while (!next);
1104
+
1105
+ body = body->next;
1106
+ }
1107
+
1108
+ } else {
1109
+ r->upstream->request_bufs = cl;
1110
+ }
1111
+
1112
+ h->version = 1;
1113
+ h->type = NGX_HTTP_FASTCGI_STDIN;
1114
+ h->request_id_hi = 0;
1115
+ h->request_id_lo = 1;
1116
+ h->content_length_hi = 0;
1117
+ h->content_length_lo = 0;
1118
+ h->padding_length = 0;
1119
+ h->reserved = 0;
1120
+
1121
+ cl->next = NULL;
1122
+
1123
+ return NGX_OK;
1124
+ }
1125
+
1126
+
1127
+ static ngx_int_t
1128
+ ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
1129
+ {
1130
+ ngx_http_fastcgi_ctx_t *f;
1131
+
1132
+ f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
1133
+
1134
+ if (f == NULL) {
1135
+ return NGX_OK;
1136
+ }
1137
+
1138
+ f->state = ngx_http_fastcgi_st_version;
1139
+ f->fastcgi_stdout = 0;
1140
+ f->large_stderr = 0;
1141
+
1142
+ return NGX_OK;
1143
+ }
1144
+
1145
+
1146
+ static ngx_int_t
1147
+ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
1148
+ {
1149
+ u_char *p, *msg, *start, *last,
1150
+ *part_start, *part_end;
1151
+ size_t size;
1152
+ ngx_str_t *status_line, *pattern;
1153
+ ngx_int_t rc, status;
1154
+ ngx_buf_t buf;
1155
+ ngx_uint_t i;
1156
+ ngx_table_elt_t *h;
1157
+ ngx_http_upstream_t *u;
1158
+ ngx_http_fastcgi_ctx_t *f;
1159
+ ngx_http_upstream_header_t *hh;
1160
+ ngx_http_fastcgi_loc_conf_t *flcf;
1161
+ ngx_http_fastcgi_split_part_t *part;
1162
+ ngx_http_upstream_main_conf_t *umcf;
1163
+
1164
+ f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
1165
+
1166
+ umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
1167
+
1168
+ u = r->upstream;
1169
+
1170
+ for ( ;; ) {
1171
+
1172
+ if (f->state < ngx_http_fastcgi_st_data) {
1173
+
1174
+ f->pos = u->buffer.pos;
1175
+ f->last = u->buffer.last;
1176
+
1177
+ rc = ngx_http_fastcgi_process_record(r, f);
1178
+
1179
+ u->buffer.pos = f->pos;
1180
+ u->buffer.last = f->last;
1181
+
1182
+ if (rc == NGX_AGAIN) {
1183
+ return NGX_AGAIN;
1184
+ }
1185
+
1186
+ if (rc == NGX_ERROR) {
1187
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1188
+ }
1189
+
1190
+ if (f->type != NGX_HTTP_FASTCGI_STDOUT
1191
+ && f->type != NGX_HTTP_FASTCGI_STDERR)
1192
+ {
1193
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1194
+ "upstream sent unexpected FastCGI record: %d",
1195
+ f->type);
1196
+
1197
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1198
+ }
1199
+
1200
+ if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
1201
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1202
+ "upstream closed prematurely FastCGI stdout");
1203
+
1204
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1205
+ }
1206
+ }
1207
+
1208
+ if (f->state == ngx_http_fastcgi_st_padding) {
1209
+
1210
+ if (u->buffer.pos + f->padding < u->buffer.last) {
1211
+ f->state = ngx_http_fastcgi_st_version;
1212
+ u->buffer.pos += f->padding;
1213
+
1214
+ continue;
1215
+ }
1216
+
1217
+ if (u->buffer.pos + f->padding == u->buffer.last) {
1218
+ f->state = ngx_http_fastcgi_st_version;
1219
+ u->buffer.pos = u->buffer.last;
1220
+
1221
+ return NGX_AGAIN;
1222
+ }
1223
+
1224
+ f->padding -= u->buffer.last - u->buffer.pos;
1225
+ u->buffer.pos = u->buffer.last;
1226
+
1227
+ return NGX_AGAIN;
1228
+ }
1229
+
1230
+
1231
+ /* f->state == ngx_http_fastcgi_st_data */
1232
+
1233
+ if (f->type == NGX_HTTP_FASTCGI_STDERR) {
1234
+
1235
+ if (f->length) {
1236
+ msg = u->buffer.pos;
1237
+
1238
+ if (u->buffer.pos + f->length <= u->buffer.last) {
1239
+ u->buffer.pos += f->length;
1240
+ f->length = 0;
1241
+ f->state = ngx_http_fastcgi_st_padding;
1242
+
1243
+ } else {
1244
+ f->length -= u->buffer.last - u->buffer.pos;
1245
+ u->buffer.pos = u->buffer.last;
1246
+ }
1247
+
1248
+ for (p = u->buffer.pos - 1; msg < p; p--) {
1249
+ if (*p != LF && *p != CR && *p != '.' && *p != ' ') {
1250
+ break;
1251
+ }
1252
+ }
1253
+
1254
+ p++;
1255
+
1256
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1257
+ "FastCGI sent in stderr: \"%*s\"", p - msg, msg);
1258
+
1259
+ flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
1260
+
1261
+ if (flcf->catch_stderr) {
1262
+ pattern = flcf->catch_stderr->elts;
1263
+
1264
+ for (i = 0; i < flcf->catch_stderr->nelts; i++) {
1265
+ if (ngx_strnstr(msg, (char *) pattern[i].data,
1266
+ p - msg)
1267
+ != NULL)
1268
+ {
1269
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1270
+ }
1271
+ }
1272
+ }
1273
+
1274
+ if (u->buffer.pos == u->buffer.last) {
1275
+
1276
+ if (!f->fastcgi_stdout) {
1277
+
1278
+ /*
1279
+ * the special handling the large number
1280
+ * of the PHP warnings to not allocate memory
1281
+ */
1282
+
1283
+ #if (NGX_HTTP_CACHE)
1284
+ if (r->cache) {
1285
+ u->buffer.pos = u->buffer.start
1286
+ + r->cache->header_start;
1287
+ } else {
1288
+ u->buffer.pos = u->buffer.start;
1289
+ }
1290
+ #else
1291
+ u->buffer.pos = u->buffer.start;
1292
+ #endif
1293
+ u->buffer.last = u->buffer.pos;
1294
+ f->large_stderr = 1;
1295
+ }
1296
+
1297
+ return NGX_AGAIN;
1298
+ }
1299
+
1300
+ } else {
1301
+ f->state = ngx_http_fastcgi_st_version;
1302
+ }
1303
+
1304
+ continue;
1305
+ }
1306
+
1307
+
1308
+ /* f->type == NGX_HTTP_FASTCGI_STDOUT */
1309
+
1310
+ #if (NGX_HTTP_CACHE)
1311
+
1312
+ if (f->large_stderr && r->cache) {
1313
+ u_char *start;
1314
+ ssize_t len;
1315
+ ngx_http_fastcgi_header_t *fh;
1316
+
1317
+ start = u->buffer.start + r->cache->header_start;
1318
+
1319
+ len = u->buffer.pos - start - 2 * sizeof(ngx_http_fastcgi_header_t);
1320
+
1321
+ /*
1322
+ * A tail of large stderr output before HTTP header is placed
1323
+ * in a cache file without a FastCGI record header.
1324
+ * To workaround it we put a dummy FastCGI record header at the
1325
+ * start of the stderr output or update r->cache_header_start,
1326
+ * if there is no enough place for the record header.
1327
+ */
1328
+
1329
+ if (len >= 0) {
1330
+ fh = (ngx_http_fastcgi_header_t *) start;
1331
+ fh->version = 1;
1332
+ fh->type = NGX_HTTP_FASTCGI_STDERR;
1333
+ fh->request_id_hi = 0;
1334
+ fh->request_id_lo = 1;
1335
+ fh->content_length_hi = (u_char) ((len >> 8) & 0xff);
1336
+ fh->content_length_lo = (u_char) (len & 0xff);
1337
+ fh->padding_length = 0;
1338
+ fh->reserved = 0;
1339
+
1340
+ } else {
1341
+ r->cache->header_start += u->buffer.pos - start
1342
+ - sizeof(ngx_http_fastcgi_header_t);
1343
+ }
1344
+
1345
+ f->large_stderr = 0;
1346
+ }
1347
+
1348
+ #endif
1349
+
1350
+ f->fastcgi_stdout = 1;
1351
+
1352
+ start = u->buffer.pos;
1353
+
1354
+ if (u->buffer.pos + f->length < u->buffer.last) {
1355
+
1356
+ /*
1357
+ * set u->buffer.last to the end of the FastCGI record data
1358
+ * for ngx_http_parse_header_line()
1359
+ */
1360
+
1361
+ last = u->buffer.last;
1362
+ u->buffer.last = u->buffer.pos + f->length;
1363
+
1364
+ } else {
1365
+ last = NULL;
1366
+ }
1367
+
1368
+ for ( ;; ) {
1369
+
1370
+ part_start = u->buffer.pos;
1371
+ part_end = u->buffer.last;
1372
+
1373
+ rc = ngx_http_parse_header_line(r, &u->buffer, 1);
1374
+
1375
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1376
+ "http fastcgi parser: %d", rc);
1377
+
1378
+ if (rc == NGX_AGAIN) {
1379
+ break;
1380
+ }
1381
+
1382
+ if (rc == NGX_OK) {
1383
+
1384
+ /* a header line has been parsed successfully */
1385
+
1386
+ h = ngx_list_push(&u->headers_in.headers);
1387
+ if (h == NULL) {
1388
+ return NGX_ERROR;
1389
+ }
1390
+
1391
+ if (f->split_parts && f->split_parts->nelts) {
1392
+
1393
+ part = f->split_parts->elts;
1394
+ size = u->buffer.pos - part_start;
1395
+
1396
+ for (i = 0; i < f->split_parts->nelts; i++) {
1397
+ size += part[i].end - part[i].start;
1398
+ }
1399
+
1400
+ p = ngx_pnalloc(r->pool, size);
1401
+ if (p == NULL) {
1402
+ return NGX_ERROR;
1403
+ }
1404
+
1405
+ buf.pos = p;
1406
+
1407
+ for (i = 0; i < f->split_parts->nelts; i++) {
1408
+ p = ngx_cpymem(p, part[i].start,
1409
+ part[i].end - part[i].start);
1410
+ }
1411
+
1412
+ p = ngx_cpymem(p, part_start, u->buffer.pos - part_start);
1413
+
1414
+ buf.last = p;
1415
+
1416
+ f->split_parts->nelts = 0;
1417
+
1418
+ rc = ngx_http_parse_header_line(r, &buf, 1);
1419
+
1420
+ h->key.len = r->header_name_end - r->header_name_start;
1421
+ h->key.data = r->header_name_start;
1422
+ h->key.data[h->key.len] = '\0';
1423
+
1424
+ h->value.len = r->header_end - r->header_start;
1425
+ h->value.data = r->header_start;
1426
+ h->value.data[h->value.len] = '\0';
1427
+
1428
+ h->lowcase_key = ngx_pnalloc(r->pool, h->key.len);
1429
+ if (h->lowcase_key == NULL) {
1430
+ return NGX_ERROR;
1431
+ }
1432
+
1433
+ } else {
1434
+
1435
+ h->key.len = r->header_name_end - r->header_name_start;
1436
+ h->value.len = r->header_end - r->header_start;
1437
+
1438
+ h->key.data = ngx_pnalloc(r->pool,
1439
+ h->key.len + 1 + h->value.len + 1
1440
+ + h->key.len);
1441
+ if (h->key.data == NULL) {
1442
+ return NGX_ERROR;
1443
+ }
1444
+
1445
+ h->value.data = h->key.data + h->key.len + 1;
1446
+ h->lowcase_key = h->key.data + h->key.len + 1
1447
+ + h->value.len + 1;
1448
+
1449
+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);
1450
+ h->key.data[h->key.len] = '\0';
1451
+ ngx_memcpy(h->value.data, r->header_start, h->value.len);
1452
+ h->value.data[h->value.len] = '\0';
1453
+ }
1454
+
1455
+ h->hash = r->header_hash;
1456
+
1457
+ if (h->key.len == r->lowcase_index) {
1458
+ ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
1459
+
1460
+ } else {
1461
+ ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
1462
+ }
1463
+
1464
+ hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
1465
+ h->lowcase_key, h->key.len);
1466
+
1467
+ if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
1468
+ return NGX_ERROR;
1469
+ }
1470
+
1471
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1472
+ "http fastcgi header: \"%V: %V\"",
1473
+ &h->key, &h->value);
1474
+
1475
+ if (u->buffer.pos < u->buffer.last) {
1476
+ continue;
1477
+ }
1478
+
1479
+ /* the end of the FastCGI record */
1480
+
1481
+ break;
1482
+ }
1483
+
1484
+ if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
1485
+
1486
+ /* a whole header has been parsed successfully */
1487
+
1488
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1489
+ "http fastcgi header done");
1490
+
1491
+ if (u->headers_in.status) {
1492
+ status_line = &u->headers_in.status->value;
1493
+
1494
+ status = ngx_atoi(status_line->data, 3);
1495
+
1496
+ if (status == NGX_ERROR) {
1497
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1498
+ "upstream sent invalid status \"%V\"",
1499
+ status_line);
1500
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1501
+ }
1502
+
1503
+ u->headers_in.status_n = status;
1504
+ u->headers_in.status_line = *status_line;
1505
+
1506
+ } else if (u->headers_in.location) {
1507
+ u->headers_in.status_n = 302;
1508
+ ngx_str_set(&u->headers_in.status_line,
1509
+ "302 Moved Temporarily");
1510
+
1511
+ } else {
1512
+ u->headers_in.status_n = 200;
1513
+ ngx_str_set(&u->headers_in.status_line, "200 OK");
1514
+ }
1515
+
1516
+ if (u->state) {
1517
+ u->state->status = u->headers_in.status_n;
1518
+ }
1519
+
1520
+ break;
1521
+ }
1522
+
1523
+ /* there was error while a header line parsing */
1524
+
1525
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1526
+ "upstream sent invalid header");
1527
+
1528
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1529
+ }
1530
+
1531
+ if (last) {
1532
+ u->buffer.last = last;
1533
+ }
1534
+
1535
+ f->length -= u->buffer.pos - start;
1536
+
1537
+ if (f->length == 0) {
1538
+ if (f->padding) {
1539
+ f->state = ngx_http_fastcgi_st_padding;
1540
+ } else {
1541
+ f->state = ngx_http_fastcgi_st_version;
1542
+ }
1543
+ }
1544
+
1545
+ if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
1546
+ return NGX_OK;
1547
+ }
1548
+
1549
+ if (rc == NGX_OK) {
1550
+ continue;
1551
+ }
1552
+
1553
+ /* rc == NGX_AGAIN */
1554
+
1555
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1556
+ "upstream split a header line in FastCGI records");
1557
+
1558
+ if (f->split_parts == NULL) {
1559
+ f->split_parts = ngx_array_create(r->pool, 1,
1560
+ sizeof(ngx_http_fastcgi_split_part_t));
1561
+ if (f->split_parts == NULL) {
1562
+ return NGX_ERROR;
1563
+ }
1564
+ }
1565
+
1566
+ part = ngx_array_push(f->split_parts);
1567
+
1568
+ part->start = part_start;
1569
+ part->end = part_end;
1570
+
1571
+ if (u->buffer.pos < u->buffer.last) {
1572
+ continue;
1573
+ }
1574
+
1575
+ return NGX_AGAIN;
1576
+ }
1577
+ }
1578
+
1579
+
1580
+ static ngx_int_t
1581
+ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
1582
+ {
1583
+ u_char *m, *msg;
1584
+ ngx_int_t rc;
1585
+ ngx_buf_t *b, **prev;
1586
+ ngx_chain_t *cl;
1587
+ ngx_http_request_t *r;
1588
+ ngx_http_fastcgi_ctx_t *f;
1589
+
1590
+ if (buf->pos == buf->last) {
1591
+ return NGX_OK;
1592
+ }
1593
+
1594
+ r = p->input_ctx;
1595
+ f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
1596
+
1597
+ b = NULL;
1598
+ prev = &buf->shadow;
1599
+
1600
+ f->pos = buf->pos;
1601
+ f->last = buf->last;
1602
+
1603
+ for ( ;; ) {
1604
+ if (f->state < ngx_http_fastcgi_st_data) {
1605
+
1606
+ rc = ngx_http_fastcgi_process_record(r, f);
1607
+
1608
+ if (rc == NGX_AGAIN) {
1609
+ break;
1610
+ }
1611
+
1612
+ if (rc == NGX_ERROR) {
1613
+ return NGX_ERROR;
1614
+ }
1615
+
1616
+ if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
1617
+ f->state = ngx_http_fastcgi_st_version;
1618
+ p->upstream_done = 1;
1619
+
1620
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
1621
+ "http fastcgi closed stdout");
1622
+
1623
+ continue;
1624
+ }
1625
+
1626
+ if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) {
1627
+ f->state = ngx_http_fastcgi_st_version;
1628
+ p->upstream_done = 1;
1629
+
1630
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
1631
+ "http fastcgi sent end request");
1632
+
1633
+ break;
1634
+ }
1635
+ }
1636
+
1637
+
1638
+ if (f->state == ngx_http_fastcgi_st_padding) {
1639
+
1640
+ if (f->pos + f->padding < f->last) {
1641
+ f->state = ngx_http_fastcgi_st_version;
1642
+ f->pos += f->padding;
1643
+
1644
+ continue;
1645
+ }
1646
+
1647
+ if (f->pos + f->padding == f->last) {
1648
+ f->state = ngx_http_fastcgi_st_version;
1649
+
1650
+ break;
1651
+ }
1652
+
1653
+ f->padding -= f->last - f->pos;
1654
+
1655
+ break;
1656
+ }
1657
+
1658
+
1659
+ /* f->state == ngx_http_fastcgi_st_data */
1660
+
1661
+ if (f->type == NGX_HTTP_FASTCGI_STDERR) {
1662
+
1663
+ if (f->length) {
1664
+
1665
+ if (f->pos == f->last) {
1666
+ break;
1667
+ }
1668
+
1669
+ msg = f->pos;
1670
+
1671
+ if (f->pos + f->length <= f->last) {
1672
+ f->pos += f->length;
1673
+ f->length = 0;
1674
+ f->state = ngx_http_fastcgi_st_padding;
1675
+
1676
+ } else {
1677
+ f->length -= f->last - f->pos;
1678
+ f->pos = f->last;
1679
+ }
1680
+
1681
+ for (m = f->pos - 1; msg < m; m--) {
1682
+ if (*m != LF && *m != CR && *m != '.' && *m != ' ') {
1683
+ break;
1684
+ }
1685
+ }
1686
+
1687
+ ngx_log_error(NGX_LOG_ERR, p->log, 0,
1688
+ "FastCGI sent in stderr: \"%*s\"",
1689
+ m + 1 - msg, msg);
1690
+
1691
+ if (f->pos == f->last) {
1692
+ break;
1693
+ }
1694
+
1695
+ } else {
1696
+ f->state = ngx_http_fastcgi_st_version;
1697
+ }
1698
+
1699
+ continue;
1700
+ }
1701
+
1702
+
1703
+ /* f->type == NGX_HTTP_FASTCGI_STDOUT */
1704
+
1705
+ if (f->pos == f->last) {
1706
+ break;
1707
+ }
1708
+
1709
+ if (p->free) {
1710
+ cl = p->free;
1711
+ b = cl->buf;
1712
+ p->free = cl->next;
1713
+ ngx_free_chain(p->pool, cl);
1714
+
1715
+ } else {
1716
+ b = ngx_alloc_buf(p->pool);
1717
+ if (b == NULL) {
1718
+ return NGX_ERROR;
1719
+ }
1720
+ }
1721
+
1722
+ ngx_memzero(b, sizeof(ngx_buf_t));
1723
+
1724
+ b->pos = f->pos;
1725
+ b->start = buf->start;
1726
+ b->end = buf->end;
1727
+ b->tag = p->tag;
1728
+ b->temporary = 1;
1729
+ b->recycled = 1;
1730
+
1731
+ *prev = b;
1732
+ prev = &b->shadow;
1733
+
1734
+ cl = ngx_alloc_chain_link(p->pool);
1735
+ if (cl == NULL) {
1736
+ return NGX_ERROR;
1737
+ }
1738
+
1739
+ cl->buf = b;
1740
+ cl->next = NULL;
1741
+
1742
+ if (p->in) {
1743
+ *p->last_in = cl;
1744
+ } else {
1745
+ p->in = cl;
1746
+ }
1747
+ p->last_in = &cl->next;
1748
+
1749
+
1750
+ /* STUB */ b->num = buf->num;
1751
+
1752
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
1753
+ "input buf #%d %p", b->num, b->pos);
1754
+
1755
+ if (f->pos + f->length < f->last) {
1756
+
1757
+ if (f->padding) {
1758
+ f->state = ngx_http_fastcgi_st_padding;
1759
+ } else {
1760
+ f->state = ngx_http_fastcgi_st_version;
1761
+ }
1762
+
1763
+ f->pos += f->length;
1764
+ b->last = f->pos;
1765
+
1766
+ continue;
1767
+ }
1768
+
1769
+ if (f->pos + f->length == f->last) {
1770
+
1771
+ if (f->padding) {
1772
+ f->state = ngx_http_fastcgi_st_padding;
1773
+ } else {
1774
+ f->state = ngx_http_fastcgi_st_version;
1775
+ }
1776
+
1777
+ b->last = f->last;
1778
+
1779
+ break;
1780
+ }
1781
+
1782
+ f->length -= f->last - f->pos;
1783
+
1784
+ b->last = f->last;
1785
+
1786
+ break;
1787
+
1788
+ }
1789
+
1790
+ if (b) {
1791
+ b->shadow = buf;
1792
+ b->last_shadow = 1;
1793
+
1794
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
1795
+ "input buf %p %z", b->pos, b->last - b->pos);
1796
+
1797
+ return NGX_OK;
1798
+ }
1799
+
1800
+ /* there is no data record in the buf, add it to free chain */
1801
+
1802
+ if (ngx_event_pipe_add_free_buf(p, buf) != NGX_OK) {
1803
+ return NGX_ERROR;
1804
+ }
1805
+
1806
+ return NGX_OK;
1807
+ }
1808
+
1809
+
1810
+ static ngx_int_t
1811
+ ngx_http_fastcgi_process_record(ngx_http_request_t *r,
1812
+ ngx_http_fastcgi_ctx_t *f)
1813
+ {
1814
+ u_char ch, *p;
1815
+ ngx_http_fastcgi_state_e state;
1816
+
1817
+ state = f->state;
1818
+
1819
+ for (p = f->pos; p < f->last; p++) {
1820
+
1821
+ ch = *p;
1822
+
1823
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1824
+ "http fastcgi record byte: %02Xd", ch);
1825
+
1826
+ switch (state) {
1827
+
1828
+ case ngx_http_fastcgi_st_version:
1829
+ if (ch != 1) {
1830
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1831
+ "upstream sent unsupported FastCGI "
1832
+ "protocol version: %d", ch);
1833
+ return NGX_ERROR;
1834
+ }
1835
+ state = ngx_http_fastcgi_st_type;
1836
+ break;
1837
+
1838
+ case ngx_http_fastcgi_st_type:
1839
+ switch (ch) {
1840
+ case NGX_HTTP_FASTCGI_STDOUT:
1841
+ case NGX_HTTP_FASTCGI_STDERR:
1842
+ case NGX_HTTP_FASTCGI_END_REQUEST:
1843
+ f->type = (ngx_uint_t) ch;
1844
+ break;
1845
+ default:
1846
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1847
+ "upstream sent invalid FastCGI "
1848
+ "record type: %d", ch);
1849
+ return NGX_ERROR;
1850
+
1851
+ }
1852
+ state = ngx_http_fastcgi_st_request_id_hi;
1853
+ break;
1854
+
1855
+ /* we support the single request per connection */
1856
+
1857
+ case ngx_http_fastcgi_st_request_id_hi:
1858
+ if (ch != 0) {
1859
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1860
+ "upstream sent unexpected FastCGI "
1861
+ "request id high byte: %d", ch);
1862
+ return NGX_ERROR;
1863
+ }
1864
+ state = ngx_http_fastcgi_st_request_id_lo;
1865
+ break;
1866
+
1867
+ case ngx_http_fastcgi_st_request_id_lo:
1868
+ if (ch != 1) {
1869
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1870
+ "upstream sent unexpected FastCGI "
1871
+ "request id low byte: %d", ch);
1872
+ return NGX_ERROR;
1873
+ }
1874
+ state = ngx_http_fastcgi_st_content_length_hi;
1875
+ break;
1876
+
1877
+ case ngx_http_fastcgi_st_content_length_hi:
1878
+ f->length = ch << 8;
1879
+ state = ngx_http_fastcgi_st_content_length_lo;
1880
+ break;
1881
+
1882
+ case ngx_http_fastcgi_st_content_length_lo:
1883
+ f->length |= (size_t) ch;
1884
+ state = ngx_http_fastcgi_st_padding_length;
1885
+ break;
1886
+
1887
+ case ngx_http_fastcgi_st_padding_length:
1888
+ f->padding = (size_t) ch;
1889
+ state = ngx_http_fastcgi_st_reserved;
1890
+ break;
1891
+
1892
+ case ngx_http_fastcgi_st_reserved:
1893
+ state = ngx_http_fastcgi_st_data;
1894
+
1895
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1896
+ "http fastcgi record length: %z", f->length);
1897
+
1898
+ f->pos = p + 1;
1899
+ f->state = state;
1900
+
1901
+ return NGX_OK;
1902
+
1903
+ /* suppress warning */
1904
+ case ngx_http_fastcgi_st_data:
1905
+ case ngx_http_fastcgi_st_padding:
1906
+ break;
1907
+ }
1908
+ }
1909
+
1910
+ f->state = state;
1911
+
1912
+ return NGX_AGAIN;
1913
+ }
1914
+
1915
+
1916
+ static void
1917
+ ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
1918
+ {
1919
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1920
+ "abort http fastcgi request");
1921
+
1922
+ return;
1923
+ }
1924
+
1925
+
1926
+ static void
1927
+ ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
1928
+ {
1929
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1930
+ "finalize http fastcgi request");
1931
+
1932
+ return;
1933
+ }
1934
+
1935
+
1936
+ static ngx_int_t
1937
+ ngx_http_fastcgi_add_variables(ngx_conf_t *cf)
1938
+ {
1939
+ ngx_http_variable_t *var, *v;
1940
+
1941
+ for (v = ngx_http_fastcgi_vars; v->name.len; v++) {
1942
+ var = ngx_http_add_variable(cf, &v->name, v->flags);
1943
+ if (var == NULL) {
1944
+ return NGX_ERROR;
1945
+ }
1946
+
1947
+ var->get_handler = v->get_handler;
1948
+ var->data = v->data;
1949
+ }
1950
+
1951
+ return NGX_OK;
1952
+ }
1953
+
1954
+
1955
+ static void *
1956
+ ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
1957
+ {
1958
+ ngx_http_fastcgi_loc_conf_t *conf;
1959
+
1960
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));
1961
+ if (conf == NULL) {
1962
+ return NULL;
1963
+ }
1964
+
1965
+ /*
1966
+ * set by ngx_pcalloc():
1967
+ *
1968
+ * conf->upstream.bufs.num = 0;
1969
+ * conf->upstream.ignore_headers = 0;
1970
+ * conf->upstream.next_upstream = 0;
1971
+ * conf->upstream.cache_use_stale = 0;
1972
+ * conf->upstream.cache_methods = 0;
1973
+ * conf->upstream.temp_path = NULL;
1974
+ * conf->upstream.hide_headers_hash = { NULL, 0 };
1975
+ * conf->upstream.uri = { 0, NULL };
1976
+ * conf->upstream.location = NULL;
1977
+ * conf->upstream.store_lengths = NULL;
1978
+ * conf->upstream.store_values = NULL;
1979
+ *
1980
+ * conf->index.len = { 0, NULL };
1981
+ */
1982
+
1983
+ conf->upstream.store = NGX_CONF_UNSET;
1984
+ conf->upstream.store_access = NGX_CONF_UNSET_UINT;
1985
+ conf->upstream.buffering = NGX_CONF_UNSET;
1986
+ conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
1987
+
1988
+ conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
1989
+ conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
1990
+ conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
1991
+
1992
+ conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
1993
+ conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
1994
+
1995
+ conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
1996
+ conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
1997
+ conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
1998
+
1999
+ conf->upstream.pass_request_headers = NGX_CONF_UNSET;
2000
+ conf->upstream.pass_request_body = NGX_CONF_UNSET;
2001
+
2002
+ #if (NGX_HTTP_CACHE)
2003
+ conf->upstream.cache = NGX_CONF_UNSET_PTR;
2004
+ conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
2005
+ conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
2006
+ conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
2007
+ conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
2008
+ #endif
2009
+
2010
+ conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
2011
+ conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
2012
+
2013
+ conf->upstream.intercept_errors = NGX_CONF_UNSET;
2014
+
2015
+ /* "fastcgi_cyclic_temp_file" is disabled */
2016
+ conf->upstream.cyclic_temp_file = 0;
2017
+
2018
+ conf->catch_stderr = NGX_CONF_UNSET_PTR;
2019
+
2020
+ ngx_str_set(&conf->upstream.module, "fastcgi");
2021
+
2022
+ return conf;
2023
+ }
2024
+
2025
+
2026
+ static char *
2027
+ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
2028
+ {
2029
+ ngx_http_fastcgi_loc_conf_t *prev = parent;
2030
+ ngx_http_fastcgi_loc_conf_t *conf = child;
2031
+
2032
+ size_t size;
2033
+ ngx_hash_init_t hash;
2034
+ ngx_http_core_loc_conf_t *clcf;
2035
+
2036
+ if (conf->upstream.store != 0) {
2037
+ ngx_conf_merge_value(conf->upstream.store,
2038
+ prev->upstream.store, 0);
2039
+
2040
+ if (conf->upstream.store_lengths == NULL) {
2041
+ conf->upstream.store_lengths = prev->upstream.store_lengths;
2042
+ conf->upstream.store_values = prev->upstream.store_values;
2043
+ }
2044
+ }
2045
+
2046
+ ngx_conf_merge_uint_value(conf->upstream.store_access,
2047
+ prev->upstream.store_access, 0600);
2048
+
2049
+ ngx_conf_merge_value(conf->upstream.buffering,
2050
+ prev->upstream.buffering, 1);
2051
+
2052
+ ngx_conf_merge_value(conf->upstream.ignore_client_abort,
2053
+ prev->upstream.ignore_client_abort, 0);
2054
+
2055
+ ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
2056
+ prev->upstream.connect_timeout, 60000);
2057
+
2058
+ ngx_conf_merge_msec_value(conf->upstream.send_timeout,
2059
+ prev->upstream.send_timeout, 60000);
2060
+
2061
+ ngx_conf_merge_msec_value(conf->upstream.read_timeout,
2062
+ prev->upstream.read_timeout, 60000);
2063
+
2064
+ ngx_conf_merge_size_value(conf->upstream.send_lowat,
2065
+ prev->upstream.send_lowat, 0);
2066
+
2067
+ ngx_conf_merge_size_value(conf->upstream.buffer_size,
2068
+ prev->upstream.buffer_size,
2069
+ (size_t) ngx_pagesize);
2070
+
2071
+
2072
+ ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
2073
+ 8, ngx_pagesize);
2074
+
2075
+ if (conf->upstream.bufs.num < 2) {
2076
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2077
+ "there must be at least 2 \"fastcgi_buffers\"");
2078
+ return NGX_CONF_ERROR;
2079
+ }
2080
+
2081
+
2082
+ size = conf->upstream.buffer_size;
2083
+ if (size < conf->upstream.bufs.size) {
2084
+ size = conf->upstream.bufs.size;
2085
+ }
2086
+
2087
+
2088
+ ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
2089
+ prev->upstream.busy_buffers_size_conf,
2090
+ NGX_CONF_UNSET_SIZE);
2091
+
2092
+ if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
2093
+ conf->upstream.busy_buffers_size = 2 * size;
2094
+ } else {
2095
+ conf->upstream.busy_buffers_size =
2096
+ conf->upstream.busy_buffers_size_conf;
2097
+ }
2098
+
2099
+ if (conf->upstream.busy_buffers_size < size) {
2100
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2101
+ "\"fastcgi_busy_buffers_size\" must be equal or bigger than "
2102
+ "maximum of the value of \"fastcgi_buffer_size\" and "
2103
+ "one of the \"fastcgi_buffers\"");
2104
+
2105
+ return NGX_CONF_ERROR;
2106
+ }
2107
+
2108
+ if (conf->upstream.busy_buffers_size
2109
+ > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
2110
+ {
2111
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2112
+ "\"fastcgi_busy_buffers_size\" must be less than "
2113
+ "the size of all \"fastcgi_buffers\" minus one buffer");
2114
+
2115
+ return NGX_CONF_ERROR;
2116
+ }
2117
+
2118
+
2119
+ ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
2120
+ prev->upstream.temp_file_write_size_conf,
2121
+ NGX_CONF_UNSET_SIZE);
2122
+
2123
+ if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
2124
+ conf->upstream.temp_file_write_size = 2 * size;
2125
+ } else {
2126
+ conf->upstream.temp_file_write_size =
2127
+ conf->upstream.temp_file_write_size_conf;
2128
+ }
2129
+
2130
+ if (conf->upstream.temp_file_write_size < size) {
2131
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2132
+ "\"fastcgi_temp_file_write_size\" must be equal or bigger than "
2133
+ "maximum of the value of \"fastcgi_buffer_size\" and "
2134
+ "one of the \"fastcgi_buffers\"");
2135
+
2136
+ return NGX_CONF_ERROR;
2137
+ }
2138
+
2139
+
2140
+ ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
2141
+ prev->upstream.max_temp_file_size_conf,
2142
+ NGX_CONF_UNSET_SIZE);
2143
+
2144
+ if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
2145
+ conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
2146
+ } else {
2147
+ conf->upstream.max_temp_file_size =
2148
+ conf->upstream.max_temp_file_size_conf;
2149
+ }
2150
+
2151
+ if (conf->upstream.max_temp_file_size != 0
2152
+ && conf->upstream.max_temp_file_size < size)
2153
+ {
2154
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2155
+ "\"fastcgi_max_temp_file_size\" must be equal to zero to disable "
2156
+ "the temporary files usage or must be equal or bigger than "
2157
+ "maximum of the value of \"fastcgi_buffer_size\" and "
2158
+ "one of the \"fastcgi_buffers\"");
2159
+
2160
+ return NGX_CONF_ERROR;
2161
+ }
2162
+
2163
+
2164
+ ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,
2165
+ prev->upstream.ignore_headers,
2166
+ NGX_CONF_BITMASK_SET);
2167
+
2168
+
2169
+ ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
2170
+ prev->upstream.next_upstream,
2171
+ (NGX_CONF_BITMASK_SET
2172
+ |NGX_HTTP_UPSTREAM_FT_ERROR
2173
+ |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
2174
+
2175
+ if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
2176
+ conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
2177
+ |NGX_HTTP_UPSTREAM_FT_OFF;
2178
+ }
2179
+
2180
+ if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
2181
+ prev->upstream.temp_path,
2182
+ &ngx_http_fastcgi_temp_path)
2183
+ != NGX_OK)
2184
+ {
2185
+ return NGX_CONF_ERROR;
2186
+ }
2187
+
2188
+ #if (NGX_HTTP_CACHE)
2189
+
2190
+ ngx_conf_merge_ptr_value(conf->upstream.cache,
2191
+ prev->upstream.cache, NULL);
2192
+
2193
+ if (conf->upstream.cache && conf->upstream.cache->data == NULL) {
2194
+ ngx_shm_zone_t *shm_zone;
2195
+
2196
+ shm_zone = conf->upstream.cache;
2197
+
2198
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2199
+ "\"fastcgi_cache\" zone \"%V\" is unknown",
2200
+ &shm_zone->shm.name);
2201
+
2202
+ return NGX_CONF_ERROR;
2203
+ }
2204
+
2205
+ ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
2206
+ prev->upstream.cache_min_uses, 1);
2207
+
2208
+ ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,
2209
+ prev->upstream.cache_use_stale,
2210
+ (NGX_CONF_BITMASK_SET
2211
+ |NGX_HTTP_UPSTREAM_FT_OFF));
2212
+
2213
+ if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {
2214
+ conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
2215
+ |NGX_HTTP_UPSTREAM_FT_OFF;
2216
+ }
2217
+
2218
+ if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_ERROR) {
2219
+ conf->upstream.cache_use_stale |= NGX_HTTP_UPSTREAM_FT_NOLIVE;
2220
+ }
2221
+
2222
+ if (conf->upstream.cache_methods == 0) {
2223
+ conf->upstream.cache_methods = prev->upstream.cache_methods;
2224
+ }
2225
+
2226
+ conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;
2227
+
2228
+ ngx_conf_merge_ptr_value(conf->upstream.cache_bypass,
2229
+ prev->upstream.cache_bypass, NULL);
2230
+
2231
+ ngx_conf_merge_ptr_value(conf->upstream.no_cache,
2232
+ prev->upstream.no_cache, NULL);
2233
+
2234
+ if (conf->upstream.no_cache && conf->upstream.cache_bypass == NULL) {
2235
+ ngx_log_error(NGX_LOG_WARN, cf->log, 0,
2236
+ "\"fastcgi_no_cache\" functionality has been changed in 0.8.46, "
2237
+ "now it should be used together with \"fastcgi_cache_bypass\"");
2238
+ }
2239
+
2240
+ ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
2241
+ prev->upstream.cache_valid, NULL);
2242
+
2243
+ if (conf->cache_key.value.data == NULL) {
2244
+ conf->cache_key = prev->cache_key;
2245
+ }
2246
+
2247
+ #endif
2248
+
2249
+ ngx_conf_merge_value(conf->upstream.pass_request_headers,
2250
+ prev->upstream.pass_request_headers, 1);
2251
+ ngx_conf_merge_value(conf->upstream.pass_request_body,
2252
+ prev->upstream.pass_request_body, 1);
2253
+
2254
+ ngx_conf_merge_value(conf->upstream.intercept_errors,
2255
+ prev->upstream.intercept_errors, 0);
2256
+
2257
+ ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL);
2258
+
2259
+
2260
+ ngx_conf_merge_str_value(conf->index, prev->index, "");
2261
+
2262
+ hash.max_size = 512;
2263
+ hash.bucket_size = ngx_align(64, ngx_cacheline_size);
2264
+ hash.name = "fastcgi_hide_headers_hash";
2265
+
2266
+ if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
2267
+ &prev->upstream, ngx_http_fastcgi_hide_headers, &hash)
2268
+ != NGX_OK)
2269
+ {
2270
+ return NGX_CONF_ERROR;
2271
+ }
2272
+
2273
+ if (conf->upstream.upstream == NULL) {
2274
+ conf->upstream.upstream = prev->upstream.upstream;
2275
+ }
2276
+
2277
+ if (conf->fastcgi_lengths == NULL) {
2278
+ conf->fastcgi_lengths = prev->fastcgi_lengths;
2279
+ conf->fastcgi_values = prev->fastcgi_values;
2280
+ }
2281
+
2282
+ if (conf->upstream.upstream || conf->fastcgi_lengths) {
2283
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
2284
+ if (clcf->handler == NULL && clcf->lmt_excpt) {
2285
+ clcf->handler = ngx_http_fastcgi_handler;
2286
+ }
2287
+ }
2288
+
2289
+ #if (NGX_PCRE)
2290
+ if (conf->split_regex == NULL) {
2291
+ conf->split_regex = prev->split_regex;
2292
+ conf->split_name = prev->split_name;
2293
+ }
2294
+ #endif
2295
+
2296
+ if (ngx_http_fastcgi_merge_params(cf, conf, prev) != NGX_OK) {
2297
+ return NGX_CONF_ERROR;
2298
+ }
2299
+
2300
+ return NGX_CONF_OK;
2301
+ }
2302
+
2303
+
2304
+ static ngx_int_t
2305
+ ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
2306
+ ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev)
2307
+ {
2308
+ u_char *p;
2309
+ size_t size;
2310
+ uintptr_t *code;
2311
+ ngx_uint_t i, nsrc;
2312
+ ngx_array_t headers_names;
2313
+ #if (NGX_HTTP_CACHE)
2314
+ ngx_array_t params_merged;
2315
+ #endif
2316
+ ngx_keyval_t *src;
2317
+ ngx_hash_key_t *hk;
2318
+ ngx_hash_init_t hash;
2319
+ ngx_http_script_compile_t sc;
2320
+ ngx_http_script_copy_code_t *copy;
2321
+
2322
+ if (conf->params_source == NULL) {
2323
+ conf->params_source = prev->params_source;
2324
+
2325
+ if (prev->headers_hash.buckets
2326
+ #if (NGX_HTTP_CACHE)
2327
+ && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
2328
+ #endif
2329
+ )
2330
+ {
2331
+ conf->flushes = prev->flushes;
2332
+ conf->params_len = prev->params_len;
2333
+ conf->params = prev->params;
2334
+ conf->headers_hash = prev->headers_hash;
2335
+ conf->header_params = prev->header_params;
2336
+
2337
+ return NGX_OK;
2338
+ }
2339
+ }
2340
+
2341
+ if (conf->params_source == NULL
2342
+ #if (NGX_HTTP_CACHE)
2343
+ && (conf->upstream.cache == NULL)
2344
+ #endif
2345
+ )
2346
+ {
2347
+ conf->headers_hash.buckets = (void *) 1;
2348
+ return NGX_OK;
2349
+ }
2350
+
2351
+ conf->params_len = ngx_array_create(cf->pool, 64, 1);
2352
+ if (conf->params_len == NULL) {
2353
+ return NGX_ERROR;
2354
+ }
2355
+
2356
+ conf->params = ngx_array_create(cf->pool, 512, 1);
2357
+ if (conf->params == NULL) {
2358
+ return NGX_ERROR;
2359
+ }
2360
+
2361
+ if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
2362
+ != NGX_OK)
2363
+ {
2364
+ return NGX_ERROR;
2365
+ }
2366
+
2367
+ if (conf->params_source) {
2368
+ src = conf->params_source->elts;
2369
+ nsrc = conf->params_source->nelts;
2370
+
2371
+ } else {
2372
+ src = NULL;
2373
+ nsrc = 0;
2374
+ }
2375
+
2376
+ #if (NGX_HTTP_CACHE)
2377
+
2378
+ if (conf->upstream.cache) {
2379
+ ngx_keyval_t *h, *s;
2380
+
2381
+ if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
2382
+ != NGX_OK)
2383
+ {
2384
+ return NGX_ERROR;
2385
+ }
2386
+
2387
+ for (i = 0; i < nsrc; i++) {
2388
+
2389
+ s = ngx_array_push(&params_merged);
2390
+ if (s == NULL) {
2391
+ return NGX_ERROR;
2392
+ }
2393
+
2394
+ *s = src[i];
2395
+ }
2396
+
2397
+ h = ngx_http_fastcgi_cache_headers;
2398
+
2399
+ while (h->key.len) {
2400
+
2401
+ src = params_merged.elts;
2402
+ nsrc = params_merged.nelts;
2403
+
2404
+ for (i = 0; i < nsrc; i++) {
2405
+ if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
2406
+ goto next;
2407
+ }
2408
+ }
2409
+
2410
+ s = ngx_array_push(&params_merged);
2411
+ if (s == NULL) {
2412
+ return NGX_ERROR;
2413
+ }
2414
+
2415
+ *s = *h;
2416
+
2417
+ next:
2418
+
2419
+ h++;
2420
+ }
2421
+
2422
+ src = params_merged.elts;
2423
+ nsrc = params_merged.nelts;
2424
+ }
2425
+
2426
+ #endif
2427
+
2428
+ for (i = 0; i < nsrc; i++) {
2429
+
2430
+ if (src[i].key.len > sizeof("HTTP_") - 1
2431
+ && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
2432
+ {
2433
+ hk = ngx_array_push(&headers_names);
2434
+ if (hk == NULL) {
2435
+ return NGX_ERROR;
2436
+ }
2437
+
2438
+ hk->key.len = src[i].key.len - 5;
2439
+ hk->key.data = src[i].key.data + 5;
2440
+ hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len);
2441
+ hk->value = (void *) 1;
2442
+
2443
+ if (src[i].value.len == 0) {
2444
+ continue;
2445
+ }
2446
+ }
2447
+
2448
+ copy = ngx_array_push_n(conf->params_len,
2449
+ sizeof(ngx_http_script_copy_code_t));
2450
+ if (copy == NULL) {
2451
+ return NGX_ERROR;
2452
+ }
2453
+
2454
+ copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
2455
+ copy->len = src[i].key.len;
2456
+
2457
+
2458
+ size = (sizeof(ngx_http_script_copy_code_t)
2459
+ + src[i].key.len + sizeof(uintptr_t) - 1)
2460
+ & ~(sizeof(uintptr_t) - 1);
2461
+
2462
+ copy = ngx_array_push_n(conf->params, size);
2463
+ if (copy == NULL) {
2464
+ return NGX_ERROR;
2465
+ }
2466
+
2467
+ copy->code = ngx_http_script_copy_code;
2468
+ copy->len = src[i].key.len;
2469
+
2470
+ p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
2471
+ ngx_memcpy(p, src[i].key.data, src[i].key.len);
2472
+
2473
+
2474
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2475
+
2476
+ sc.cf = cf;
2477
+ sc.source = &src[i].value;
2478
+ sc.flushes = &conf->flushes;
2479
+ sc.lengths = &conf->params_len;
2480
+ sc.values = &conf->params;
2481
+
2482
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2483
+ return NGX_ERROR;
2484
+ }
2485
+
2486
+ code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
2487
+ if (code == NULL) {
2488
+ return NGX_ERROR;
2489
+ }
2490
+
2491
+ *code = (uintptr_t) NULL;
2492
+
2493
+
2494
+ code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
2495
+ if (code == NULL) {
2496
+ return NGX_ERROR;
2497
+ }
2498
+
2499
+ *code = (uintptr_t) NULL;
2500
+ }
2501
+
2502
+ code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
2503
+ if (code == NULL) {
2504
+ return NGX_ERROR;
2505
+ }
2506
+
2507
+ *code = (uintptr_t) NULL;
2508
+
2509
+ conf->header_params = headers_names.nelts;
2510
+
2511
+ hash.hash = &conf->headers_hash;
2512
+ hash.key = ngx_hash_key_lc;
2513
+ hash.max_size = 512;
2514
+ hash.bucket_size = 64;
2515
+ hash.name = "fastcgi_params_hash";
2516
+ hash.pool = cf->pool;
2517
+ hash.temp_pool = NULL;
2518
+
2519
+ return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
2520
+ }
2521
+
2522
+
2523
+ static ngx_int_t
2524
+ ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
2525
+ ngx_http_variable_value_t *v, uintptr_t data)
2526
+ {
2527
+ u_char *p;
2528
+ ngx_http_fastcgi_ctx_t *f;
2529
+ ngx_http_fastcgi_loc_conf_t *flcf;
2530
+
2531
+ flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
2532
+
2533
+ f = ngx_http_fastcgi_split(r, flcf);
2534
+
2535
+ if (f == NULL) {
2536
+ return NGX_ERROR;
2537
+ }
2538
+
2539
+ if (f->script_name.len == 0
2540
+ || f->script_name.data[f->script_name.len - 1] != '/')
2541
+ {
2542
+ v->len = f->script_name.len;
2543
+ v->valid = 1;
2544
+ v->no_cacheable = 0;
2545
+ v->not_found = 0;
2546
+ v->data = f->script_name.data;
2547
+
2548
+ return NGX_OK;
2549
+ }
2550
+
2551
+ v->len = f->script_name.len + flcf->index.len;
2552
+
2553
+ v->data = ngx_pnalloc(r->pool, v->len);
2554
+ if (v->data == NULL) {
2555
+ return NGX_ERROR;
2556
+ }
2557
+
2558
+ p = ngx_copy(v->data, f->script_name.data, f->script_name.len);
2559
+ ngx_memcpy(p, flcf->index.data, flcf->index.len);
2560
+
2561
+ return NGX_OK;
2562
+ }
2563
+
2564
+
2565
+ static ngx_int_t
2566
+ ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
2567
+ ngx_http_variable_value_t *v, uintptr_t data)
2568
+ {
2569
+ ngx_http_fastcgi_ctx_t *f;
2570
+ ngx_http_fastcgi_loc_conf_t *flcf;
2571
+
2572
+ flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
2573
+
2574
+ f = ngx_http_fastcgi_split(r, flcf);
2575
+
2576
+ if (f == NULL) {
2577
+ return NGX_ERROR;
2578
+ }
2579
+
2580
+ v->len = f->path_info.len;
2581
+ v->valid = 1;
2582
+ v->no_cacheable = 0;
2583
+ v->not_found = 0;
2584
+ v->data = f->path_info.data;
2585
+
2586
+ return NGX_OK;
2587
+ }
2588
+
2589
+
2590
+ static ngx_http_fastcgi_ctx_t *
2591
+ ngx_http_fastcgi_split(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
2592
+ {
2593
+ ngx_http_fastcgi_ctx_t *f;
2594
+ #if (NGX_PCRE)
2595
+ ngx_int_t n;
2596
+ int captures[(1 + 2) * 3];
2597
+
2598
+ f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
2599
+
2600
+ if (f == NULL) {
2601
+ f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
2602
+ if (f == NULL) {
2603
+ return NULL;
2604
+ }
2605
+
2606
+ ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
2607
+ }
2608
+
2609
+ if (f->script_name.len) {
2610
+ return f;
2611
+ }
2612
+
2613
+ if (flcf->split_regex == NULL) {
2614
+ f->script_name = r->uri;
2615
+ return f;
2616
+ }
2617
+
2618
+ n = ngx_regex_exec(flcf->split_regex, &r->uri, captures, (1 + 2) * 3);
2619
+
2620
+ if (n >= 0) { /* match */
2621
+ f->script_name.len = captures[3] - captures[2];
2622
+ f->script_name.data = r->uri.data + captures[2];
2623
+
2624
+ f->path_info.len = captures[5] - captures[4];
2625
+ f->path_info.data = r->uri.data + captures[4];
2626
+
2627
+ return f;
2628
+ }
2629
+
2630
+ if (n == NGX_REGEX_NO_MATCHED) {
2631
+ f->script_name = r->uri;
2632
+ return f;
2633
+ }
2634
+
2635
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
2636
+ ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"",
2637
+ n, &r->uri, &flcf->split_name);
2638
+ return NULL;
2639
+
2640
+ #else
2641
+
2642
+ f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
2643
+
2644
+ if (f == NULL) {
2645
+ f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
2646
+ if (f == NULL) {
2647
+ return NULL;
2648
+ }
2649
+
2650
+ ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
2651
+ }
2652
+
2653
+ f->script_name = r->uri;
2654
+
2655
+ return f;
2656
+
2657
+ #endif
2658
+ }
2659
+
2660
+
2661
+ static char *
2662
+ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2663
+ {
2664
+ ngx_http_fastcgi_loc_conf_t *flcf = conf;
2665
+
2666
+ ngx_url_t u;
2667
+ ngx_str_t *value, *url;
2668
+ ngx_uint_t n;
2669
+ ngx_http_core_loc_conf_t *clcf;
2670
+ ngx_http_script_compile_t sc;
2671
+
2672
+ if (flcf->upstream.upstream || flcf->fastcgi_lengths) {
2673
+ return "is duplicate";
2674
+ }
2675
+
2676
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
2677
+
2678
+ clcf->handler = ngx_http_fastcgi_handler;
2679
+
2680
+ if (clcf->name.data[clcf->name.len - 1] == '/') {
2681
+ clcf->auto_redirect = 1;
2682
+ }
2683
+
2684
+ value = cf->args->elts;
2685
+
2686
+ url = &value[1];
2687
+
2688
+ n = ngx_http_script_variables_count(url);
2689
+
2690
+ if (n) {
2691
+
2692
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2693
+
2694
+ sc.cf = cf;
2695
+ sc.source = url;
2696
+ sc.lengths = &flcf->fastcgi_lengths;
2697
+ sc.values = &flcf->fastcgi_values;
2698
+ sc.variables = n;
2699
+ sc.complete_lengths = 1;
2700
+ sc.complete_values = 1;
2701
+
2702
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2703
+ return NGX_CONF_ERROR;
2704
+ }
2705
+
2706
+ return NGX_CONF_OK;
2707
+ }
2708
+
2709
+ ngx_memzero(&u, sizeof(ngx_url_t));
2710
+
2711
+ u.url = value[1];
2712
+ u.no_resolve = 1;
2713
+
2714
+ flcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
2715
+ if (flcf->upstream.upstream == NULL) {
2716
+ return NGX_CONF_ERROR;
2717
+ }
2718
+
2719
+ return NGX_CONF_OK;
2720
+ }
2721
+
2722
+
2723
+ static char *
2724
+ ngx_http_fastcgi_split_path_info(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2725
+ {
2726
+ #if (NGX_PCRE)
2727
+ ngx_http_fastcgi_loc_conf_t *flcf = conf;
2728
+
2729
+ ngx_str_t *value;
2730
+ ngx_regex_compile_t rc;
2731
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
2732
+
2733
+ value = cf->args->elts;
2734
+
2735
+ flcf->split_name = value[1];
2736
+
2737
+ ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
2738
+
2739
+ rc.pattern = value[1];
2740
+ rc.pool = cf->pool;
2741
+ rc.err.len = NGX_MAX_CONF_ERRSTR;
2742
+ rc.err.data = errstr;
2743
+
2744
+ if (ngx_regex_compile(&rc) != NGX_OK) {
2745
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
2746
+ return NGX_CONF_ERROR;
2747
+ }
2748
+
2749
+ if (rc.captures != 2) {
2750
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2751
+ "pattern \"%V\" must have 2 captures", &value[1]);
2752
+ return NGX_CONF_ERROR;
2753
+ }
2754
+
2755
+ flcf->split_regex = rc.regex;
2756
+
2757
+ return NGX_CONF_OK;
2758
+
2759
+ #else
2760
+
2761
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2762
+ "\"%V\" requires PCRE library", &cmd->name);
2763
+ return NGX_CONF_ERROR;
2764
+
2765
+ #endif
2766
+ }
2767
+
2768
+
2769
+ static char *
2770
+ ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2771
+ {
2772
+ ngx_http_fastcgi_loc_conf_t *flcf = conf;
2773
+
2774
+ ngx_str_t *value;
2775
+ ngx_http_script_compile_t sc;
2776
+
2777
+ if (flcf->upstream.store != NGX_CONF_UNSET
2778
+ || flcf->upstream.store_lengths)
2779
+ {
2780
+ return "is duplicate";
2781
+ }
2782
+
2783
+ value = cf->args->elts;
2784
+
2785
+ if (ngx_strcmp(value[1].data, "off") == 0) {
2786
+ flcf->upstream.store = 0;
2787
+ return NGX_CONF_OK;
2788
+ }
2789
+
2790
+ #if (NGX_HTTP_CACHE)
2791
+
2792
+ if (flcf->upstream.cache != NGX_CONF_UNSET_PTR
2793
+ && flcf->upstream.cache != NULL)
2794
+ {
2795
+ return "is incompatible with \"fastcgi_cache\"";
2796
+ }
2797
+
2798
+ #endif
2799
+
2800
+ if (ngx_strcmp(value[1].data, "on") == 0) {
2801
+ flcf->upstream.store = 1;
2802
+ return NGX_CONF_OK;
2803
+ }
2804
+
2805
+ /* include the terminating '\0' into script */
2806
+ value[1].len++;
2807
+
2808
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2809
+
2810
+ sc.cf = cf;
2811
+ sc.source = &value[1];
2812
+ sc.lengths = &flcf->upstream.store_lengths;
2813
+ sc.values = &flcf->upstream.store_values;
2814
+ sc.variables = ngx_http_script_variables_count(&value[1]);
2815
+ sc.complete_lengths = 1;
2816
+ sc.complete_values = 1;
2817
+
2818
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
2819
+ return NGX_CONF_ERROR;
2820
+ }
2821
+
2822
+ return NGX_CONF_OK;
2823
+ }
2824
+
2825
+
2826
+ #if (NGX_HTTP_CACHE)
2827
+
2828
+ static char *
2829
+ ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2830
+ {
2831
+ ngx_http_fastcgi_loc_conf_t *flcf = conf;
2832
+
2833
+ ngx_str_t *value;
2834
+
2835
+ value = cf->args->elts;
2836
+
2837
+ if (flcf->upstream.cache != NGX_CONF_UNSET_PTR) {
2838
+ return "is duplicate";
2839
+ }
2840
+
2841
+ if (ngx_strcmp(value[1].data, "off") == 0) {
2842
+ flcf->upstream.cache = NULL;
2843
+ return NGX_CONF_OK;
2844
+ }
2845
+
2846
+ if (flcf->upstream.store > 0 || flcf->upstream.store_lengths) {
2847
+ return "is incompatible with \"fastcgi_store\"";
2848
+ }
2849
+
2850
+ flcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
2851
+ &ngx_http_fastcgi_module);
2852
+ if (flcf->upstream.cache == NULL) {
2853
+ return NGX_CONF_ERROR;
2854
+ }
2855
+
2856
+ return NGX_CONF_OK;
2857
+ }
2858
+
2859
+
2860
+ static char *
2861
+ ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2862
+ {
2863
+ ngx_http_fastcgi_loc_conf_t *flcf = conf;
2864
+
2865
+ ngx_str_t *value;
2866
+ ngx_http_compile_complex_value_t ccv;
2867
+
2868
+ value = cf->args->elts;
2869
+
2870
+ if (flcf->cache_key.value.len) {
2871
+ return "is duplicate";
2872
+ }
2873
+
2874
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
2875
+
2876
+ ccv.cf = cf;
2877
+ ccv.value = &value[1];
2878
+ ccv.complex_value = &flcf->cache_key;
2879
+
2880
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
2881
+ return NGX_CONF_ERROR;
2882
+ }
2883
+
2884
+ return NGX_CONF_OK;
2885
+ }
2886
+
2887
+ #endif
2888
+
2889
+
2890
+ static char *
2891
+ ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
2892
+ {
2893
+ #if (NGX_FREEBSD)
2894
+ ssize_t *np = data;
2895
+
2896
+ if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
2897
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2898
+ "\"fastcgi_send_lowat\" must be less than %d "
2899
+ "(sysctl net.inet.tcp.sendspace)",
2900
+ ngx_freebsd_net_inet_tcp_sendspace);
2901
+
2902
+ return NGX_CONF_ERROR;
2903
+ }
2904
+
2905
+ #elif !(NGX_HAVE_SO_SNDLOWAT)
2906
+ ssize_t *np = data;
2907
+
2908
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2909
+ "\"fastcgi_send_lowat\" is not supported, ignored");
2910
+
2911
+ *np = 0;
2912
+
2913
+ #endif
2914
+
2915
+ return NGX_CONF_OK;
2916
+ }