Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#1471 closed defect (invalid)

Nginx ignores proxy_read_timeout inside location context

Reported by: maximzxc@… Owned by:
Priority: major Milestone:
Component: nginx-module Version: 1.13.x
Keywords: proxy_read_timeout ngx_http_proxy_module Cc:
uname -a: Linux 88c9461fb367 4.4.0-1049-aws #58-Ubuntu SMP Fri Jan 12 23:17:09 UTC 2018 x86_64 Linux
nginx -V: nginx version: nginx/1.13.3
built by gcc 6.2.1 20160822 (Alpine 6.2.1)
built with OpenSSL 1.0.2k 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-http_v2_module

Description

Config looks like:

    server {
        ...
        proxy_read_timeout 45s;
        ...
    
        location /admin {
            proxy_pass http://ADMIN_APP_IP:8000;
        }

        location /admin/analytics {
            proxy_read_timeout 900s;
        }
    }

For some reason, when I send a request to https://my_stage_server_addr.com/admin/analytics/ proxy_read_timeout inside location /admin/analytics seems to be ignored, because after 45s nginx returns 504 error. If I change proxy_read_timeout value inside server context everything works fine.

The documentation says that it should be ok to use proxy_read_timeout inside location http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout, maybe I miss something?

Change History (4)

comment:1 by Maxim Dounin, 7 years ago

Resolution: invalid
Status: newclosed

In the provided configuration, the /admin/analytics location does not contain proxy_pass, and hence requests to /admin/analytics will be handled as static files, likely returning 404. If a request to /admin/analytics returns 504 instead, it's either handled in a different configuration (check if your configuration is correctly loaded) or additionally processed, e.g., using an error_page directive.

If you still think there is a bug in nginx, please provide full self-contained configuration example which demonstrates the problem. If you need help with configuring nginx, consider using support options available.

comment:2 by maximzxc@…, 7 years ago

Resolution: invalid
Status: closedreopened

Thanks for response, sorry, I forgot to mention that all requests to /admin/analytics are simply going to another server:

    location / {
        resolver 127.0.0.11 valid=30s;
        proxy_pass http://upstream_web;
    }

But even if I, for example, move proxy_read_timeout 900s to /admin location context like this:

    location /admin {
        proxy_pass http://ADMIN_APP_IP:8000;
        proxy_read_timeout 900s;
    }

and make same request requests, after 45 seconds I'll get 504 error, so I'm sure that there is a bug in nginx not in my configuration.

Version 0, edited 7 years ago by maximzxc@… (next)

comment:3 by Maxim Dounin, 7 years ago

Resolution: invalid
Status: reopenedclosed

As long as there is location /admin/analytics in the configuration as show in the original report, there are two basic options:

  • the request is handled in this location as a request to static files, and then processed according to other configuration options;
  • there are other regexp locations in the configuration, and the request is handled in one of these locations instead.

It is not possible to tell what happens in your configuration without seeing the full configuration.

As previously suggested, if you think there is a bug in nginx, please provide full self-contained configuration example which demonstrates the problem. That is, please provide full nginx.conf (or nginx -T output) which demonstrates the problem.

in reply to:  3 comment:4 by maximzxc@…, 7 years ago

Yes, it was my fault, had another regexp locations in the configuration that had a bigger priority than /admin/analytics, just missed it, thanks for pointing that.

Note: See TracTickets for help on using tickets.