LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-07-2012, 02:01 PM   #1
newbie67
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Rep: Reputation: Disabled
Virtual Host not working properly


Hi,
I am new to Linux/Apache.

I am trying to set up two virtual hosts. For this, I changed the file /etc/apache2/apache2.conf as follow:

......
#Include sites-enabled

<VirtualHost *:80>
DocumentRoot "/var/www"
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/applications/myapps"
ServerName myapps.myserver.com

<directory "/var/www/applications/myapps">
Allow from all
Options +Indexes
</directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/phpmyadmin"
ServerName phpmyadmin.myserver.com

<directory "/var/www/phpmyadmin">
Allow from all
Options +Indexes
</directory>
</VirtualHost>

Now, I can access phpmyadmin application by the URL http://phpmyadmin.myserver.com. However, I cannot access the myapps application by the URL http://myapps.myserver.com. If I do so, a default index.html placed at /var/www is shown. The actual index.html of myapps, can be accessed if I give the full URL like http://myapps.myserver.com/applicati...pps/index.html. What is the problem?

Earlier I put separate configuration files for phpmyadmin and myapps in /etc/apache2/sites-enabled. However, the same problem was seen there also.

Any help is appreciated.

Thanks in advance,
 
Old 03-07-2012, 04:31 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

What is the output of:
Code:
https -S
Have you cleaned your browser cache, before visiting the offending vhost?
 
Old 03-07-2012, 07:46 PM   #3
newbie67
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi,
Thanks for your mail. Yes, I cleared the browsing data and frequently clicked refresh icon, without any change.

The output of https -S is:
100 Capabilities
Version: 1.2
Pipeline: true
Send-Config:true

Hope this helps.

Best regards,
 
Old 03-08-2012, 12:23 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
No it didn't. Try:
Code:
apache2ctl -S
Since you didn't mention your distro, I guess it's debian or ubuntu, as they are the only distros that use sites-enabled for vhosts.
Also check if the name you gave to this vhost (myapps.myserver.com) and the name you have in /etc/hosts (or dns) are the same, or there is some hard to see typo.

Regards

Last edited by bathory; 03-08-2012 at 12:34 AM. Reason: Additional info
 
Old 03-08-2012, 01:11 AM   #5
newbie67
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi Bathroy,

Many thanks for your support.

The output of apache2ctl -S is something like
------------------------------
*:80 is a NameVirtualHost
default server myapps.myserver.com (/etc/apache2/apache2.conf:233)
port 80 namevhost myapps.myserver.com (/etc/apache2/apache2.conf:233)
port 80 namevhost myapps.myserver.com (/etc/apache2/apache2.conf:237)
port 80 namevhost phpmyadmin.myserver.com (/etc/apache2/apache2.conf:247)
------------------------------

This is copy-paste from the actual output, but I had to use "myapps" and "myserver" in this mail, as I am not allowed to mention the real application or server name in a public forum.

I am using ubuntu Linux. I am not the system administrator of this server and have not made any change myself in etc/hosts or any dns files.

The /etc/hosts, looks like the following (the machine name is rhine)

-------------------------------------------------------------------
127.0.0.1 localhost
127.0.1.1 rhine

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
---------------------------------------------------------------------

The dns was configured by the system administrator. I do not know which file I should look for. But in general the dns looks ok, as I can access the machine from internet by both myapps.myserver.com and phpmyadmin.myserver.com

Follwoing is the copy paste of the relevant section from /etc/apache2/apache2.conf (changing application and server name).

------------------------------------------------------------------------
# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
#Include sites-enabled/

#Virtualhosts
<VirtualHost *:80>
DocumentRoot /var/www
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/applications/myapps/htdocs"
ServerName myapps.myserver.com

<Directory "/var/www/applications/myapps/htdocs">
allow from all
Options +Indexes
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/phpmyadmin"
ServerName phpmyadmin.myserver.com

<Directory "/var/www/phpmyadmin">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
---------------------------------------------------------------------------------------

I guess the issue is Apache is treating myapps.myserver.com as the default server (as seen in apache2ctl -S), and accordingly showing the index.html from the default root /var/www. It is ignoring the DocumentRoot declaration of myapps.myserver.com in apache2.conf.

Thanks for your time,
 
Old 03-08-2012, 01:58 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
I guess the issue is Apache is treating myapps.myserver.com as the default server (as seen in apache2ctl -S), and accordingly showing the index.html from the default root /var/www. It is ignoring the DocumentRoot declaration of myapps.myserver.com in apache2.conf.
Nope. Apache is using the 1st vhost as the default. In your case, it's the one with docroot /var/www. You can give it a dummy ServerName (e.g. localhost), so when you're trying to access myapps.myserver.com it uses the correct vhost.
 
1 members found this post helpful.
Old 03-08-2012, 02:30 AM   #7
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

My working configuration is like this (I'm posting just relevant lines):
Code:
### Section 3: Virtual Hosts
NameVirtualHost *


#---------------------------------
#     www.example.net
#---------------------------------
<VirtualHost *>

ServerName www.example.net
ServerAlias  www.example.net example.net
ServerAdmin admin@example.net

DocumentRoot "/var/www/html/example.net/"

ScriptAlias /cgi-bin/ "/var/www/html/example.net/cgi-bin/"

ScriptAlias /mailman/ /usr/lib/mailman/cgi-bin/
<Directory /usr/lib/mailman/cgi-bin/>
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

<Directory "/var/www/html/example.net">
         Options            +Indexes FollowSymLinks
         IndexOptions       FancyIndexing NameWidth=* FoldersFirst
         AllowOverride      All
         Order              allow,deny
         Allow              from all
</Directory>
</VirtualHost>


# ---------------------------------------------- #
# PHP.example.NET
# ---------------------------------------------- #

<VirtualHost *>
ServerAdmin admin@example.net
ServerName php.example.net
ServerAlias php.example.net

DocumentRoot "/var/www/html/example.net/php/"
ScriptAlias /cgi-bin/ /var/www/html/example.net/cgi-bin/

<Directory "/var/www/html/example.net/php">
  Options -Indexes +FollowSymlinks
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

</VirtualHost>
I hope you could get the configuration to work.

good luck
 
Old 03-08-2012, 02:37 AM   #8
newbie67
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi Bathory,

Giving a dummy ServerName for the default 1st vhost solved the problem. Now myapps.myserver.com behaves properly.

Many thanks for your suggestion,
 
  


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
RHEL 5 apache name based virtual host not working smch1 Linux - Software 11 07-28-2011 09:33 AM
[SOLVED] Ping from Vmware host to Virtual Box host greatcyrus Linux - Virtualization and Cloud 7 03-09-2011 02:03 AM
debian lenny - all virtual hosts lead to first virtual host rantastic Linux - Server 2 04-21-2010 09:32 PM
[SOLVED] Apache2 - virtual host defaulting to default host slimjim Linux - Server 1 10-31-2009 01:47 AM
virtual users and virtual host need to stay at /home nephish Linux - Networking 3 01-14-2006 01:36 PM

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

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