Apache 2.4和php-fpm不会触发php页面的Apache http基本身份验证 [英] Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages

查看:125
本文介绍了Apache 2.4和php-fpm不会触发php页面的Apache http基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定这是一个在某个地方问过的问题,如果可以的话,请问一下,但是谷歌搜索并没有给我带来任何实质性的好处。

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.

这里是我的情况:

我正在使用apache http basic auth保护Web目录。因此,我将.htaccess放在根文件夹中,并将httpd.conf配置为覆盖所有内容,以便将.htaccess纳入考虑范围。我的.htaccess的内容如下:

I am protecting a web directory with apache http basic auth. 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. The content of my .htaccess is as follows:

AuthType Basic

AuthType Basic

AuthName test

AuthName "test"

AuthUserFile /etc/httpd/.test_pass

AuthUserFile /etc/httpd/.test_pass

需要有效用户

.test_pass已成功使用htpasswd设置。通过浏览器或任何html文件访问Web根文件夹时,我会正确弹出身份验证。使用密码给了我预期的访问权限。

.test_pass has been set up with htpasswd successfully. When accessing the web root folder via the browser or any html file I get the authentication pop up correctly. Using the password gives me the expected access.

但是当我访问php页面时,不会出现身份验证弹出窗口,并且会渲染php页面。

But when I access a php page, the authentication pop up does not appear and the php page renders.

这是我的设置:


  • Apache版本:2.4.6

  • php-fpm:带有Zend Engine v2.4.0的PHP 5.4.16(fpm-fcgi)

  • 使用proxy_fcgi_module(共享)中的proxypass来实现apache 2.4和php-fpm >
  • 我也不使用套接字连接,因为apache 2.4.6不支持

  • 我的proxypass设置如下,效果很好:
    ProxyPassMatch ^ /(.. .php(/.)?)$
    fcgi://127.0.0.1:9000 / var / www / html / $ 1

  • Apache Version: 2.4.6
  • php-fpm: PHP 5.4.16 (fpm-fcgi) with Zend Engine v2.4.0
  • Using proxypass from proxy_fcgi_module (shared) for the communication between apache 2.4 and php-fpm
  • Also I am not using socket connections because apache 2.4.6 does not support it
  • My proxypass setting is as follows and works pretty well: ProxyPassMatch ^/(..php(/.)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

我需要能够通过apache基本身份验证设置用户名/密码身份验证,以保护目录中的所有文件,包括php文件。

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.

我正在使用开源软件;因此,修改软件代码是最后的选择。

I am using opensource softwares; therefore modifying the software codes is the very last resort.

是否有针对php-fpm和mod_proxy_fcgi的解决方案?

Is there a work around/solution for php-fpm and mod_proxy_fcgi?

谢谢

推荐答案

经过数小时的研究,我了解到发生这种情况的原因是ProxyPassMatch指令是第一个指令要处理,这会导致apache忽略.php扩展名的其他指令。

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.

为了能够通过php-fpm使用其他apache指令proxy_fcgi_module一个人应该使用filesmatch指令而不是proxypassmatch。

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.

语法如下:

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

这篇关于Apache 2.4和php-fpm不会触发php页面的Apache http基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