0

I'm setting up a webpage in a server that runs ubuntu 12.04.

I have deactivated the default sites ( a2dissite default default-ssl ) and I have created a new one, the one that I need up and working which would be a subdomain.

Imagine I have foo.com. My goal is that foo.com throws a 403 http error and sub.foo.com renders the web page I need. My virtual host look something like this:

foo.com (default)

<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>

When I access sub.foo.com the page is displayed. When I access foo.com, the same page is displayed (:S) and I need the 403 here...

What am I doing wrong?

ThisIsErico
  • 1,885
  • 2
  • 19
  • 24

1 Answers1

0

Have you enabled NamedVirtualHosts in your Apache config? Does Apache give you any warnings when restarted? Are all sites enabled?

They have different DocumentRoots configured, so I am guessing you have the same files in both paths or are actually having both requests served by the same vhost config. In the config for foo.com I would start by changing Allow from all to Deny from all:

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

...you have a much greater chance of being greeted with a 403 with that change ;)

bryn
  • 3,155
  • 1
  • 16
  • 15