ThR*_*R37 7 apache-http-server proxy
我正在通过指令ProxyPass和ProxyPassReverse一些网址在 apache 中设置一个代理:
ProxyPass /mypath http://myotherserver.com
ProxyPassReverse /mypath http://myotherserver.com
Run Code Online (Sandbox Code Playgroud)
但是,myotherserver.com需要(基本)身份验证。如果我什么都不做,这个身份验证就会传递给最终的客户端。出于某种原因,我不希望这样,我想直接在我的 apache 配置中添加凭据。我怎样才能做到这一点 ?我试过:
ProxyPass /mypath http://user:pass@myotherserver.com
ProxyPassReverse /mypath http://user:pass@myotherserver.com
Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用。在此先感谢您的帮助。
ThR*_*R37 17
我实际上已经找到了解决方案。我希望它对其他人有用:
运行以下 python 脚本以获取您的身份验证hash:
import base64
hash = base64.b64encode(b'user:password')
Run Code Online (Sandbox Code Playgroud)
在您的 apache 配置中添加以下指令:
<Location /mypath>
RequestHeader set Authorization "Basic $hash"
</Location>
Run Code Online (Sandbox Code Playgroud)
where$hash替换为先前计算的字符串。
确保mod_proxy和mod_headers可用(a2enmod proxy和a2enmod headers)。重新启动 apache2,你就完成了:)