Saturday, July 9, 2022

How to Restrict Request Method in NGINX


HTTP and HTTPS protocol has several request methods. POST, GET, PUT, PATCH, HEAD and DELETE. When we configuraing NGINX web server we need to restrict PUT,PATCH and DELETE request methods. Only POST, GET and HEAD methods enough to enable from web sever.

Configurations

For Static Content

location /request {
        if ( $request_method !~ ^(GET|POST|HEAD)$ )
        {
                return 405;
        }
        root  /usr/share/nginx/html;
}

For Proxy Pass

location /request-Proxy {
        if ( $request_method !~ ^(GET|POST|HEAD)$ )
        {
                return 405;
        }
        proxy_pass      https://127.0.0.1:8380;
}

Output

GET Request 




DELETE Request






No comments:

Post a Comment