简体   繁体   English

Apache 2.4 反向代理设置不能强加基本身份验证

[英]Apache 2.4 reverse proxy setup cannot impose basic authentication

I have apache2.4 set up and when visiting any apache served web sites basic authentication works great.我设置了 apache2.4 并且在访问任何 apache 服务的 web 站点时,基本身份验证效果很好。

Now I have one more webserver running from an other service at port 8000 and I wanted to setup apache as a reverse proxy hoping that it can also impose and handle basic authentication there as well...but instead for asking for user and password it just serves the website unprotected.现在我在端口 8000 上从其他服务运行了一个网络服务器,我想将 apache 设置为反向代理,希望它也可以在那里强加和处理基本身份验证......但只是询问用户和密码为网站提供不受保护的服务。

my setup is:我的设置是:

<VirtualHost *:8000>
    ProxyPreserveHost On
    ProxyPass / http://192.168.0.101:8000/
    ProxyPassReverse / http://192.168.0.101:8000/
<Location />
AuthType Basic
AuthName "Authorization"
AuthUserFile /etc/htpasswd/.htpasswd
require valid-user
</Location>
</VirtualHost>

what am i doing wrong?我究竟做错了什么?

Update: solution found by marked answer:更新:标记答案找到的解决方案:

<VirtualHost *:8000>
  ProxyPreserveHost On

  <Location />
    ProxyPass http://192.168.0.101:8000/
    ProxyPassReverse http://192.168.0.101:8000/
    
    AuthType Basic
    AuthName "Authorization"
    AuthUserFile /etc/htpasswd/.htpasswd
    require valid-user
  </Location>
</VirtualHost>

Also make sure that apache is configured to listen to that port and also if the proxied server is local it is not running at the same port as listened one还要确保 apache 配置为侦听该端口,并且如果代理服务器是本地的,则它不在与侦听的端口相同的端口上运行

The problem is that Apache doesn't 'link' Proxypass / http://example.com and <Location /> - even though they both try to work with / .问题是 Apache 没有“链接” Proxypass / http://example.com<Location /> - 即使他们都尝试使用/ This means that Proxypass is handling requests for '/' first, and the Location section is never being used.这意味着 Proxypass 首先处理对“/”的请求,并且永远不会使用Location部分。

You need to move the Proxy config inside the Location , dropping the path, eg:您需要在Location中移动代理配置,删除路径,例如:

<VirtualHost *:8000>
  ProxyPreserveHost On

  <Location />
    ProxyPass http://192.168.0.101:8000/
    ProxyPassReverse http://192.168.0.101:8000/
    
    AuthType Basic
    AuthName "Authorization"
    AuthUserFile /etc/htpasswd/.htpasswd
    require valid-user
  </Location>
</VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM