【问题标题】:DigitalOcean Apache 2 Debian 7 Virtual Host for subdomainDigitalOcean Apache 2 Debian 7 子域虚拟主机
【发布时间】:2013-12-14 16:40:10
【问题描述】:

我在 digitalocean.com 上有 VPS。对于 example.com 的 DNS,我添加了 cname 子域。

在 Debian 7 上使用 apache 2.2 和 php 5.5 服务器工作

我的子域配置有问题。我尝试了所有教程形式的前 4 个谷歌页面的“apache 子域配置”。

但在请求 subdomain.example.com 之后,响应仍然是 example.com 内容。

我用:

apachectl -t -D DUMP_VHOSTS

结果是:

    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Thu Nov 28 15:58:58 2013] [warn] VirtualHost xxx.xxx.xx.xxx:80 overlaps with VirtualHost xxx.xxx.xx.xxx:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Thu Nov 28 15:58:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
VirtualHost configuration:
xxx.xx.xxx.xxx:80     subdomain.example.com (/etc/apache2/sites-enabled/subdomain.example.com:1)
127.0.0.1:80           xxx.xxx.xx.xxx (/etc/apache2/sites-enabled/000-default:1)
xxx.xxx.xx.xxx:80      example.com (/etc/apache2/sites-enabled/example.com:1)

/etc/apache2/sites-available/example.com 我已启用站点的链接

<VirtualHost xxx.xxx.xx.xxx:80>
  ServerName  example.com
  ServerAdmin email@email.com
  DocumentRoot /var/www/example.com

  <Directory /var/www/example.com>
<IfModule sapi_apache2.c>
        php_admin_flag engine on
    </IfModule>
    <IfModule mod_php5.c>
        php_admin_flag engine on
    </IfModule>
    Options Includes FollowSymLinks MultiViews
    AllowOverride All
    DirectoryIndex index.php index.html index.html5
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  ErrorDocument 404 /404/

  SetOutputFilter DEFLATE
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|ico|png)$ \ no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</VirtualHost>

/etc/apache2/sotes-available/subdomain.example.com 我在启用站点中有链接

:80>
  ServerName  subdomain.example.com
  ServerAdmin mail@mail.com
  DocumentRoot /var/www/subdomain.example.com
 ServerAlias subdomain.example.com
  <Directory /var/www/subdomain.example.com>
<IfModule sapi_apache2.c>
        php_admin_flag engine on
    </IfModule>
    <IfModule mod_php5.c>
        php_admin_flag engine on
    </IfModule>
    Options Includes FollowSymLinks MultiViews
    AllowOverride All
    DirectoryIndex index.php index.html index.html5
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  ErrorDocument 404 /404/

  SetOutputFilter DEFLATE
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|ico|png)$ \ no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</VirtualHost>

我也尝试过使用 ServerAlias,/var/www 中的文件夹拥有 www-data 和 755 chmod。

提前感谢您的任何想法。

问候

【问题讨论】:

    标签: apache dns apache2 apache2.2


    【解决方案1】:

    正如您在第二个区块中看到的那样,您缺少这个:

    <VirtualHost xxx.xxx.xx.xxx:80>
    

    并且应该在开始时进行配置。您需要通过执行以下操作获得服务器的完全限定域名: 如果您使用 root 作为用户,那么: 纳米 /etc/hosts

    然后添加这个:

    127.0.0.1       localhost
    
    #Virtual Hosts 
    12.34.56.789    example.com
    

    然后保存并重新启动 Apache,就完成了。

    【讨论】:

      【解决方案2】:

      您所要做的就是将子域记录添加到您分配的域中。为此,请按照他们网站上的教程进行操作:How To Set Up and Test DNS Subdomains with DigitalOcean's DNS Panel

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-10
        • 1970-01-01
        • 2014-08-21
        • 2022-01-12
        • 2015-05-27
        • 2014-12-28
        • 2015-02-24
        • 2012-12-03
        相关资源
        最近更新 更多