nginx allow local access

Nginx Allow Local Network

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

Leave a Reply

Your email address will not be published. Required fields are marked *