【问题标题】:apache mass virtual hosting with suexec and mod_fcgid带有 suexec 和 mod_fcgid 的 apache 大规模虚拟主机
【发布时间】:2012-08-15 01:47:13
【问题描述】:

我关注了Falco's tutorial,现在对于 2 个用户(例如 john 和 alice)及其相关目录(/var/www/john/var/ww/alice),一切都按预期工作。

现在,我想更进一步:我需要dynamically configured mass virtual hosting,而不是在/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. 正如您从 cmets 中看到的,我有一个有问题的 ServerAdmin webmaster@example.comSuexecUserGroup web1 web1VirtualDocumentRoot /var/www/%-3+/web 配置!

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

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

谢谢。

【问题讨论】:

  • 正如我所说,我的意图是将 www.another.site.example.com 请求定向到 /var/www/another 的用户。 site/web 但正如我在“Using suEXEC”处的link 所读到的,我们可以在 VirtualHost 定义中不使用 SuexecUserGroup 指令但在 mod_userdir!那么,如果对 www.another.site.example.com 的请求在 www.example.com/~another.site 会怎样? >mod_rewrite 然后使用 mod_userdir 来启用 suexec???有什么想法或指令可以实现这一点?

标签: apache2 virtual-hosts mod-fcgid suexec


【解决方案1】:

好的,因为我没有回复,我将尝试我提出的解决方案的一半(?):使用 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. 让我们在/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/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. 让我们在/var/www/bob/public_html创建一个.htaccess

    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 尝试将其作为普通文件发送!!! 任何想法如何解决这个问题?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-31
  • 1970-01-01
  • 2015-04-09
  • 2014-12-24
  • 1970-01-01
  • 1970-01-01
  • 2016-02-11
相关资源
最近更新 更多