1

I will start with describing what I want to achieve.

First of all I have one main domain which is xxx.pl, a domain has 4 subdomains 000.xxx.pl, 111.xxx.pl, 222.xxx.pl, 333.xxx.pl. Also I have another domain yyy.pl with its own subdomains (mostly the same). Of course it will be more domains, but its not the point.

Now what I need is any domain which doesn't have its vhost set up for http, will point /var/www/pl.xxx and the same with https. (so its the default site) which for now I have set up as (and similar for https):

sites-enabled/999-default

<VirtualHost *:80>
    ServerAdmin postmaster@xxx.pl
    DocumentRoot /var/www/vhosts/pl.xxx
    <Directory /var/www/vhosts/pl.xxx>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

So this file as far as I understand will be loaded as last so apache will go there if there was no more precise answer.

Then there is file for main domain (HTTP and HTTPS is the same except the keys etc.) which will be loaded before default site config.

sites-enabled/998-pl.xxx

<VirtualHost *:80>
    ServerAdmin postmaster@xxx.pl
    ServerName xxx.pl
    ServerAlias *.xxx.pl
    DocumentRoot /var/www/vhosts/pl.xxx
    <Directory /var/www/vhosts/pl.xxx>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

And now I need to specify 2 domains (only on https), on http they should use sites-enabled/998-pl.xxx config.

sites-enabled/997-pl.xxx.000

ServerAdmin postmaster@xxx.pl

    ServerName 000.xxx.pl
    ServerAlias 000.xxx.pl

    DocumentRoot /var/www/vhosts/pl.xxx.000

    <Directory /var/www/vhosts/pl.xxx.000>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

And all would be good except the other domain yyy.pl on the https use the same config as the 000.xxx.pl address. And what I need it to restrict only 000.xxx.pl to use this address. Not all other not assigned domains.

so https://yyy.pl | https://000.yyy.pl etc. should use default-ssl settings instead of 000.xxx.pl settings.

Please help me understand whats going on. Maybe I misunderstood the apache config usage.

Edit:

Generally the problem is partially solved, because it works. but there is one interesting thing about dependency /etc/hosts entry with the subdomain configuration.

l1em1on1
  • 57
  • 1
  • 7
  • You want "any domain which doesn't have its vhost set up for http, will point /var/www/pl.xxx" but in 999-default you have `DocumentRoot /var/www/default`. It seems something is wrong here... Please improve your answer so it is more clear. Try to disable all vhosts which are not important for solving this issue and then paste content of all configuration files from sites-enabled. – Mike Apr 23 '13 at 14:25
  • its just a typo, maybe Its not clear enough, so I will try to edit it. – l1em1on1 Apr 23 '13 at 14:31

1 Answers1

1

sites-enabled/999-default

[...]

So this file as far as I understand will be loaded as last so apache will go there if there was no more precise answer.

This works the other way around. So the site to be shown as default should be the first one Apache have to parse. I would name it 000-default or whatever which will go before the others.

Mike
  • 598
  • 7
  • 16
  • So I have to have something else wrong then, because if I moved default to be the first, my 000.xxx.pl domain is using a default setting then. – l1em1on1 Apr 23 '13 at 13:59
  • OK I found out that it didn't work because my subdomain (000.xxx.pl) was in /etc/hosts as **000.xxx.pl 000** if I removed it it works good. But will this affect my mail server? As I set up this address as **myhostname ** – l1em1on1 Apr 23 '13 at 14:27
  • well still your answer was correct, because apparently the default should be first. – l1em1on1 Apr 23 '13 at 14:46