以上界面,如果管理员设置密码过于简单其他人试出来,就太不安全了,所以在些基础上我们可以加一层用户认证。

更新配置之前备份配置文件。

[root@LNMP vhosts]# cd /usr/local/nginx/conf/vhosts

                   # vim linux.conf

server

{

    listen 80;

    server_name www.linux.com;

    index index.html index.htm index.php;

    root /data/dis;

    }

    location ~ \.php$ {

        include fastcgi_params;

        fastcgi_pass unix:/tmp/dis.sock;

        #fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME /data/dis$fastcgi_script_name;

    }

}

-------------------------------------------------------------------------

按照实验要求加入认证,验证代码并没有错误,并重起nginx 服务,

location ~ .*admin\.php$ {

    auth_basic "auth";

    auth_basic_user_file /usr/local/nginx/conf/.htpasswd;

    include fastcgi_params;

    fastcgi_pass unix:/tmp/dis.sock;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME /data/dis$fastcgi_script_name;

插曲

nginx 没有密码工具,所以需要安装htpasswd 工具,且创建用户。

[root@LNMP ~]# htpasswd -c /usr/local/nginx/conf/.htpasswd linux

[root@LNMP ~]# cat /usr/local/nginx/conf/.htpasswd  #查看添加的用户

liven:PyvLlwpERgowE

liven1:***3WNKyvYSeY

再次刷新网页