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

Apache Reverse Proxy : put a htaccess type password on a specfic URL

· 52CE 我爱测

I have an Apache2 reverse proxy managing multiple domains. Inside I have a vHost configured like this : <VirtualHost *:443> RewriteEngine On ServerName www.example.com DocumentRoot /var/lib/letsencrypt/http_challenges ProxyPass /…

问题原文

原帖链接 · Processor · CC BY-SA 4.0

I have an Apache2 reverse proxy managing multiple domains.

Inside I have a vHost configured like this :

<VirtualHost *:443>
        RewriteEngine On
        ServerName www.example.com
        DocumentRoot /var/lib/letsencrypt/http_challenges
        ProxyPass / http://10.55.0.180/plugin/main/
        ProxyPassReverse / http://10.55.0.180/plugin/main/
        ProxyRequests Off
        ProxyPreserveHost On
        <Directory /var/lib/letsencrypt/http_challenges>
            Allow from All
        </Directory>
        <Location /Cours/index.php/Stats/>
                  AuthType Basic
                  AuthName "Wrapper auth"
                  AuthBasicProvider file
                  AuthUserFile "/etc/.htpasswd"
                  Require valid-user
        </Location> 

The purpose of this is that users accessing https://www.example.com can do it without being prompted for a password whereas those who access https://www.example.com/Cours/index.php/Stats/ can't do it without being authenticated.

Of course, if I'm there, this method is not working.

The /etc/.htpasswd file is present and well configured but people are able to access https://www.example.com/Cours/index.php/Stats/ without being asked for a password.

已采纳解答

原帖链接 · Processor · CC BY-SA 4.0

It was easier than I thought. My issue was the trailing slash at the end of the location as it is automatically remove at the end of the URL in the browser. So this is the working config:

<VirtualHost *:443>
        RewriteEngine On
        ServerName www.example.com
        DocumentRoot /var/lib/letsencrypt/http_challenges
        ProxyPass / http://10.55.0.180/plugin/main/
        ProxyPassReverse / http://10.55.0.180/plugin/main/
        ProxyRequests Off
        ProxyPreserveHost On
        <Directory /var/lib/letsencrypt/http_challenges>
            Allow from All
        </Directory>
        <Location /Cours/index.php/Stats>
                  AuthType Basic
                  AuthName "Wrapper auth"
                  AuthBasicProvider file
                  AuthUserFile "/etc/.htpasswd"
                  Require valid-user
        </Location>

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

资料来源与适用范围

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

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

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