LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-28-2007, 01:04 PM   #1
70mas
Member
 
Registered: Sep 2006
Location: Slovakia
Distribution: Debian, Gentoo
Posts: 34

Rep: Reputation: 15
Advanced Apache virtual hosts


Hi

I would like to set up some difficult apache virtual hosts, but i have not enough skills for doing that:

1. The www. should be ignored in all cases.
2. 2nd level domains (i.e. domain.com) should be looked for in /www/domain.com/
3. 3rd level domains (i.e. example.domain.com) should be looked in /www/domain.com/.sub/example(of course according to 1. it would not apply to www.domain.com)
4. If the directories don't exist, look for other <VirtualHosts>-s
5. If no virtual hosts match the host, go to the default documentroot

As you can see, the highest priority should have the <VirtualHost> with the virtualdocumentroot, and then the other <VirtualHost>-s and then the default DocumentRoot

Could you help me please?

Thanks in advance.
 
Old 01-29-2007, 06:34 AM   #2
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
I think you are looking for something like this:

Code:
<VirtualHost 1.2.3.4>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /www/domain.com
</VirtualHost>

<VirtualHost 1.2.3.4>
ServerName example.domain.com
ServerAlias www.example.domain.com
DocumentRoot /www/domain.com/.sub/example
</VirtualHost>

<VirtualHost 1.2.3.4>
ServerAlias *.domain.com
DocumentRoot /www/domain.com/.sub/default
</VirtualHost>
The only thing I was unclear about was exactly what "the www. should be ignored" meant. I assumed you meant that whether or not it was typed, the user goes to the same place, i.e., www.domain.com = domain.com, www.example.domain.com = example.domain.com. If that is not the case, and you want www.example.domain.com to equal non-existent-subdomain.domain.com and be caught by the default, then leave the ServerAlias directive out of all the vhost containers (except for the default one, of course).

Hope that helps.
 
Old 01-29-2007, 10:44 AM   #3
70mas
Member
 
Registered: Sep 2006
Location: Slovakia
Distribution: Debian, Gentoo
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks zaichik for your answer...

What I really had in mind is something like this...

Code:
NameVirtualHost *:80

ServerName srna.sk
ServerSignature On
ErrorLog /www/logs/error.log
LogLevel warn
CustomLog /www/logs/access.log combined

<VirtualHost *:80>
	ServerName srna.sk
	ServerAlias www.srna.sk
	ServerAdmin tomas@homelin.srna.sk
	DocumentRoot /www/htdocs/
</VirtualHost>

<VirtualHost *:80>
	ServerAlias *.*.srna.sk
	ServerAdmin tomas@homelin.srna.sk
	VirtualDocumentRoot /www/htdocs/%-3.0.%-2.0.%-1.0/.sub/%-4.0
</VirtualHost>

<VirtualHost *:80>
	ServerAlias *.srna.sk
	ServerAdmin tomas@homelin.srna.sk
	VirtualDocumentRoot /www/htdocs/%-3.0.%-2.0.%-1.0
</VirtualHost>
And to this, I would like to add something to omit www. at the beginning... For example now the address www.sth.srna.sk is now translated as /www/htdocs/sth.srna.sk/.sub/www, but i want it to be translated as /www/htdocs/sth.srna.sk On the other hand, addresses like web.sth.srna.sk should be translated as /www/htdocs/sth.srna.sk/.sub/web

Nothing complicated but to omit www. from the address of request.

Thanks.
 
  


Reply



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
vsftpd, web uploads, vsftpd virtual users, apache virtual hosts, home directories jerryasher Linux - Software 7 02-18-2007 06:29 AM
Apache Virtual Hosts ToothlessRebel Linux - Networking 6 10-06-2006 02:11 PM
APACHE - Virtual Hosts luca2 Linux - Networking 3 12-27-2005 07:32 PM
Apache Virtual Hosts (again) scatcat Linux - General 1 10-17-2002 09:51 AM
Apache: Virtual hosts pk21 Linux - Software 15 10-08-2002 05:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:20 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration