LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 02-04-2013, 08:11 AM   #1
sliddjur
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Rep: Reputation: Disabled
Question 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
 
Old 02-04-2013, 09:11 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
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.
 
Old 02-08-2013, 02:39 AM   #3
sliddjur
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by acid_kewpie View Post
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?
 
Old 02-08-2013, 02:48 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
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.
 
  


Reply

Tags
apache, port, subdomain, virtualhost


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Apache with VirtualHosts how to use lpallard Linux - Server 18 02-24-2013 08:51 PM
Apache and Virtualhosts slowness fireballsp Linux - Server 2 01-12-2013 10:22 AM
Apache Virtualhosts and subdomains arew264 Linux - Networking 1 01-03-2006 08:53 AM
VirtualHosts & apache 2.0.48 TiCkO Linux - Networking 2 07-13-2004 03:20 PM
Virtualhosts in apache. where am i going wrong. SSBN Linux - Networking 20 07-11-2003 04:02 AM


All times are GMT -5. The time now is 10:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration