LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 06-21-2009, 03:18 PM   #1
buee
Member
 
Registered: May 2009
Posts: 81

Rep: Reputation: 16
Unhappy Virtual Hosting Issue


So after many hours of wrestling with Virtual Hosting, I've managed to get one of my websites up using the virtual hosting file. I have 2 files (domain1.com & domain2.com) in /etc/apache2/sites-available/(file names). I also have them symbolically linked to /etc/apache2/sites-enabled/(file names). When I have domain1.com in sites enabled, and I browse to domain1.com, I get it. When both domain1.com and domain2.com in sites-enabled and I browse to domain1.com, I get domain2.com and cannot get to domain1.com in the browser. What am I missing?

There is one interesting piece of information that may bear on this config. The server is sitting behind a firewall with a private IP of 10.0.0.11. So I don't know if that works in to the equation or not.

/etc/apache2/sites-available/domain1.com
Code:
#
# domain1.com
#
<VirtualHost *>
  ServerName domain1.com
  ServerAlias www.domain1.com
  DocumentRoot /var/www/domain1
  CustomLog /var/www/logs/domain1.com-access.log combined
  ErrorLog /var/www/logs/domain1.com-error.log
</VirtualHost>
/etc/apache2/sites-available/domain2.com
Code:
#
# blog.domain2.com
#
<VirtualHost *>
  ServerName blog.domain2.com
  ServerAlias www.blog.domain2.com
  DocumentRoot /var/www/domain2
  CustomLog /var/www/logs/Blog.domain2.com-access.log combined
  ErrorLog /var/www/logs/Blog.domain2.com-error.log
</VirtualHost>
My brain is shot at the moment. Anyone have any insights?

I've got Ubuntu 8.04 i386 Server Edition and the newest version of Apache2. Not sure how to check the version number.
 
Old 06-22-2009, 11:57 PM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Sorry - you lost me with the bit about /etc/apache2, but then your document root is /var/www/domain1.

Can you explain what is where a bit more clearly?
 
Old 06-23-2009, 05:27 AM   #3
vap16oct1984
Member
 
Registered: Jun 2009
Location: INDIA
Distribution: RHEL-5
Posts: 174
Blog Entries: 3

Rep: Reputation: 38
Hey how u configuring virtal host.

you must go to the path
/etc/httpd/conf/httpd.conf
and do use the file
/var/www/dom*

And one more which version of linux are u using????
 
Old 06-23-2009, 05:56 AM   #4
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
billymayday:
/etc/apache2 is the apache server root
document root is usually
/var/www
with debian / ubuntu

vap16...:
the path /etc/httpd/... doesn't exist in ubuntu/debian.
That's more rather red-hat / fedora-ish

httpd.conf in /etc/apache2/ is usually empty, as the files are split up.

buee: Not sure if it's because it's missing, however in my vhost config I have at line 1 in file "default"
"NameVirtualHost *"
then followed by one <VirtualHost> block.
Other <Virtualhost> blocks are in separate files, however the default gets loaded first by being symlinked to
000-default, therefore NameVirtualHost being loaded first.

right now don't see anything wrong / missing otherwise which could cause it (unless teh DocRoot need a trailing slash, which all mine have)

Have you also tried with <directory> entries in virtualhost block?

Code:
    <Directory /doc_root/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
however can't say if that's vital / necessary for multiple vhosts.
 
Old 06-23-2009, 06:47 AM   #5
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
So are you saying that /etc/apache2/whatever is where the parts of the config are? That makes more sense then. Ta.
 
Old 06-23-2009, 06:59 AM   #6
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
aye, that it is.
Debian's /etc/apache2/ e.g. looks like this

Code:
-rw-r--r-- 1 root root  11K 2008-05-29 20:33 apache2.conf
-rw-r--r-- 1 root root 9.9K 2008-07-07 21:51 apache2.conf.dpkg-dist
drwxr-xr-x 2 root root 4.0K 2009-05-12 21:15 conf.d/
-rw-r--r-- 1 root root  462 2008-08-13 17:55 envvars
-rw-r--r-- 1 root root    0 2007-10-11 23:41 httpd.conf
drwxr-xr-x 2 root root  12K 2009-05-29 10:10 mods-available/
drwxr-xr-x 2 root root 4.0K 2009-06-10 14:37 mods-enabled/
-rw-r--r-- 1 root root  664 2009-06-16 23:36 ports.conf
-rw-r--r-- 1 root root  513 2008-12-03 09:22 ports.conf.dpkg-dist
drwxr-xr-x 2 root root 4.0K 2009-06-16 23:36 sites-available/
drwxr-xr-x 2 root root 4.0K 2009-06-16 23:35 sites-enabled/
 
Old 06-23-2009, 07:20 AM   #7
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Amazing how you only fee lcomfortable with what you are used to. But I digress.

So in this setup, where does the statement "NameVirtualHost *" or similar appear (I saw you mentioned it also), and what does
Quote:
I also have them symbolically linked to /etc/apache2/sites-enabled/(file names)
mean?
 
Old 06-23-2009, 07:31 AM   #8
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Rep: Reputation: Disabled
Does it make any sense if I say that DocumentRoot has been set but no DirectoryIndex?

@billy,

NameVirtualHost should go into sites-enabled/<file-name>
 
Old 06-23-2009, 07:54 AM   #9
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
billy:

debian's apache is broken up in a way that it'll include your vhosts through files which are in
/etc/apache2/sites-enabled

similar to red hat way, including files in
/etc/httpd/conf.d/

usually you will have all your sites in
/etc/apache2/sites-available
and those you want to have enabled,
you will symlink them in ../sites-enabled

in the same way modules are included, through all available in
/etc/apache2/mods-available
and symlink those you want to use in
../mods-enabled

Ports to listen to are in ports.conf, file dedicated to them only

and the file envvars contains the default environment variables for apache2ctl

all other settings are in apache2.conf


The first file in the /etc/apache2/sites-available is called default, and that's where the NameVirtualHost appeared.
 
Old 06-23-2009, 11:23 PM   #10
buee
Member
 
Registered: May 2009
Posts: 81

Original Poster
Rep: Reputation: 16
Wow, no hits and all of the sudden 8 in one day

Ok, so let's try to go down the list here:

Quote:
Sorry - you lost me with the bit about /etc/apache2, but then your document root is /var/www/domain1.

Can you explain what is where a bit more clearly?
Sure, I guess using different variables would be more efficient. The tutorial I was following said to create the file for the vhosts. That is stored in /etc/apach2/sites-available/vhost (vhost is the file). The contents of which are above. Then I have that symlinked to sites-enabled. Also, I have removed the symlink for 000-default. From what I understand, that won't be an issue. It's just going to pull all files from sites-enabled. The index.html files are in /var/www/(respective folders) so the html file for domain1 is /var/www/domain1/index.html. The html file(s) for domain2 is /var/www/domain2/index.html <---(This is supposed to be a wordpress blog). I hope that clears that up...probably not.

rsciw is correct in that the httpd.conf file is completely empty in my case. I'm running Ubuntu 8.04 server i386 with apache2. I tried this method as well with 0 success.

To rsciw: I have tried using the NameVirtualHost * directive but that seems to mess things up worse than they were before. I have not tried the directory directive yet, mainly because I have seen it in about 20% of the examples I've seen. I suppose I could throw that in and see if it does any good, I guess I was just searching for someone that could catch a 1 where there's supposed to be a 0 and slap me in to submission.

I think everyone else's questions were answered. I've also tried adding a number of different things in to serveralias such as *.domain2.com. But that is unsuccessful as well. If that Directory /doc_root will work, I'll give it a go. It can't get much worse.
 
Old 06-23-2009, 11:30 PM   #11
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
If you are trying to use name virtual hosts, then you need the NameVirtualHost directive as I recall.

