Recently, we came across a requirement to limit access to one of our production grade nginx server so that only a few of the applications running on different host can send requests.

The steps to enable such restrictions on nginx is quite easy.

1. Prepare configuration file with list of IP addresses.

  • Create a new file in /etc/nginx folder, named conf.
  • Add list of IP addresses to conf mentioning if particular IP address can make request to nginx or not.
# Restrict individual IP address

# Restrict subnet

# Allow your IP addresses, restrict all others
allow; deny all;

2. Update nginx configuration.

  • Modify /etc/nginx/nginx.conffile to include conf.
http {
  include /etc/nginx/restrictedips.conf;

3. Reload nginx configuration.

  • Reload nginx configuration with command

$ nginx -s reload

That’s all. We’re done.

Now, whenever someone from denied/restricted IP addresses want to access our web application via nginx, they will see 403 - Forbidden page.

At BoTree Technologies, we build web and mobile applications to add value to our client’s business. We align ourselves to ensure that our client benefits the most out of our engagement.

We work in Ruby on RailsPython, Java, React, Android, iOS and RPA as well.

Drop us a line to discuss how can we help take your business to the next level.