简体   繁体   English

Apache 2.4和php-fpm不会触发php页面的Apache http基本身份验证

[英]Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages

I am sure this is a question which has been asked somewhere, if so excuse me, but googling around did not give me anything tangible. 我确信这是一个在某个地方提出的问题,如果可以的话,请问一下,但是谷歌搜索并没有给我带来任何实质性的好处。

Here is my scenario: 这是我的情况:

I am protecting a web directory with apache http basic auth. 我使用apache http basic auth保护Web目录。 So I have my .htaccess in the root folder and my httpd.conf is configure to override all so that it takes the .htaccess into consideration. 因此,我将.htaccess放在根文件夹中,并将httpd.conf配置为覆盖所有内容,以便将.htaccess考虑在内。 The content of my .htaccess is as follows: 我的.htaccess的内容如下:

AuthType Basic AuthType基本

AuthName "test" AuthName“测试”

AuthUserFile /etc/httpd/.test_pass AuthUserFile /etc/httpd/.test_pass

Require valid-user 需要有效用户

.test_pass has been set up with htpasswd successfully. .test_pass已成功使用htpasswd设置。 When accessing the web root folder via the browser or any html file I get the authentication pop up correctly. 通过浏览器或任何html文件访问Web根文件夹时,我会正确弹出身份验证。 Using the password gives me the expected access. 使用密码给了我预期的访问权限。

But when I access a php page, the authentication pop up does not appear and the php page renders. 但是,当我访问php页面时,不会出现身份验证弹出窗口,并且会渲染php页面。

Here is my set up: 这是我的设置:

  • Apache Version: 2.4.6 Apache版本:2.4.6
  • php-fpm: PHP 5.4.16 (fpm-fcgi) with Zend Engine v2.4.0 php-fpm:装有Zend Engine v2.4.0的PHP 5.4.16(fpm-fcgi)
  • Using proxypass from proxy_fcgi_module (shared) for the communication between apache 2.4 and php-fpm 使用来自proxy_fcgi_module(共享)的proxypass进行Apache 2.4和php-fpm之间的通信
  • Also I am not using socket connections because apache 2.4.6 does not support it 另外我不使用套接字连接,因为Apache 2.4.6不支持它
  • My proxypass setting is as follows and works pretty well: ProxyPassMatch ^/(. .php(/. )?)$ fcgi://127.0.0.1:9000/var/www/html/$1 我的proxypass设置如下,并且运行良好:ProxyPassMatch ^ /(.. php( /。)?)$ fcgi://127.0.0.1:9000 / var / www / html / $ 1

I need to be able to set a username/password authentication via apache basic auth which protects every files including php files in the directory. 我需要能够通过apache基本身份验证设置用户名/密码身份验证,以保护目录中包括php文件在内的每个文件。

I am using opensource softwares; 我正在使用开源软件; therefore modifying the software codes is the very last resort. 因此,修改软件代码是最后的选择。

Is there a work around/solution for php-fpm and mod_proxy_fcgi? 是否有针对php-fpm和mod_proxy_fcgi的解决方案/解决方案?

Thanks 谢谢

After hours of research I understood that the reason that this occurs is because the ProxyPassMatch directive is the first directive to be processed, and this causes apache to ignore the other directives for the .php extensions. 经过数小时的研究,我了解到发生这种情况的原因是因为ProxyPassMatch伪指令是要处理的第一个伪指令,这使apache忽略了.php扩展名的其他伪指令。

To be able to use other apache directives with php-fpm via the proxy_fcgi_module one should rather use the filesmatch directive instead of proxypassmatch. 为了能够通过proxy_fcgi_module与php-fpm一起使用其他apache指令,应该使用filesmatch指令而不是proxypassmatch。

The syntax is as follows: 语法如下:

<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

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

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