Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

Combining .htaccess IP block with AuthType Basic on Apache 2.4

I need to combine basic auth in the apache conf file, with a (long) series of IPs to block in the .htaccess file.

The IP blocking works, but if I switch on the basic auth in the site's conf file, authentication does not work.

My site's conf is as follows:

<Directory "/var/www/sites/site.com/">
    Require all denied
    AuthName "Dev Site"
    AuthType Basic
    AuthUserFile /etc/httpd/conf/users
    deny from all
    allow from 1.0.0.0/8 2.0.0.0/8 3.0.0.0/8
    Require valid-user
</Directory>

.htaccess file (IPs to block):

<RequireAll>
Require all granted
Require not ip 10.1.1.1
Require not ip 11.1.1.1
# ...
</RequireAll>

It's as if the .htaccess directives are overriding the basic auth in the conf file. If I remove the .htaccess file, then the basic auth works as expected. The .htaccess block list is dynamic, so it needs to remain.

I'd appreciate any ideas.

Thanks

question from:https://stackoverflow.com/questions/65644613/combining-htaccess-ip-block-with-authtype-basic-on-apache-2-4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...