大网数据广告活动
服务器运维问答

Allow multiple IPs with the Require directive in Apache 2.4

· 52CE 我爱测

I am migrating from Apache 2.2 to 2.4, and would like to prefer the use of "Require" than the now discouraged use of Allow , Deny . My question: How can I allow access from a set of IP addresses or ranges, by having one address/r…

问题原文

原帖链接 · mimo · CC BY-SA 3.0

I am migrating from Apache 2.2 to 2.4, and would like to prefer the use of "Require" than the now discouraged use of Allow, Deny.

My question: How can I allow access from a set of IP addresses or ranges, by having one address/range per line in the configuration file?

With Apache 2.2, I used:

Order deny,allow
Deny from all
Allow from 2001:1000:2000::1/64
Allow from 1.2.3.4
Allow from 1.2.3.10

How would that translate to the new access control syntax?

社区高分解答

原帖链接 · Unbeliever · CC BY-SA 3.0

The upgrading documentation has clear information on how to do this. It is also something that should be read in case any other configuration changes are required: https://httpd.apache.org/docs/2.4/upgrading.html

Also you do not need to put different IP addresses or networks on separate lines. It is perfectly acceptable to do the following:

# Apache v2.2
Allow from 1.2.3.4 1.2.3.10
# Apache v2.4
Require ip 1.2.3.4 1.2.3.10

Finally, the default is for multiple require directives to be treated as if they are in a <RequireAny> block, so unless you are forming a more complex nested grouping you do not need to add it. Though you may wish to for clarify of course. Reference: https://httpd.apache.org/docs/2.4/howto/auth.html#beyond

Additional Information: One other thought is that when upgrading you should definitely go through all your configuration (including any htaccess files you might have) and convert the older Apache v2.2 directives to the Apache v2.4 ones, and then comment out the loading of the mod_access_compat module. Mixing v2.2 and v.24 directives can cause some very unusual problems that are hard to troubleshoot.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。