Apache 2.4 外部代理,内部重定向

Bri*_*ian 7 proxy reverse-proxy apache-2.4

我正在尝试设置一个反向代理,以只允许几个选定的 ip 范围代理到内部主机,而我希望不在 ip 范围内的任何其他人重定向到我们的内部命名主机。在此设置中,网络服务将正常工作,而没有通过 VPN 连接到我们网络的任何人都无法导航到内部资源。我一直试图让它在没有运气的情况下工作,我的部分配置目前如下:

       ProxyRequests Off
    <Proxy *>
            Allow from all
    </Proxy>
    <Location />
            Allow From xxx.xxx.xxx.xxx/24 1xxx.xxx.xxx.xxx/23
            Deny From All
            ProxyPass http://server.local.corp:8000/
            ProxyPassReverse http://server.local.corp:8000/
    </Location>
Run Code Online (Sandbox Code Playgroud)

此配置似乎可以很好地阻止其他 ip 范围进行代理,但是我不清楚如何为其他人添加重定向语句。

编辑 从第一个答案中获取建议我的代码现在看起来像:

<If "%{REMOTE_ADDR} -ipmatch 'xxx.xxx.xxx.xxx/24'">
  ProxyPass / http://server.local.corp:8000/
  ProxyPassReverse / http://server.local.corp:8000/
</If>
Run Code Online (Sandbox Code Playgroud)

并且 apache 在重启时抛出以下错误:

ProxyPass cannot occur within <If> section
Action 'configtest' failed.
The Apache error log may have more information.
Run Code Online (Sandbox Code Playgroud)

alx*_*omz 0

您需要将 ProxyPass 和 Redirect 指令包装到新引入的 If 语句中:\n <If expression>\n ProxyPass\xe2\x80\xa6\n </If>"

\n\n

查看http://httpd.apache.org/docs/2.4/mod/core.html#if以了解有关 If 指令的更多信息,以及http://httpd.apache.org/docs/2.4/expr .html来学习如何编写 Apache 表达式(-ipmatch 似乎就是您正在寻找的内容)

\n\n

请注意,这仅在 Apache httpd 2.4 中有效。

\n

  • Apache 2.4 不允许在 &lt;If&gt; 部分中使用 ProxyPass (3认同)