How to Allow or Disallow A Customer to Access Admin Area of Magento?

Allow or Disallow certain ips to access Magento 2.3 admin area is very important for security reasons. I am using Nginx for my Magento 2.3 shop. I have tried the following method for Magento 2.3.

Method One:

# IP RESTRICTED URI
location ~* ^/(index\.php/admin_eyewearcanada|admin_eyewearcanada) {
  index index.php;
  try_files $uri $uri/ /index.php?$args;
  allow 192.168.0.13; # Office IP Address
  allow 192.168.0.16; # Warehouse IP Address
  deny all;
  location ~* \.php$ {
    fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Method Two:

# location ~* ^/(index\.php/admin_eyewear_canada|admin_eyewear_canada) {
location ~ ^/(index\.php/)?admin_eyewear_canada/? {
    deny 49.87.2.168;
 
    try_files $uri $uri/ /index.php?$args;
    location ~* \.php$ { try_files /dummy @proxy; }
    allow all;
}
Published
Categorized as Magento