0

I am very new to Nginx and I have below configuration in Nginx

server {
location /api {

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

So now suppose if user access hostname/api/{{anything}} should allow them to access but user tries to access hostname/api/admin it should deny them, So how I can achieve this?

Thanks

Mahesh G
  • 101
  • 3

1 Answers1

2

You could specify the paths in the config like so : See relevant doc here

 <Location /api/*>
    Order Allow,Deny
    Allow from all
  </Location>
  <Location /api/admin>
    Order Allow,Deny
    Deny from all
  </Location>

EDIT : Provided solution for apache, but nginx was required. Location directive also exists in nginx :

location /api/* {
    allow all;
}

location /api/admin {
    deny all;
}
Dexirian
  • 430
  • 2
  • 11