0

我正在运行 ubuntu 12.04 的服务器中设置网页。

我已经停用了默认站点( a2dissite default default-ssl ),并且我创建了一个新站点,我需要启动并工作的站点将是一个子域。

想象一下我有 foo.com。我的目标是 foo.com 抛出 403 http 错误,而 sub.foo.com 呈现我需要的网页。我的虚拟主机看起来像这样:

foo.com(默认)

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName foo.com

    DocumentRoot /var/www/default
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/default/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

sub.foo.com

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName sub.foo.com

    DocumentRoot /var/www/sub
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/sub/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

当我访问 sub.foo.com 时,会显示该页面。当我访问 foo.com 时,显示相同的页面(:S),我需要 403 在这里...

我究竟做错了什么?

4

1 回答 1

0

您是否在 Apache 配置中启用了 NamedVirtualHosts?Apache 重新启动时是否会给您任何警告?所有网站都启用了吗?

他们配置了不同的 DocumentRoots,所以我猜你在两个路径中都有相同的文件,或者实际上两个请求都由同一个 vhost 配置提供服务。在foo.com的配置中,我将首先更改Allow from allDeny from all

<Directory /var/www/default/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Deny from all
</Directory>

...您有更大的机会受到 403 的欢迎;)

于 2013-11-19T13:05:34.000 回答