• Apache对web访问用户进行限制

    Posted on 九月 10th, 2007 inetdemon No comments

    Apache下有两种模式可以对用户限制:

    1. apache验证模式:服务端ip,refer 调用DSO引擎,403限制访问

    这种方式适合服务端调用,只要2步就可以完成操作。
    第一步,可以直接写到 httpd.conf 里面,但是建议写一个auth.conf 验证文件
    #头文件中为 userid=001
    SetEnvIfNoCase Referer "userid=001" local_ref=1
    #访问引擎的 IP
    SetEnvIfNoCase Remote_Addr  "172.16.74.139" local_ref=1

    第二步,验证,让只有auth.conf中 local_ref=1的用户才可以访问你的 DSO 服务
    写一个 mod_search.conf (好习惯), httpd.conf  中include它
    #包含so模块
    loadModule search_module modules/mod_search.so
    #服务部署
    <Location /LocalSearch>
    SetHandler LocalSearch
    Log4Cpp /apache/smartls/log4cpp.properties
    WordTable /apache/smartls/smartlsData/wordTable.txt
    WordTableEntry /apache/smartls/smartlsData/wordTableEntry.txt
    PoiBal /apache/smartls/smartlsData/Poi.bal
    PoiBas /apache/smartls/smartlsData/Poi.bas
    PoiNdx /apache/smartls/smartlsData/Poi.ndx
    PoiACode /apache/smartls/smartlsData/ACode.ndx
    AnTable /apache/smartls/smartlsData/AnTable.txt
    CnTable /apache/smartls/smartlsData/CnTable.txt
    LsIDTable /apache/smartls/smartlsData/LsIDTable.idx
    </Location>
    #验证DSO服务,只有auth.conf的用户才可以访问
    <Location /LocalSearch>
    SetHandler LocalSearch
    Order Allow,Deny
    Allow from env=local_ref
    </Location>

    这个是用apache的access设定调用403禁止访问,如果不想简单禁止访问可以用apache重定向来实现。

    2. 用户名/密码弹出框 验证访问

    这种方式适合url访问或客户端使用

    #输入框 验证
    <Location /LocalSearch>
    SetHandler LocalSearch
    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /usr/local/awstats/passwd
    Require user 51ditu_admin
    require valid-user
    </Location>

    #查看认证的用户名密码

    vi /usr/local/awstats/passwd
    jeff:S4EYx.WkmiBLg

    #那个密码是这样生成的

    htpasswd -c .htpasswd jeff

    第一次创建用户要用到-c 参数 第2次添加用户,就不用-c参数,如果你们想修改密码,可以如下
    htpasswd -m .htpasswd jeff

    也可以用mySql作验证用户库

    #AuthMySQLHost localhost
    #AuthMySQLUser root
    #AuthMySQLPassword 123456
    #AuthMySQLPasswordField user_passwd
    #AuthMySQLDB test
    #AuthMySQLUserTable user_info
    #AuthMySQLPwEncryption none

    Leave a reply