Apache2反向代理到需要BasicAuth但想要从用户隐藏它的端点

Bo *_*nes 20 apache reverse-proxy apache2 mod-proxy basic-authentication

基本上我的情况是我有一个内部网站,需要一个单一的硬编码用户名和密码才能访问(这不能关闭,只能更改).我出于各种原因通过反向代理公开这个网站(隐藏端口,简化网址,简化NAT等).

但是,我想要做的是能够使用Apache来处理身份验证,以便:

  1. 我没有给每个人发密码
  2. 我可以使用Apache的BasicAuth拥有多个用户名和密码
  3. 对于内部用户,我不必提示输入密码

编辑:关于更丰富的身份验证的第二部分已移至新问题

这或多或少是我现在所拥有的:

<VirtualHost *:80>
  ServerName sub.domain.com

  ProxyPass        / http://192.168.1.253:8080/endpoint
  ProxyPassReverse / http://192.168.1.253:8080/endpoint

  # The endpoint has a mandatory password that I want to avoid requiring users to type
  # I.e. something like this would be nice (but does not work)

  # ProxyPass        / http://username:password@192.168.1.253:8080/endpoint
  # ProxyPassReverse / http://username:password@192.168.1.253:8080/endpoint

  # Also need to be able to require a password to access proxy for people outside local subnet
  # However these passwords will be controlled by Apache using BasicAuth, not the ProxyPass endpoint

  # Ideas?
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

vla*_*adr 24

在将任何请求传递到端点之前添加或覆盖Authorization标头.授权标头可以是硬编码的,它只是字符串"username:password"的base-64编码(不带引号).

如果尚未完成,请启用mod_headers模块.

RequestHeader set Authorization "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
Run Code Online (Sandbox Code Playgroud)

要有条件地执行此操作,请启用mod_setenvif,例如,在本地请求的情况下仍然要求输入主密码:

SetEnvIf Remote_Addr "127\.0\.0\.1" localrequest
RequestHeader set Authorization "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" env=!localrequest
Run Code Online (Sandbox Code Playgroud)

# ALL remote users ALWAYS authenticate against reverse proxy's
#  /www/conf/passwords database
#
<Directory /var/web/pages/secure>
  AuthBasicProvider /www/conf/passwords
  AuthType Basic
  AuthName "Protected Area"
  Require valid-user
</Directory>

# reverse proxy authenticates against master server as:
#  Aladdin:open sesame (Base64 encoded)
#
RequestHeader set Authorization "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
Run Code Online (Sandbox Code Playgroud)


小智 6

好吧,我用你的例子来指向两个使用 apache proxypass 的 IP 摄像机。当我使用语法 user:password@camarafeliz3.compu Fiber.com 并通过 iphone 访问时,我收到了来自 safari(iphone 导航器)的安全消息,因此我更改了示例以使其能够与 iPhone 4S 配合使用

<Location /camarafeliz1/ >
        # usuario admin password 123456
        ProxyPass         http://192.168.0.39/
        ProxyPassReverse  http://192.168.0.39/
        RequestHeader set Authorization "Basic YWRtaW46MTIzNDU2=="
</Location>
<Location /camarafeliz3/ >
        # usuario admin password 123456
        ProxyPass         http://192.168.0.99/
        ProxyPassReverse  http://192.168.0.99/
        RequestHeader set Authorization "Basic YWRtaW46MTIzNDU2=="
</Location>
Run Code Online (Sandbox Code Playgroud)

由于链接中的用户名和密码,iPhone 4s 不再抱怨安全问题。