apache + fastcgi + fpm为什么需要suexec?

时间:2012-09-07 17:44:21

标签: apache fastcgi php suexec

所以我有以下 WORKING 虚拟主机:

<VirtualHost 192.168.128.20:80> 
        ServerName euclid.domain.tld 

        #LogLevel debug 
        ErrorLog /var/www/euclid/logs/error_log 

        SuexecUserGroup fastcgi www_euclid 
        FastCgiExternalServer /var/www/euclid/htdocs/cgi-bin -socket /var/run/php-fpm/euclid.sock -user fastcgi -group www_euclid 
        AddHandler php-fastcgi .php 
        Action php-fastcgi /cgi-bin 
        Alias /cgi-bin /var/www/euclid/htdocs/cgi-bin 

        <Location /cgi-bin> 
                Order Deny,Allow 
                Deny from All 
                # Prevent accessing this path directly 
                Allow from env=REDIRECT_STATUS 

                Options +ExecCGI +FollowSymLInks +SymLinksIfOwnerMatch 
        </Location> 

        DocumentRoot /var/www/euclid/htdocs 
        <Directory /var/www/euclid/htdocs> 
                AllowOverride all 
                Order allow,deny 
                Allow from all 
        </Directory> 
</VirtualHost>

我似乎无法弄清楚为什么我需要使用-user fastcgi -group www_euclid标志来同时拥有SuexecUserGroup fastcgi www_euclid和FastCgiExternalServer。 FPM启用了池,每个池都在其自己的用户/组下运行。这工作正常,没问题。如果我删除SuexecUserGroup和/或-user fastcgi -group www_euclid参数,我得到以下错误,我不知道为什么。另外,fastcgi使用什么uid和gid来访问套接字文件?它肯定不是fastcgi:ww_euclid。

(13)Permission denied: FastCGI: failed to connect to server
"/var/www/euclid/htdocs/cgi-bin": connect() failed  FastCGI:
incomplete headers (0 bytes) received from server
"/var/www/euclid/htdocs/cgi-bin"

2 个答案:

答案 0 :(得分:1)

好的我相信我已经弄明白问题是什么了。简单的答案是; mod_fastcgi糟透了。它古老,没有维护,记录不完整。为什么它在查找如何运行php-fpm时不断出现是超出我的。保护自己头痛,不要使用它!

真正的解决方案很简单:

<VirtualHost 192.168.128.20:80> 
        ServerName euclid.domain.tld 

        #LogLevel debug 
        ErrorLog /var/www/euclid/logs/error_log 

        <IfDefine PROXY>
                #If you want to use mod_proxy (Probably the best option)
                ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://localhost:9000/var/www/euclid/htdocs/$1
        </IfDefine>

        <IfDefine FASTCGI_HANDLER>
                #If you want to use mod_fastcgi_handler (3rd party)
                AddHandler fcgi:/var/run/php-fpm-euclid.sock .php
        </IfDefine>


        DocumentRoot /var/www/euclid/htdocs 
        <Directory /var/www/euclid/htdocs> 
                AllowOverride all 
                Order allow,deny 
                Allow from all 
        </Directory> 
</VirtualHost>

答案 1 :(得分:1)

您是否偶然使用SELinux?我遇到了一个类似的问题,该问题是由SELinux安全策略引起的,该策略阻止Apache连接到Django的fastcgi套接字。运行setenforce Permissive允许它工作。

相关问题