limit_except

The 'limit_except' directive restricts HTTP request methods in a specified location block.

Syntaxlimit_except method { deny|allow ...; };
Defaultnone
Contextlocation
Argumentsblock (1+)

Description

The 'limit_except' directive in NGINX is used within a location block to limit the allowed HTTP request methods. When implemented, it defines a set of allowed methods, while all other methods will receive a 403 Forbidden response. For instance, if you specify 'GET' and 'HEAD' in the 'limit_except' block, all other methods like 'POST', 'PUT', or 'DELETE' will be blocked. This is useful for securing resources where only specific methods should be permitted, thereby enhancing access control and security.

The directive takes a block as its argument, which contains one or more methods specified using the corresponding configuration syntax. Each method can be listed consecutively within the block. For example, if you have 'limit_except GET { deny all; }', only GET requests to that location will be allowed. It is crucial to understand that in the context of URI protection, the exceptions defined here provide graceful handling of disallowed requests while ensuring legitimate methods are served without interruptions.

Config Example

location /protected {
    limit_except GET {
        deny all;
    }
}

Ensure the methods specified in 'limit_except' are supported by your application; unsupported methods may inadvertently return a 403 error.

Remember that 'limit_except' rules apply only to the specified location block and not to nested location blocks unless explicitly defined there.

← Back to all directives