apache、nginx验证

1.一般做二次验证:

apache2-utils
mini-httpd
#以上2个包都带htpasswd工具
#sudo   apt-get   install  install  apache2-utils 或 mini-httpd
#htpasswd -b -c /usr/local/nginx/conf/nginx_passwd  kkk kkk   #创建验证文件并添加用户
#htpasswd -b /usr/local/nginx/conf/nginx_passwd  ppp  kkk     #添加验证用户
#htpasswd -D  /usr/local/nginx/conf/nginx_passwd  ppp    #删除用户ppp

2.nginx配置:

server {
        listen 80 default_server;
        server_name localhost;
        root /data/www/t1;
        index index.php index.html index.htm;
        

        #对app目录开启验证
        location  /app {
            location ~ .*\.(php|php5)?$ {
                #fastcgi_pass unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fcgi.conf;
            }
        #以下验证方式:基本验证
        auth_basic "input you user name and  password";
        auth_basic_user_file /etc/nginx/conf.d/nginx_passwd;
        #auth_basic_user_file conf.d/nginx_passwd; #验证文件配置在ngix目录,不可以配置网站目录下
        }
        #对pkg开启目录列表
        location  /pkg {
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        }

3.apache2配置:

<VirtualHost 127.0.0.1:8081>
        #ServerName www.example.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        <Directory /var/www/html/phpmyadmin>
        Options Indexes FollowSymLinks
        AllowOverride authconfig  #自动寻找网站根目录下的.htaccess文件
        order allow,deny
        allow from all
        #Require all granted
        </Directory>
        #
        <Directory /var/www/html/pkg>
        ##对pkg开启目录列表
        Options Indexes
        IndexOptions NameWidth=25 Charset=UTF-8 
        Order allow,deny
        Allow from all
        </Directory>
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
#----------------------------------------------------------------
# vi  /var/www/html/.htaccess
AuthName "Please input name and password:"
AuthType basic
AuthUserFile /etc/apache2/apache2.pas
require valid-user

4.重启nginx、apache

你可能感兴趣的:(apache、nginx验证)