Jump to content

[SOLVED] multiple domains on single ip - subdomain problem


jncR09

Recommended Posts

hi

 

i got a linux-vserver with one ip running apache2 with 3 domains as virtualhosts

almost everything works fine.

the dns redirects all subdomains to the IP.

 

the problem.

subdomains which not exists as virtualhost show up the frontpage of one domain. (xyz.domain2.com shows the same as www.domain1.com)

 

how can I redirect all not existing subdomains of domain1.com to www.domain1.com, the same for domain2 and domain3?

 

The same for SSL

I host one site with a SSL certificate mail.domain1.com, when I open https://www.domain3.com/ its the same as mail.domain1.com just with a certificate error.

How can I redirect them to http://www.domain3.com without creating a virtualhost for every subdomain!

Link to comment
Share on other sites

<VirtualHost www.domain1.com:80 www.domain2.com:80>
        ServerAdmin info@***
        ServerAlias www.doman1.com
        DocumentRoot /var/www/****/htdocs

       # some php and log configs
</VirtualHost>

<VirtualHost abc.domain1.com:80>
        ServerAdmin info@******
        ServerAlias abc.domain1.com
        DocumentRoot /var/www/***/subdomains/abc/htdocs/
</VirtualHost>

<VirtualHost we.domain1.com:80>
        ServerAdmin webmaster@localhost
        ServerAlias we.domain1.com
        DocumentRoot /var/www/****/subdomains/we/htdocs/
        #some php configs
</VirtualHost>

<VirtualHost domain1.com:80>
        RewriteEngine   on
        RewriteRule ^(.*) http://www.domain1.com$1 [R=301]
</VirtualHost>

<VirtualHost domain2.com:80>
        RewriteEngine   on
        RewriteRule ^(.*) http://www.domain2.com$1 [R=301]
</VirtualHost>

other file for ssl

<VirtualHost mail.domain1.com:443>
        ServerAdmin info@******
        ServerAlias mail.domain1.com
        DocumentRoot /var/www/roundcube/
        #some php configs

        #SSL
        SSLEngine On
        SSLCipherSuite HIGH:MEDIUM
        SSLCertificateFile    /etc/apache2/ssl/mail.*****.crt
        SSLCertificateKeyFile /etc/apache2/ssl/mail.****.key
</VirtualHost>
<VirtualHost mail.domain1.com:80 mail.domain2.com:80>
        RewriteEngine   on
        RewriteRule ^(.*) https://mail.domain1.com$1
</VirtualHost>

and domain3 file

<VirtualHost www.domain3.com:80>
        ServerAdmin info@******
        ServerAlias www.domain3.com
        DocumentRoot /var/www/******/htdocs
        # some php and log configs
</VirtualHost>

<VirtualHost mail.domain3.com:80>
        ServerAdmin info@*******
        ServerAlias mail.domain3.com
        DocumentRoot /var/www/roundcube/
        #... some php configs
</VirtualHost>

replaced some stuff with ****

Link to comment
Share on other sites

"subdomains which not exists as virtualhost show up the frontpage of one domain. (xyz.domain2.com shows the same as www.domain1.com)"

 

It looks like you need to setup a default VirtualHost.

 

 

The very first virtual host that you set will be the default one.  If no other virtual hosts match, the first one will be used.  So, just set one up for the IP or something.

 

 

"how can I redirect all not existing subdomains of domain1.com to www.domain1.com, the same for domain2 and domain3?"

 

Hrmmmm......  I'm sure that's possible, but I don't know how.  Is it possible to use wildcards in VirtualHosts?  If so, you could set a wildcard virtual host as the first one for a subdomain, and then set the individual subdomains.

 

 

Something like:

 

<VirtualHost *.domain1.com>

</VirtualHost>

 

<VirtualHost something.domain1.com>

</VirtualHost>

 

Then do the same for the other subdomains.  No idea if it's valid or not though.

 

 

 

"I host one site with a SSL certificate mail.domain1.com, when I open https://www.domain3.com/ its the same as mail.domain1.com just with a certificate error."

 

