0

所以我有以下工作虚拟主机:

<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"
4

2 回答 2

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>
于 2012-09-07T22:31:44.783 回答
1

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

于 2013-10-26T17:05:36.030 回答