Sometimes you may need to allow access to only local IP addresses or network to your website. In this article, we will learn how to allow access to local network in NGINX.
Nginx Allow Local Network
Here are the steps to allow local network in NGINX.
1. Open NGINX configuration file
Open NGINX configuration file in a text editor.
$ sudo vi /etc/nginx/nginx.conf
2. Allow Local Network
If you only want to allow access from your local machine, then add the following location block inside server block.
server { ... location / { allow 127.0.0.1; deny all; ... } ... }
If you want to allow access only from local network IP range 192.168.1.0-192.168.1.255, then add the following location block inside server block.
server { ... location / { allow 192.168.1.0/24; deny all; ... } ... }
Save and close the file.
3. Restart NGINX Server
Restart NGINX server to apply changes.
$ sudo service nginx restart
Also read:
How to Prevent Direct Access to Images in NGINX
How to Prevent Direct Access to Images in Apache
How to Know Which Shell I am Using
How to Find Package Details in RHEL, CentOS & Fedora
How to Delete Objects in Django
Related posts:
How to Get Unique IP Address from Log File
How to Setup Uwsgi with NGINX for Python
How to do Case Insensitive Rewrite in NGINX
How to Exclude Requests from NGINX Log
How to Use NGINX as Reverse Proxy for NodeJS
Cannot Access NGINX From Outside
NGINX Catch All Location
Set NGINX to Catch All Unhandled Virtual Hosts

Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.