I have no idea why SSL is enabled in all of the VirtualHosts and not just the one you specified.  Are you sure that's the only SSLEngine On statement in the file?

 

Link to comment
Share on other sites

"The very first virtual host that you set will be the default one.  If no other virtual hosts match, the first one will be used.  So, just set one up for the IP or something."

 

the problem is i got 3 domains how can i set a default one to every single domain?

 

 

"Hrmmmm......  I'm sure that's possible, but I don't know how.  Is it possible to use wildcards in VirtualHosts?  If so, you could set a wildcard virtual host as the first one for a subdomain, and then set the individual subdomains."

 

Thats not possible, how should apache resolve the hostname *.domain.com??

correct me if im wrong!

 

"I have no idea why SSL is enabled in all of the VirtualHosts and not just the one you specified.  Are you sure that's the only SSLEngine On statement in the file?"

 

Yes, it is. because apache doesnt find another vhost which is bind to port 443 he use this one, and because the domain doesnt match the browser gives a domain mismatch error.

Link to comment
Share on other sites

"the problem is i got 3 domains how can i set a default one to every single domain?"

 

 

That's where my second thing came into play with the *.domain.com.

 

 

"Thats not possible, how should apache resolve the hostname *.domain.com??

correct me if im wrong!"

 

 

Uhhh.... Apache doesn't resolve domain names.  Webserver != nameserver.

 

But I still don't know if *.domain.com is valid syntax.  I shall google in a second.

Link to comment
Share on other sites

Got it,

<VirtualHost domain1.com:80>
        ServerAlias *.domain1.com
        RewriteEngine on
        RewriteRule ^(.*) http://www.domain1.com$1 [R=301]
</VirtualHost>

(for every domain)

 

works fine

 

i tried "<VirtualHost *.domain1.com:80>" before, that was the problem ;)

 

but it wont work for the ssl one,

NameVirtualHost ****Server'sIP****:443
<VirtualHost mail.domain1.com:443>
        ServerAdmin info@domain1.com
        ServerAlias mail.domain1.com
        DocumentRoot /var/www/roundcube/

        <Directory "/var/www/roundcube">
                Order deny,allow
                allow from all
        </Directory>

        #PHP config (stripped)

        #SSL (stripped)
</VirtualHost>

<VirtualHost mail.domain1.com:80 mail.domain2.com:80>
        RewriteEngine on
        RewriteRule ^(.*) https://mail.domain1.com$1 [R=301]
</VirtualHost>

<VirtualHost domain1.com:443>
        ServerAlias *.domain1.com
        RewriteEngine on
        RewriteRule ^(.*) http://www.domain1.com$1 [R=301]
</VirtualHost>

i dont understand why it works fine for port 80 but not for port 443 :P

 

apache2 gives no error while starting...

Link to comment
Share on other sites

With ssl you need to use the IP. Also, you should note that only one ssl per IP will work with apache. There is a work-around for that but it isn't supported by all browsers.

 

I recommend that you do something like:

 

NameVirtualHost 123.12.12.1:80
NameVirtualHost 123.12.12.1:443
<VirtualHost 123.12.12.1:443>
        ServerAdmin info@domain1.com
        ServerName  mail.domain1.com
        DocumentRoot /var/www/roundcube/

        <Directory "/var/www/roundcube">
                Order deny,allow
                allow from all
        </Directory>

        #PHP config (stripped)

        #SSL (stripped)
</VirtualHost>

 

Instead of using name based virtual hosting I would recommend IP based like in the example above.

 

how can I redirect all not existing subdomains of domain1.com to www.domain1.com, the same for domain2 and domain3?

You could do a simple rewrite but imho that isn't really needed. In your main vhost for each domain add the following. All requests to any subdomain that doesn't have it's own vhost will be ran through that main vhost.

ServerAlias *.domain.tld

Link to comment
Share on other sites

Is it possible that the host name wont be passed until the session is encrypted?

because after I add an expection for the cert i gonna be redirected to the host i want.

it works fine :D

 

I think I create a multi domain certificate and enable ssl for all. That would be the best for every domain.

 

thanks for the help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.