nginx read timeout for a specific path

44 views Asked by At

I'm using Cloud66 which has a long nginx config.

This config is currently proxy passing to Puma, which is a Rails server (my app).

All I'm wanting to do is specify a 10m proxy_read_timeout ONLY to my /api/import path, which basically is a long running (blocking) API request, used very rarely by admins, and the time may go ~3-4 minutes, so I want to set it to 10 minutes.

When I add this:

location /api/import {
    proxy_read_timeout 5s;
}

It now returns a 404 as if this location block is evaluated and thats the end of it. It doesn't proceed with the rest of the config.

How am I supposed to do this? Surely there is a way to apply configs selectively without having to copy and paste the entire proxy pass in every single custom config area?

This is whats in the config:

 server {
        ...

        location /api/import {
            proxy_read_timeout 5s;
        }

        location / {
            {% if websocket_support == true %}
            # Next three lines enable websocket support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            {% endif %}
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        Host $http_host;
            proxy_set_header        X-Forwarded-Proto $real_scheme;
            proxy_redirect          off;

            if (!-f $request_filename) {
                proxy_pass  http://socket_server${unique_suffix};
                break;
            }
        }
        location ~ \.php$ {
            deny  all;
        }
    }
0

There are 0 answers