带有mod_fastcgi和Symfony2的Apache2无法正确识别图像文件



我已经挣扎了一段时间,在谷歌上寻找我的问题的想法和解决方案,但我仍然无法找到这个。

我有一个使用mod_fastcgi的Apache2服务器,并且正在使用Symfony2。一切似乎都很好,CSS和JS文件以及PHP文件都经过了正确的解析。然而,问题在于图像文件,例如.png文件(甚至favicon.ico也无法识别)。直接访问该文件会使我访问被拒绝,而在.titch模板中使用文件会在apache的error.log中出现以下错误:

    FastCGI: server "/home/{...}/www/fastcgi/mina/php5.external/favicon.ico" stderr: Access to the script '/home/{...}/www/fastcgi/mina/php5.external/favicon.ico' has been denied (see security.limit_extensions)

我目前的配置是:

fastcgi.conf:

    <IfModule mod_fastcgi.c>
       FastCgiIpcDir /var/lib/apache2/fastcgi/
       AddHandler php5-fcgi .php
       Action php5-fcgi /cgi-bin/php5.external
       <Location "/cgi-bin/php5.external">
        Order Allow,Deny
        Allow from All
       </Location>
    </IfModule>

我的VirtualHost配置:

<VirtualHost *:6308>
    ServerName mina.loc
    DocumentRoot /home/{...}/www/mina/web
    # Fast CGI + FPM
    FastCgiExternalServer /home/{...}/www/fastcgi/mina/php5.external -socket /var/run/php5-fpm.sock
    Alias /cgi-bin/ /home/{...}/www/fastcgi/mina/
    <Directory />
        Options FollowSymLinks 
        AllowOverride All
    </Directory>
    <Directory /home/{...}/www/mina/web>
        Options FollowSymlinks  
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    Action application/x-httpd-php /cgi-bin/php5
    ErrorLog /var/log/apache2/error.log
    LogLevel debug 
    LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %T/%D" extended
    CustomLog /var/log/apache2/mina_access.log extended
    # Enable output compression for all text/html files
    AddOutputFilterByType DEFLATE text/html text/plain
</VirtualHost>

其中php5.external是指向我的Symfony的web文件夹的符号链接,其中包含app.phpapp_dev.php.htaccess文件,以及指向我的bundle、javascript和css文件的链接。

我真的不确定问题出在哪里,因为我在这个话题上读到的大部分内容都是关于Nginx+fastcgi的。我想这是在设置整个网络文件夹与fastcgi一起使用,但不能确定。有人有什么建议吗?谢谢

将其添加到php-fpm配置中以解决问题:

 security.limit_extensions = FALSE

好吧,我自己设法解决了这个问题。正是我对fastcgi配置的误解造成了这个问题,通过这个链接,我解决了这个问题。

以下是经过修订的两个文件:

fastcgi.conf

<IfModule mod_fastcgi.c>
    ScriptAlias /cgi-bin/ "/home/{...}/www/fastcgi/"
    AddHandler php5-fcgi .php .php5 .php4
    Action php5-fcgi /cgi-bin/php5.fcgi
</IfModule>

这里,php5.fcgi是以下脚本:

#!/bin/bash
#
# php5.fcgi
# Shell Script to run PHP5 using mod_fastcgi under Apache 2.x
#
#USER=$(/usr/bin/whoami)
#PHPRC="/var/www/$USER/.cgi-bin/php.ini"
PHP_FCGI_CHILDREN=5
#PHP_FCGI_MAX_REQUESTS=1000
#export PHPRC
export PHP_FCGI_CHILDREN
#export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php5-cgi

虚拟主机配置:

<VirtualHost *:6308>
    ServerName mina.loc
    DocumentRoot /home/{...}/www/mina/web
    FastCgiExternalServer /home/{...}/www/fastcgi/php5.fcgi -socket /var/run/php5-fpm.sock
    <Directory />
        Options FollowSymLinks 
        AllowOverride All
    </Directory>
    <Directory /home/{...}/www/mina/web>
        Options FollowSymlinks  
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel debug 
    LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %T/%D" extended
    CustomLog /var/log/apache2/mina_access.log extended
    # Enable output compression for all text/html files
    AddOutputFilterByType DEFLATE text/html text/plain
</VirtualHost>

最新更新