zoukankan      html  css  js  c++  java
  • nginx访问控制

    (1)基于ip的访问控制

    #vim /usr/local/nginx/conf/nginx.conf 
    //只允许单个ip,其它全部拒绝
    location /status {
    	stub_status on;
    	access_log off;
        allow 127.0.0.1/32;
        deny all;
       }
    
    #vim /usr/local/nginx/conf/nginx.conf
    //只允许单个网段,其它全部拒绝
    location /status {
    	stub_status on;
    	access_log off;
        allow 192.168.1.0/24;
        deny all;
       }
    

    (2)基于用户的访问控制

    1.安装工具和创建用户

    yum install httpd-tools -y												//安装工具包
    htpasswd -c /usr/local/nginx/conf/auth_conf auth_user					//创建配置文件,添加auth_user用户
    
    cat /usr/local/nginx/conf/auth_conf 
    auth_user:$apr1$8BcpYOko$L6bboNwSNSJgMIJfGtpkY.
    

    2.可在http,server,location下添加以下认证信息

    #vim /usr/local/nginx/conf/nginx.conf
    location /download {
    	root html;
    	auth_basic "Input your password!";									//提示符
    	auth_basic_user_file /usr/local/nginx/conf/auth_conf;				//指定需要认证的配置文件
        } 
    #nginx -t 
    #nginx -s reload
    


    3.验证
    http://192.168.1.31/download

    4.添加用户和删除用户

    htpasswd -b /usr/local/nginx/conf/auth_conf auth_test 123				//添加用户,第二次添加用户需要输入用户名和密码
    htpasswd -D /usr/local/nginx/conf/auth_conf auth_test					//删除用户
    
  • 相关阅读:
    448. Find All Numbers Disappeared in an Array
    447. Number of Boomerangs
    441. Arranging Coins
    438. Find All Anagrams in a String
    437. Path Sum III
    434. Number of Segments in a String
    422. Valid Word Square
    415. Add Strings
    414. Third Maximum Number
    [codility]Array-closest-ascenders
  • 原文地址:https://www.cnblogs.com/lovelinux199075/p/9056315.html
Copyright © 2011-2022 走看看