LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   apache virtualhosts. can contact on any subdomains. (http://www.linuxquestions.org/questions/linux-server-73/apache-virtualhosts-can-contact-on-any-subdomains-4175448552/)

sliddjur 02-04-2013 09:11 AM

apache virtualhosts. can contact on any subdomains.
 
Hello, I have a hard time understanding this virtual host problem. I want an empty subdomain to go to /var/www/www. www as subdomain to the same. www2 subdomain to the /var/www/www2 folder only on port 80 and admin subdomain only on port 88 to /var/www/admin.
Now it happens that I have a couple of more hosts in my DNS. So I can contact eg. mail.student481.linuxkurs.tfe.umu.se:88 to go to the adminpage, or smtp.student481.linuxkurs.tfe.umu.se:80 goes to the /var/www/www folder. Thats not what I want.
Can someone help me out a little?

Code:

root@student481:/etc/apache2/sites-available# cat www
<VirtualHost *:80>
  DocumentRoot /var/www/www
  ServerName student481.linuxkurs.tfe.umu.se
  ServerAlias www.student481.linuxkurs.tfe.umu.se
</VirtualHost>

root@student481:/etc/apache2/sites-available# cat www2
<VirtualHost *:80>
  DocumentRoot /var/www/www2
  ServerName www2.student481.linuxkurs.tfe.umu.se
  ServerAlias www2.student481.linuxkurs.tfe.umu.se
</VirtualHost>

root@student481:/etc/apache2/sites-available# cat admin
<VirtualHost *:88>
        ServerName admin.student481.linuxkurs.tfe.umu.se
        ServerAlias admin.student481.linuxkurs.tfe.umu.se
        DocumentRoot /var/www/admin
        DirectoryIndex index.html
        <Directory /var/www/admin/>
                AllowOverride AuthConfig
        </Directory>
</VirtualHost>

Code:

#cat ports.conf
NameVirtualHost *:80
Listen 80
NameVirtualHost *:88
Listen 88


acid_kewpie 02-04-2013 10:11 AM

the first virtualhost is used when no other defined virtual host on a given port matches the hostname. So just put in a default catch-all host definition before the ones you want to have to have the exact correct name, just make it redirect somewhere else or something.

sliddjur 02-08-2013 03:39 AM

Quote:

Originally Posted by acid_kewpie (Post 4884145)
the first virtualhost is used when no other defined virtual host on a given port matches the hostname. So just put in a default catch-all host definition before the ones you want to have to have the exact correct name, just make it redirect somewhere else or something.

Im not sure if I understand, could you show me an example?

acid_kewpie 02-08-2013 03:48 AM

Code:

root@student481:/etc/apache2/sites-available# cat www
<VirtualHost *:80>
  DocumentRoot /var/www/www
  ServerName student481.linuxkurs.tfe.umu.se
  ServerAlias www.student481.linuxkurs.tfe.umu.se
</VirtualHost>

root@student481:/etc/apache2/sites-available# cat www2
<VirtualHost *:80>
  DocumentRoot /var/www/www2
  ServerName www2.student481.linuxkurs.tfe.umu.se
  ServerAlias www2.student481.linuxkurs.tfe.umu.se
</VirtualHost>

Well when you make a request for a a domain that isn't defined, the www server should be served, as the filenames are alphabetically returned and proecessed. so if you put in a "default" file with a dummy host in, "default" will be loaded sooner as d is earlier in the alphabet than w, and so will be used as a default.


All times are GMT -5. The time now is 08:01 PM.