jncR09 Posted February 7, 2009 Share Posted February 7, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/ Share on other sites More sharing options...
corbin Posted February 7, 2009 Share Posted February 7, 2009 What do your VirtualHost sections look like? Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-756916 Share on other sites More sharing options...
jncR09 Posted February 7, 2009 Author Share Posted February 7, 2009 <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 **** Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-756952 Share on other sites More sharing options...
corbin Posted February 7, 2009 Share Posted February 7, 2009 "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? Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-756966 Share on other sites More sharing options...
jncR09 Posted February 8, 2009 Author Share Posted February 8, 2009 "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. Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-757204 Share on other sites More sharing options...
corbin Posted February 8, 2009 Share Posted February 8, 2009 "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. Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-757305 Share on other sites More sharing options...
jncR09 Posted February 8, 2009 Author Share Posted February 8, 2009 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 apache2 gives no error while starting... Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-757446 Share on other sites More sharing options...
tomfmason Posted February 8, 2009 Share Posted February 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-757456 Share on other sites More sharing options...
jncR09 Posted February 8, 2009 Author Share Posted February 8, 2009 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 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 Quote Link to comment https://forums.phpfreaks.com/topic/144235-solved-multiple-domains-on-single-ip-subdomain-problem/#findComment-757552 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.