Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a location block for / that does all of my fastcgi stuff and it has a normal timeout of 10s. I want to be able to have different timesouts for certain files(/admin, sitemap.xml). Is there an easy way to do this without copying the entire location block for each location?

location /admin{
 fastcgi_read_timeout 5m;
 #also use the location info below.
}

location /sitemap.xml{
 fastcgi_read_timeout 5m;
 #also use the location info below.
}

location / {
            fastcgi_pass 127.0.0.1:8014;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_pass_header Authorization;
            fastcgi_intercept_errors off;
            fastcgi_param  SERVER_ADDR        $server_addr;
            fastcgi_param  SERVER_PORT        $server_port;
            fastcgi_param  SERVER_NAME        $server_name;
            fastcgi_param  SERVER_PROTOCOL    $server_protocol;
            fastcgi_param  REMOTE_ADDR        $remote_addr;
            fastcgi_param  REMOTE_PORT        $remote_port;
            fastcgi_param  HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
        }
share|improve this question

2 Answers 2

I think there are two possibilities, of which the second would be the most flexible.

1

You could try:

location /admin{
    fastcgi_read_timeout 5m;
    include snippets/location.fcgi.conf;
}

location /sitemap.xml{
    fastcgi_read_timeout 5m;
    include snippets/location.fcgi.conf;
}

File snippets/location.fcgi.conf (no need for location block there):

fastcgi_pass 127.0.0.1:8014;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
# ...

2

Or I guess you could go like this.

location / {
    # set you default, so we don't bomb out
    set $timeout 2s;
    # your other general stuff
}

location /sitemap.xml{
    set $timeout 5m;
    include snippets/location.fcgi.conf;
}

location /admin{
    fastcgi_read_timeout 5m;
    include snippets/location.fcgi.conf;
}

NOTE: All include paths are always relative to the Nginx main config folder.
And yes, you can put them wherever you want provided that you have a symlink in place.

share|improve this answer

You can't inherit between location blocks but what you can do is use the include directive to place all your common configuration directives in one file and then include that in each location.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.