1:打开虚拟主机配置文件,在server{}增加如下内容
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
2:使用htpasswd工具生成 .htpasswd文件,可以使用apache的htpasswd工具生成,也可以yum install httpd安装后来生成
/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/.htpasswd aming
输入2次密码
3: /usr/local/nginx/sbin/nginx -t 检查ok,
/usr/local/nginx/sbin/nginx reload 重新加载
页面的301重定向 http://www.apelearn.com/bbs/thread-4840-1-1.html
server_name www.test.com test.com;
if ($host != 'www.test.com')
{
rewrite ^/(.*)$ www.test.com/$1 permanent;
}
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
2:使用htpasswd工具生成 .htpasswd文件,可以使用apache的htpasswd工具生成,也可以yum install httpd安装后来生成
/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/.htpasswd aming
输入2次密码
3: /usr/local/nginx/sbin/nginx -t 检查ok,
/usr/local/nginx/sbin/nginx reload 重新加载
页面的301重定向 http://www.apelearn.com/bbs/thread-4840-1-1.html
server_name www.test.com test.com;
if ($host != 'www.test.com')
{
rewrite ^/(.*)$ www.test.com/$1 permanent;
}
编辑回复