nginxの設定で以下のようにします。
location / {
satisfy any;
auth_basic "Basic Auth";
auth_basic_user_file /path/to/.htpasswd;
allow xxx.xxx.xxx.xxx;
allow xxx.xxx.xxx.xxx;
deny all;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}


