Skip to content

Instantly share code, notes, and snippets.

@andreimaxim
Last active December 15, 2015 23:09
Show Gist options
  • Save andreimaxim/5338303 to your computer and use it in GitHub Desktop.
Save andreimaxim/5338303 to your computer and use it in GitHub Desktop.
# This block requires the geo module, which enables the use of
# variables which depend on the IP address of the client.
#
# In this case, everyone outside of the 192.168.0.x network
# is considered an "external" client.
geo $external {
default 1;
192.168.0.0/24 0;
}
server {
listen 192.168.0.1:80;
server_name example.com;
# Redirect all requests from the external IPs to an
# unauthorized page.
if ($external) {
rewrite ^ /unauthorized.html last;
}
try_files $uri $uri.html $uri/index.html =404;
}
server {
listen 192.168.0.1:80;
server_name example.com;
location / {
# This line determines the access policy based on multiple
# access handles, meaning it will let the user pass if any
# of the following conditions are fulfilled:
#
# * the IP address belongs to the 192.168.0.x range
# * the username and password match those on file in users.conf
satisfy any;
allow 192.168.0.0/24;
deny all;
auth_basic "Restricted Access";
auth_basic_user_file users.conf;
try_files $uri $uri.html $uri/index.html =404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment