Commit 2e37e64
committed
ngx_cache_purge: fix 404 on non-PURGE requests when "if" block is present
When nginx processes an "if" directive inside a location block, it creates
an anonymous child location and calls merge_loc_conf to propagate the
parent's configuration into it. At that point clcf->handler is already
set to ngx_http_cache_purge_access_handler by the parent merge pass.
The child merge re-entered the proxy.enable (or fastcgi/scgi/uwsgi)
branch, saved ngx_http_cache_purge_access_handler into original_handler,
then set clcf->handler to ngx_http_cache_purge_access_handler again.
On any non-PURGE request that triggered the "if" block, access_handler
called original_handler(r), which called access_handler again, producing
a 404 instead of forwarding to the upstream handler.
Fix: in each of the four protocol branches in merge_loc_conf, check
whether clcf->handler is already our own access handler before recording
it as original_handler. If it is, the merge is being called for an
anonymous "if" child location; inherit original_handler from the parent
conf instead. This preserves the pointer to the real upstream handler
(e.g. ngx_http_proxy_handler) across the child merge and ensures that
non-PURGE requests entering the "if" branch are forwarded correctly.
The bug is present in v3.0.0 and later. v2.x is not affected because
it used a different handler installation strategy.
Issues: #631 parent 6147443 commit 2e37e64
1 file changed
Lines changed: 32 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3353 | 3353 | | |
3354 | 3354 | | |
3355 | 3355 | | |
3356 | | - | |
3357 | | - | |
3358 | | - | |
3359 | | - | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
3360 | 3364 | | |
3361 | 3365 | | |
3362 | 3366 | | |
| |||
3365 | 3369 | | |
3366 | 3370 | | |
3367 | 3371 | | |
3368 | | - | |
3369 | | - | |
3370 | | - | |
3371 | | - | |
3372 | | - | |
3373 | | - | |
3374 | | - | |
3375 | | - | |
3376 | | - | |
3377 | | - | |
| 3372 | + | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
3378 | 3380 | | |
3379 | 3381 | | |
3380 | 3382 | | |
| |||
3383 | 3385 | | |
3384 | 3386 | | |
3385 | 3387 | | |
3386 | | - | |
3387 | | - | |
3388 | | - | |
3389 | | - | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
| 3393 | + | |
| 3394 | + | |
| 3395 | + | |
3390 | 3396 | | |
3391 | 3397 | | |
3392 | 3398 | | |
| |||
3395 | 3401 | | |
3396 | 3402 | | |
3397 | 3403 | | |
3398 | | - | |
3399 | | - | |
3400 | | - | |
3401 | | - | |
| 3404 | + | |
| 3405 | + | |
| 3406 | + | |
| 3407 | + | |
| 3408 | + | |
| 3409 | + | |
| 3410 | + | |
| 3411 | + | |
3402 | 3412 | | |
3403 | 3413 | | |
3404 | 3414 | | |
| |||
0 commit comments