ANS Documentation

Improve This Doc
  • Cloud
  • Domains and DNS management
  • Backup and High Availability
  • eCommerce Stacks
    • Magento
      • Magento 1
      • Magento 2
    • Shopware
    • WooCommerce
    • AeroCommerce
  • Security
  • Email
  • Monitoring and usage management
  • Networking
  • Operating systems
  • Webcelerator
  • MyUKFast
  • Home >
  • eCommerce Stacks >
  • Magento >
  • Magento 1 >
  • Restrict Website

Restrict Website¶

This guide is to show you how you can Password and or IP restrict a website. This is most common for staging or development websites. This guide is for the NGINX web service and is applicable for Magento 1 or Magento 2.

htpasswd File¶

For password restriction you need to generate a username and password before configuring NGINX. You can do this with the following command:

~]$ htpasswd -c /etc/nginx/conf.d/.htpasswd adminusername
New password:
Re-type new password:
Adding password for user adminusername
~]$

Password Restriction¶

To password restrict your website following configuration options for NGINX:

# PASSWORD RESTRICTED WEBSITE
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/conf.d/.htpasswd;

IP Restriction¶

To IP restrict your website use the following configuration options for NGINX:

# IP RESTRICTED WEBSITE
   allow 192.168.0.13; # Office IP Address
   allow 192.168.0.51; # Warehouse IP Address
   deny all;

Password with IP Allow list¶

To password restrict the website whilst allowing certain IP address(s) access to the website without password restrictions you can use the following configuration options for NGINX:

# PASSWORD RESTRICTED WITH IP ALLOW LIST WEBSITE
  satisfy any;
  allow 192.168.0.13; # Office IP Address
  allow 192.168.0.51; # Warehouse IP Address
  deny all;
  auth_basic "Restricted";
  auth_basic_user_file /etc/nginx/conf.d/.htpasswd;

Password and IP Restriction¶

The most secure method is to restrict the website to an allowed list of IP addresses and then have password restriction for the allow list. You can achieve this with the following configuration options in NGINX:

# PASSWORD AND IP RESTRICTED WEBSITE
  satisfy all;
  allow 192.168.0.13; # Office IP Address
  allow 192.168.0.51; # Warehouse IP Address
  deny all;
  auth_basic "Restricted";
  auth_basic_user_file /etc/nginx/conf.d/.htpasswd;

These configuration options need to be placed within the server block of your NGINX configuration file.

To implement this change you need to reload the NGINX service. First perform a configuration test with the following command:

 ~]$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If there are no errors in the configuration test proceed to reload the NGINX service with the following command:

 ~]$ nginx -s reload

Next Article > Time To First Byte (TTFB)

  • Useful Links
  • SMB
  • Enterprise
  • Channel
  • Public Sector
  • ANS Data Centres
  • About ANS
  • Careers
  • Blog
  • Get in touch
  •  
  • Sales 0800 458 4545
  • Support 0800 230 0032
  • Get in touch

© ANS Group Limited | Terms and Conditions | Corporate Guidance | Sitemap
ANS Group Limited, registered in England and Wales, company registration number 03176761, registered office 1 Archway, Birley Fields, Manchester M15 5QJ