Nginx configuration

I’m trying to throw an error(403) if request is for api. So I created map like this map $uri $is_webpage { ~\.(html|htm|js) 0; #web pages default 1; #apis }

map $is_webpage $error_code { 0 return 302 $location_page/static/login.html; default return 403; }

and in location block I’m specifying $error_code but it is not working. So can you please help me with this. I am not allowed to use if.

@Sushant91265 if you want to throw just 403 to a particular request, you can try

location = /myapi { return 403; }

THanks

1 Like