Solved

Vhost configuration

Posted on 2006-07-15
10
765 Views
Last Modified: 2008-03-06
Hi,

I have configured a virtual host on my apache 2 web server, but the are pointing to the same site.
I have created two folders under www, i.e. htdocs & demo.
Under vhost.d i have 2 config files
default_vhost.conf
demo_vhost.conf

Default_vhost.conf have the following enteires
<VirtualHost *:80>
    ServerAdmin webmaster@mywebserver.com
    ServerName www.mywebserve.com
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    DocumentRoot /srv/www/htdocs
    # if not specified, the global error log is used
    ErrorLog /var/log/apache2/error_log
    CustomLog /var/log/apache2/access_log combined
    # Include /etc/apache2/conf.d/*.conf
    <Directory "/srv/www/htdocs">
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

and Demo has the following :
<VirtualHost demo.mywebserver.com:80>
    ServerAdmin webmaster@mywebserver.com
    ServerName demo.mywebserver.com
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    DocumentRoot /srv/www/demo
    # if not specified, the global error log is used
    ErrorLog /var/log/apache2/demo.mywebservert.com_error_log
    CustomLog /var/log/apache2/demo.mywebserver.com_access_log combined
    # Include /etc/apache2/conf.d/*.conf
    <Directory "/srv/www/demo">
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Please help me resolve this problem.

Thank You.
0
Comment
Question by:Wrathyimp
10 Comments
 
LVL 24

Expert Comment

by:slyong
ID: 17115648
Hi,

Sorry, what's the problem?
0
 
LVL 7

Expert Comment

by:CraigHarris
ID: 17117860
<VirtualHost *:80>
<VirtualHost demo.mywebserver.com:80>

Are those differences intentional? - do you have appropriate DNS entries for such?
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 17118540
Refer here:

http://httpd.apache.org/docs/2.0/vhosts/name-based.html

The one possibility I see is no NameVirtualHost declaration.  This directive is not optional for name-based virtual hosts.  You need one of these directives for every distinct point of contact.

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName www.mywebserve.com
# ... other stuff
</VirtualHost>

<VirtualHost *:80>
  ServerName demo.mywebserver.com
# ... other stuff
</VirtualHost>

Also keep in mind that the first listed vhost entry for any particular NameVirtualHost becomes the default...if a ServerName/ServerAlias cannot be matched in your vhost containers, the first vhost will be used.
0
 
LVL 1

Author Comment

by:Wrathyimp
ID: 17148079
Sorry to come so late.

But routinet, I tried to change the NameVirtualHost to *:80 on both the vhost.cong files, but to success, only pointing to the www.mywebserver.com, even when i type demo.mywebserver.com, it takes me to www.mywebserver.com
So is there something to do with httpd.conf?

Thank You.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:Wrathyimp
ID: 17148233
In my DNS entries, I have given demo as alias to www, so it should point to the same machine.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 17148520
From your command line:

# httpd -S

This is not the link found /etc/init.d.  The full path on mine is /usr/sbin/httpd.  That command should dump a list of the current vhosts.  Paste that here, after appropriate editing if needed.  I had some issues when setting mine up, too, but I was eventually able to get around it.  I believe your second vhost entry is not being picked up, and the server is defaulting to the first vhost entry (www.mywebserve.com).

From what I've seen of your previous examples, your only issues were the lack of NameVirtualHost, and the demo vhost should be:

<VirtualHost *:80>
  ServerName demo.mywebserver.com
  # ...other stuff
</VirtualHost>
0
 
LVL 1

Author Comment

by:Wrathyimp
ID: 17159000
Thank Routinet,

This the output of the command http2 -S:
Creating new config (0x80deb00) for (null)
VirtualHost configuration:
xxx.xxx.xxx.xxx:80      demo.mywebserver.com (/etc/apache2/vhosts.d/demo_vhost.conf:7)
wildcard NameVirtualHosts and _default_ servers:
*:80                   www.mywebserver.com (/etc/apache2/vhosts.d/default_vhost.conf:7)
Syntax OK
Destroying config 0x80deb00

There is an IP (static) defined to the demomywebserver.com, even with the IP, i am going to the www.mywebserver.com page.
Any other conf file to be modified. The http2.conf has a line mention for the following:
## 'Main' server configuration ##
Include /etc/apache2/default-server.conf

and for virtual host it has the following:
### Virtual server configuration ##
Include /etc/apache2/vhosts.d/*.conf

Does the about main server line affect teh vhost configuration.

Thank You once again.


0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 50 total points
ID: 17161963
A couple things to check:

1) Is the IP used in (/etc/apache2/vhosts.d/demo_vhost.conf:7) the same IP returned by DNS for demo.mywebserver.com?
2) Are you listening  on that IP?  (Listen directive)
3) Try changing your vhost directive for demo to <VirtualHost *:80>
4) Try ensuring the demo declaration is read first.  Does that change any behavior?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now