Nginx allow only one ip

 

To allow only one IP to access add following line in nginx.conf file:

server {
    listen 80;
    server_name www.example.com;

    location / {
      root /var/www/;

      allow   add.your.ip.here;
      deny    all;
    }
  }

Two lines that are bold in above configuration are important to achieve this functionality.

After adding above configuration restart nginx and try to test. Expect from your IP is should not allow access to any other IP.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s