首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的Apache配置有什么问题?

问我的Apache配置有什么问题?
EN

Server Fault用户
提问于 2013-06-18 20:15:27
回答 1查看 662关注 0票数 0

我正在运行一个AWS设置,该设置目前由指向单个EC2实例的ELB组成。该实例正在运行Ubuntu12.04.2和Apache2.22.2。过去,我在服务器上设置了几个子域。我今天想再做一次,但我想弄清楚我错过了什么。我敢肯定这是我忽略或不太正确的一小步。

我的DNS记录是使用53路建立的。我登录到AWS控制台并为我的服务器添加了一个新的CNAME记录。我们叫它samael.example.com。看起来是这样的:

代码语言:javascript
复制
samael.example.com. 3600    IN  CNAME   web-pool-xxxxxxxxxx.us-east-1.elb.amazonaws.com.

这似乎很好,因为我的浏览器指向sameael.example.com会弹出默认的VirtualHost。

所以,我现在要做的就是创建另一个VirtualHost配置文件,对吗?

代码语言:javascript
复制
mkdir /http/www/samael.example.com
touch /httpd/www/samael.example.com/index.html
cd /etc/apache2/sites-available
sudo cp dav.example.com samael.example.com
sudo sed -i 's/dav.example.com/samael.example.com/g' samael.example.com
cd ../sites-enabled
sudo ln -s ../sites-available/samael.example.com
sudo apachectl restart

应该是这样吧?但是当我将浏览器指向samael.example.com时,它仍然指向默认的VirtualHost。我跳到哪一步了?

cat samael.example.com

代码语言:javascript
复制
<VirtualHost *:80>
    ServerName samael.example.com
    ServerAdmin webmaster@localhost

    DocumentRoot /httpd/www/samael.example.com
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /httpd/www/samael.example.com>
            Options FollowSymLinks
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ErrorLog /var/log/apache2/samael.example.com-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/samael.example.com-access.log combined

编辑:

根据评论中的请求:

代码语言:javascript
复制
sudo apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server dav.example.com (/etc/apache2/sites-enabled/dav.example.com:1)
         port 80 namevhost dav.example.com (/etc/apache2/sites-enabled/dav.example.com:1)
         port 80 namevhost dev.example.com (/etc/apache2/sites-enabled/dev.example.com:1)
         port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com:1)
         port 80 namevhost new.example.com (/etc/apache2/sites-enabled/new.example.com:1)
         port 80 namevhost samael.example.com (/etc/apache2/sites-enabled/samael.example.com:1)
         port 80 namevhost stage.example.com (/etc/apache2/sites-enabled/stage.example.com:1)
         port 80 namevhost test.example.com (/etc/apache2/sites-enabled/test.example.com:1)
Syntax OK

这件事的结果让我有点困惑。我希望默认的是example.com,而不是dav.example.com。example.com的配置文件中定义了ServerAlias *。

EN

回答 1

Server Fault用户

回答已采纳

发布于 2013-06-18 20:28:14

您的vhost配置文件可能没有被apache看到,可能是因为缺少include指令,也可能是因为缺乏权限。

确保在主配置文件中有一个指令,如

代码语言:javascript
复制
Include /etc/apache2/sites-enabled/*

如果它位于条件块(如<IfDefine VHOSTS> )中,请确保条件正在计算为true (例如。通过确保指定正确的定义或加载正确的模块)。

此外,确保无论哪个用户apache正在运行,因为(通常是apache)具有读取文件和枚举启用站点目录的权限。具体来说,它需要在启用站点的目录上读取和执行,并对站点中的所有配置文件进行读取。

根据您的编辑,您拥有的ServerAlias *指令很可能是令人困惑的事情。这不是指定默认vhost的方法。默认的vhost具有基于名称的虚拟主机,仅在没有其他虚拟主机匹配(ServerAlias或ServerName)时才使用,并且只是按字母顺序加载的第一个虚拟主机。这是最有可能选择dav.example.com主机的方式。为了克服这一问题,通常需要指定的虚拟主机配置文件名为00_default_vhost.conf。

匹配也是在顺序文件中进行读取的。因此,任何不是dav.example.com或dev.example.com的站点都将由example.com与通配符别名匹配。

票数 2
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/516752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档