Several ways:
1. Command http://www.centos.bz/2011/12/nginx-http-auth-basic/
If there is no apache htpasswd program, you can use the pl program to generate:
Program address :http://trac.edgewall.org/export/10890/trunk/contrib/htpasswd.py
Usage: ./htpasswd.py -b -c pass.txt admin 123456
pass.txt is the password file, admin is User name, 123456 is the password.
2.apache http://jooben.blog.51cto.com/253727/429977
3. Command to generate password
./pw.pl password
After generating it, Added to nginx
#auth_basic "Please input your username and password!";
#auth_basic_user_file /usr/local/nginx/conf/engir_pass;