I don't know how it's done under Debian (just in case you hadn't picked that one up), but I'd try a single file with both virtual hostst defined in it and the NameVirtualHost directive at the top. it may be the order in which the files a read by apache that is causing problems.
 
Old 06-23-2009, 11:33 PM   #12
buee
Member
 
Registered: May 2009
Posts: 81

Original Poster
Rep: Reputation: 16
Tried that

Quote:
Originally Posted by billymayday View Post
If you are trying to use name virtual hosts, then you need the NameVirtualHost directive as I recall.

I don't know how it's done under Debian (just in case you hadn't picked that one up), but I'd try a single file with both virtual hostst defined in it and the NameVirtualHost directive at the top. it may be the order in which the files a read by apache that is causing problems.
I have tried that, in fact, it may be in there now. And I did combine the VirtualHost directives in to one file. When doing that, since the box is on a firewall, do I need to put the public IP that points to it or the private? I would assume the public. One other concern I have is, do I need to forward additional ports to the box? Right now I only have 80 but was wondering if possibly 53 is necessary as well for some reason since the requests are handled differently by DNS.
 
Old 06-23-2009, 11:46 PM   #13
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
I would simply use

NameVirtualHost *

and then

<VirtualHost *>
etc.

You only need to forward port 80 (and 443 if you want https)
 
Old 06-24-2009, 12:51 PM   #14
buee
Member
 
Registered: May 2009
Posts: 81

Original Poster
Rep: Reputation: 16
No go

Quote:
Originally Posted by rsciw View Post
billymayday:
/etc/apache2 is the apache server root
document root is usually
/var/www
with debian / ubuntu

vap16...:
the path /etc/httpd/... doesn't exist in ubuntu/debian.
That's more rather red-hat / fedora-ish

httpd.conf in /etc/apache2/ is usually empty, as the files are split up.

buee: Not sure if it's because it's missing, however in my vhost config I have at line 1 in file "default"
"NameVirtualHost *"
then followed by one <VirtualHost> block.
Other <Virtualhost> blocks are in separate files, however the default gets loaded first by being symlinked to
000-default, therefore NameVirtualHost being loaded first.

right now don't see anything wrong / missing otherwise which could cause it (unless teh DocRoot need a trailing slash, which all mine have)

Have you also tried with <directory> entries in virtualhost block?

Code:
    <Directory /doc_root/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
however can't say if that's vital / necessary for multiple vhosts.
I tried this just now and when trying to access domain1.com, I get an apache error that the URL / was not found on the server. I then tried domain2 and it pulled up but with horrible formatting and didn't look normal (it's supposed to be a wordpress site), which may be attributed to the fact that it's a PHP page and not .html. Not sure, but I can tackle that one later. This is with the following file symlinked in sites-enabled:

Code:
NameVirtualHost *

#
# domain1.com
#
<VirtualHost *>
  ServerName domain1.com
  ServerAlias www.domain1.com
  <Directory /var/www/domain1/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
  </Directory>
  CustomLog /var/www/logs/domain1.com-access.log combined
  ErrorLog /var/www/logs/domain1.com-error.log
</VirtualHost>
#
# blog.domain2.com
#
<VirtualHost *>
  ServerName blog.domain2.com
  ServerAlias www.blog.domain2.com *.domain2.com
  DocumentRoot /var/www/blog
  <Directory /var/www/blog/ >
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
  </Directory>
  CustomLog /var/www/logs/Blog.domain2.com-access.log combined
  ErrorLog /var/www/logs/Blog.domain2.com-error.log
</VirtualHost>
Then I thought, maybe if I through the index.html and index.php at the end of those Directory directives, it might shake something lose. But it yielded the exact same results.
 
Old 06-24-2009, 03:52 PM   #15
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Now is the time to look at the logs, and what happens when the url for domain1 isn't found
 
  


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
do I really need virtual hosting if only hosting one site kustomjs Linux - Server 8 05-22-2008 12:17 PM
Virtual Hosting utw-mephisto Linux - Server 3 09-10-2007 12:08 PM
Virtual Hosting bstuart Linux - Software 1 06-19-2005 11:26 AM
virtual hosting setenv02 Linux - General 6 05-05-2005 02:35 AM
Virtual Hosting - what does it actually do? gevers1 Linux - General 3 02-01-2004 09:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:53 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