【发布时间】:2014-06-18 04:37:30
【问题描述】:
我做了什么:
从源代码安装 apache 2.4 和 php 5.4。
apache 配置:
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
php 配置
./configure --prefix=/usr/local/php \
--with-mysql=mysqlnd\
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir\
--with-png-dir\
--with-zlib \
--with-libxml-dir=/usr/local/libxml2 \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2\
--with-apxs2=/usr/local/apache/bin/apxs
在 httpd.conf 文件中,我启用了 mod_proxy.so 和 mod_proxy_fcgi.so 并添加以下配置:
<IfModule proxy_module>
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/$1
</IfModule>
从 phpinfo(),我看到 Server API 是 FPM/FastCGI
我的问题: 我将 DirectoryIndex 设置如下。我在 DirectoryRoot 中有 index.html,即“/var/www”。当我访问 localhost 时,我应该看到 index.html 的内容。但它给出了一个 404 文件未找到。
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
当我在上面的代码中切换 index.html 和 php 的位置时。这次html文件在php文件的前面。然后当我访问 localhost 时,我可以看到正确的内容。 我检查了 apache 错误日志。它说:
[Thu May 01 23:21:15.968659 2014] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unkn own\n'
/var/www 中只有 index.php 文件时,像 httpd.conf 一样
<IfModule dir_module> DirectoryIndex index.html index.php</IfModule>
同样得到404,访问本地主机。
我的问题:
"FastCGIExternalServer /var/www/cgi-bin/php5.fcgi -host 127.0.0.1:9000"
所以我不确定我是否以正确的方式使用 FastCgi?这种错误的方式会导致上述问题吗?
【附注】 谢谢你。我没有使用虚拟主机,我检查了 error.log。它似乎与php-fpm有关。浏览器中的响应页面显示“找不到文件”,而不是“404”,尽管响应代码是 404。这是 error.log 中的内容
[2014 年 5 月 1 日星期四 23:21:15.968659] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unknown\n'
我尝试将所有以“.php”结尾的请求转发到 fcgi。但是上面的错误好像是我请求index.html的时候,也是转发给fcgi的,fcgi不能处理。(这是我的猜测)关于这个转发的配置,请看上面的代码,或者搜索这个“fcgi://”的页面。
这是我的目录配置。我不确定这是否是您需要的。
DocumentRoot "/var/www"
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
【问题讨论】:
-
对于您关注的链接,他们使用旧方法将 apache 中的 php-fpm 与 libapache2-mod-fastcgi 连接。自 2.4 版以来,mod_proxy_fastcgi 是新的官方方式。现在您应该显示完整的 vhost 配置,并且 404 错误应该在 apache error.log 中添加有用信息的行。