Mar 23

It occur to me how to add somekind like .htaccess user login authentication on nginx, it was called NginxHttpAuthBasicModule. You need to go to your nginx.conf.  Here is some example :

# vim /etc/nginx/nginx.conf

root /usr/local/www/page;
index  index.php;
location  /user  {
auth_basic            “Restricted”;
auth_basic_user_file  /usr/local/www/user.pass
}

location ~ \.php$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME /usr/local/www/page$fastcgi_script_name;
include        fastcgi_params;
}

then create user.pass using htpasswd

# /usr/bin/htpasswd -c /usr/local/www/user.pass admin

New password:
Re-Type new password:
Adding password for user admin

then restart your nginx

# /etc/init.d/nginx stop

#/etc/init.d/nginx start

And now you can access the page http://localhost/user