proxy_pass to upstreams and then 404 location

daveyfx nginx-forum at
Fri Apr 17 04:59:51 UTC 2015

Hello all -

I'm attempting to do the following in nginx and having difficulty with the
last step in this succession.

1) In / location, proxy_pass to Django upstream.
2) proxy_intercept_errors is on in this block and does a proxy_pass to PHP
upstream if 404 is returned.
3) In PHP location block (internal), proxy_intercept_errors is on and if a
404 is returned, goes to 404 location block.
4) The 404 location block should proxy_pass to the same Django upstream, but
pass /404/ to the Django app.

Everything but the final 404 proxy_pass is working fine.  I can send a "bad"
URL that will return a 404 from Django and PHP upstreams, but when I tail
the Django app logs, the "bad" URL is what is sent to the upstream when I
would like /404/ sent to the upstream.  I do not need the URL to be
re-written to in the client browser.

Thank you in advance for any help/recommendations.

    location / {
        log_not_found off;

        expires 1m;

        proxy_intercept_errors on;
        proxy_pass http://django;
        error_page 404 = @php;

    location @django {
        log_not_found off;

        proxy_redirect off;
        proxy_pass http://django$uri$is_args$args;

    location @php {
        log_not_found off;

        include conf.d/proxypass.conf;
        proxy_redirect off;
        proxy_intercept_errors on;
        proxy_pass http://php$uri$is_args$args;
        error_page 404 = /404/;

    location /404/ {
        log_not_found off;
        proxy_pass  http://django;

Posted at Nginx Forum:,258132,258132#msg-258132

More information about the nginx mailing list