1

我按照Falco 的教程进行操作,现在对于 2 个用户(例如 john 和 alice)及其相关目录(/var/www/john/var/ww/alice),一切都按预期工作。

现在,我想更上一层楼:我需要动态配置大量虚拟主机/etc/apache2/sites-available/<username>,而不是在Apache 上定义不同的虚拟主机并重新启动。比如说,我的 DNS 服务器有以下记录:,我希望它的主目录位于.another.site.example.com/var/www/another.site/web

问题在于 suexec 和 mod_fcgid 的所有这些配置设置。我结束了我的这份草稿httpd.conf(或者我应该创建一个类似的文件/etc/apache2/sites-available/mass_virtual?):

NameVirtualHost *:80

#default virtual host
<VirtualHost *:80>
  ServerName www.example.com
  ServerAlias example.com
  ServerAdmin webmaster@example.com
  DocumentRoot /var/www/root/web/

  <IfModule mod_fcgid.c>
    SuexecUserGroup web-admin web-admin
    <Directory /var/www/root/web/>
      Options +ExecCGI
      Options -Indexes
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/root/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    </Directory>
  </IfModule>

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off

</VirtualHost>

#3rd-level subdomain virtual hosts
<VirtualHost *:80>
  UseCanonicalName Off
  ServerAlias *.example.com
  #problematic email!
  ServerAdmin webmaster@example.com
  #is this /var/www/another.site/web or /var/www/www.another.site/web for
  #a request for www.another.site.example.com ?
  VirtualDocumentRoot /var/www/%-3+/web

  <IfModule mod_fcgid.c>
    #problematic group and user!
    SuexecUserGroup web1 web1
    <Directory /var/www/*/web/>
      Options +ExecCGI
      Options -Indexes
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/*/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    </Directory>
  </IfModule>

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off

</VirtualHost>
  1. 正如您从评论中看到的那样,我有一个有问题ServerAdmin webmaster@example.com的,一个SuexecUserGroup web1 web1和一个VirtualDocumentRoot /var/www/%-3+/web配置!

  2. 此外,为了确保安全,我认为IfModule不应该存在——如果 mod_fcgid无法加载,那么服务器也不应该存在,

  3. 而不是Alow from all,我想我应该Deny from all打开一个 php-library 目录!

谢谢。

4

1 回答 1

0

好的,因为我没有回复,我将尝试我提出的解决方案的一半(?):使用 mod_userdir 强制执行 suexec

  1. 让我们创建以下 /etc/apache2/httpd.conf

    ##########################################
    ### mod_fcgid configuration directives ###
    ##########################################
    #values should be tuned depending on server memory
    FcgidMaxProcesses 1000
    FcgidMaxProcessesPerClass 100
    FcgidMinProcessesPerClass 3
    #see 'export PHP_FCGI_MAX_REQUESTS=5000' at '/var/www/php-fcgi-scripts/<user>/php-fcgi-starter'
    FcgidMaxRequestsPerProcess 5000
    FcgidIOTimeout 40
    FcgidProcessLifeTime 3600
    FcgidMaxRequestInMem 65536
    FcgidMaxRequestLen 131072
    FcgidOutputBufferSize 65536
    
  2. 让我们创建一个mass_virtualat/etc/apache2/sites-available/

    #NameVirtualHost *:80
    
    #default virtual host
    <VirtualHost *:80>
      ServerName www.example.com
      ServerAlias example.com
      ServerAdmin webmaster@example.com
      DocumentRoot /var/www/web-admin/web/
    
      SuexecUserGroup web-admin web-admin
      <Directory /var/www/web-admin/web/>
        Options +ExecCGI
        Options -Indexes
        AllowOverride All
        AddHandler fcgid-script .php
        #FCGIWrapper /var/www/php-fcgi-scripts/web-admin/php-fcgi-starter .php
        FcgidWrapper /var/www/php-fcgi-scripts/web-admin/php-fcgi-starter .php
        Order allow,deny
        Allow from all
      </Directory>
    
      # ErrorLog /var/log/apache2/error.log
      # CustomLog /var/log/apache2/access.log combined
      ServerSignature Off
    
    </VirtualHost>
    
    #3rd-level subdomain virtual hosts
    <VirtualHost *:80>
      ServerAlias *.example.com
      ServerAdmin webmaster@example.com
      ##################
      ### solution 1 ###
      ##################
      #mod_vhost_alias directives: needs parameterized SuexecUserGroup(?)
      #UseCanonicalName Off
      #VirtualDocumentRoot /var/www/%-3+/web
      ##################
      ### solution 2 ###
      ##################
      #mod_userdir directives for requests: http://www.example.com/~user
      UserDir disabled root
      UserDir /var/www/*/public_html
    
      #reduntant if using requests: http://www.example.com/~user
      #SuexecUserGroup web1 web1
      <Directory /var/www/*/public_html>
        Options +ExecCGI
        Options -Indexes
        AllowOverride All
        AddHandler fcgid-script .php
        #move to .htaccess
        #FCGIWrapper /var/www/php-fcgi-scripts/*/php-fcgi-starter .php
        #FcgidWrapper /var/www/php-fcgi-scripts/*/php-fcgi-starter .php
        Order allow,deny
        Allow from all
      </Directory>
    
      # ErrorLog /var/log/apache2/error.log
      # CustomLog /var/log/apache2/access.log combined
      ServerSignature Off
    
    </VirtualHost>
    

    问题:如果我取消注释第一行,我会在服务器重新启动时收到一条警告,指出没有虚拟主机!!

  3. 让我们创建我的用户 bob

  4. 让我们创建一个 .htaccess 在/var/www/bob/public_html

    FcgidWrapper /var/www/php-fcgi-scripts/bob/php-fcgi-starter .php
    
  5. 让我们点击我的浏览器www.example.com/info.phpexample.com/info.php

    web-admin
    

    ...正如预期的那样,但是,

  6. 让我们搬到www.example.com/~bob/info.php

    ...trying to open info.php!!!
    

    让我们看看错误

    <root># cat /var/log/apache2/error.log
    [notice] caught SIGTERM, shutting down
    [notice] suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
    [notice] Apache/2.2.20 (Ubuntu) mod_fcgid/2.3.6 configured -- resuming normal operations
    

    如您所见,没有错误但未mod_fcgid启用运行 .php 文件,并且 apache 尝试将其作为普通文件发送!!!任何想法如何解决这个问题?

于 2012-09-02T08:15:00.143 回答