Find the answer to your Linux question:
Results 1 to 9 of 9
I am attempting to set up virtual name based hosting with Apache,and Red Hat 9 My problem is that the server always defaults to the first host. /var/www/ausbec. Sorry for ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2004
    Posts
    5

    Virtual hosting


    I am attempting to set up virtual name based hosting with Apache,and Red Hat 9

    My problem is that the server always defaults to the first host. /var/www/ausbec.

    Sorry for the big code post but i thought it would help.

    Code:
    # Use name-based virtual hosting.
    #
    NameVirtualHost *:80
    
    
    
    <VirtualHost *&#58;80>
            ServerName www.ausbec.com
            DocumentRoot /var/www/ausbec
    	DirectoryIndex index.html index.php index.htm
    </VirtualHost>
    
    <VirtualHost *&#58;80>
    	ServerName www.adsolutions.com.au
            DocumentRoot /var/www/adsolutions
            DirectoryIndex index.html
    </VirtualHost>
    
    # Where do we put the lock and pif files?
    LockFile "/var/lock/httpd.lock"
    CoreDumpDirectory "/etc/httpd"
    
    # Defaults for virtual hosts
    
    
    
    
    
    
    
    # Logs
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    #
    # Virtual hosts
    #
    
    # Virtual host Default Virtual Host
    <VirtualHost *>
    
    
    
    
    
    
     	ServerSignature email
    
    	DirectoryIndex  index.php index.html index.htm index.shtml
    
    
    
    
    
    
     	LogLevel  warn
     	HostNameLookups off
    
    
    
    
    </VirtualHost>

  2. #2
    Linux Engineer jledhead's Avatar
    Join Date
    Oct 2004
    Location
    North Carolina
    Posts
    1,077

    Re: Virtual hosting

    try this, notice the part in bold, change to your real ip
    its probably also a good idea to specify a different log file for each VH within the <virtuahost> container</virtualhost>
    # Use name-based virtual hosting.
    #
    NameVirtualHost 192.168.1.1:80



    <VirtualHost *:80>
    ServerName www.ausbec.com
    DocumentRoot /var/www/ausbec
    DirectoryIndex index.html index.php index.htm
    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.adsolutions.com.au
    DocumentRoot /var/www/adsolutions
    DirectoryIndex index.html
    </VirtualHost>

    # Where do we put the lock and pif files?
    LockFile "/var/lock/httpd.lock"
    CoreDumpDirectory "/etc/httpd"

    # Defaults for virtual hosts







    # Logs


































    #
    # Virtual hosts
    #

    # Virtual host Default Virtual Host
    <VirtualHost *>






    ServerSignature email

    DirectoryIndex index.php index.html index.htm index.shtml






    LogLevel warn
    HostNameLookups off




    </VirtualHost>

  3. #3
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    Well, that is not needed; but it gives you a tighter binding if you use something like that.
    You can explicitly control the interfaces to which a VH could be bound.

    And yes, it would definitely help to have different log files for individual VHs.

    My guess for the problem is that both the dirs contain the same index.html, so, you're not able to notice the difference.
    Is it so?
    One more wild guess would be missing <Directorty ...>....</Directory> containers for the docroots of individual VHs.

    If not, could you please post the way you're trying to access the sites?
    Also, are the domain names properly resolved?
    The Unforgiven
    Registered Linux User #358564

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Oct 2004
    Posts
    5
    Hi,
    Thanks for your responses.

    I am definately serving different content from each folder.

    the adsolutions folder is a test page, and the ausbec folder is a php website.

    I am not sure about the directory containers as I have not set any. I have attempted to find information about it on the net, it seems that it is not needed in a simple setup to make it work. But I may have misunderstood,(newbie ) .

    The domain names are resolved using a DNS server, both www.ausbec.com and www.adsolutions.com.au are accessible from the internet, and resolve to the same IP address.

    As a further point, if I change the DocumentRoot directive in the ausbec.com virtual host container, the path does change and both VHs resolve to the new path. So it seems that the first directive is working and the second is not, so Apache resolves to the primary Host.

    Let me know if you require further information.
    Thanks.

  6. #5
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    I am definately serving different content from each folder.
    Yes, agreed...
    This is what it appears to be; but some small detail you might have overlooked?

    Besides, it would be easier if you could set up individual log files for both the VHs and track what is happening - where does it get mapped.
    The Unforgiven
    Registered Linux User #358564

  7. #6
    Just Joined!
    Join Date
    Oct 2004
    Posts
    5
    I have set seperate logs

    Code:
    NameVirtualHost *&#58;80
    
    
    
    
    <VirtualHost *&#58;80>
            ServerName www.ausbec.com
            DocumentRoot /var/www/ausbec
            serverpath /ausbec/
            ErrorLog /var/log/ausbec_error.log
            TransferLog /var/log/ausbec_access.log
            DirectoryIndex index.html index.php index.html
    </VirtualHost>
    
    <VirtualHost *&#58;80>
    	ServerName www.adsolutions.com.au
            DocumentRoot /var/www/adsolutions
            ServerPath /adsolutions/
            ErrorLog /var/log/solutions_error.log
            TransferLog /var/log/solutions_access.log
            DirectoryIndex index.html index.php index.htm
    </VirtualHost>
    The ausbec access log follows(after accessing both hosts once)

    Code:
    203.113.236.190 - - &#91;27/Oct/2004&#58;21&#58;29&#58;26 +091800&#93; "GET / HTTP/1.1" 200 1808
    203.113.236.190 - - &#91;27/Oct/2004&#58;21&#58;29&#58;26 +091800&#93; "GET /Splash1.swf HTTP/1.1" 304 0
    203.113.236.190 - - &#91;27/Oct/2004&#58;21&#58;29&#58;33 +091800&#93; "GET / HTTP/1.1" 304 0
    203.113.236.190 - - &#91;27/Oct/2004&#58;21&#58;29&#58;33 +091800&#93; "GET /Splash1.swf HTTP/1.1" 304 0
    The Splash1.swf is the opening for the webpage.

    The error log for ausbec is empty as are bothe the adsolution log files.

    I feel there must be something simple that I have overlooked.

    also note that the DNS server is on a seperate machine within my network.(but I don't think this should make a differance)

    Another thing I tried was to comment out the first VH container,(ausbec.com). the server then served the page from adsolutions.com.au to both domains.

  8. #7
    Linux Engineer jledhead's Avatar
    Join Date
    Oct 2004
    Location
    North Carolina
    Posts
    1,077
    well, doesn't seem you like my advice so here is my working VH section with fake url and ip's so do what you will with it.

    but mine is working

    Code:
    NameVirtualHost 192.168.1.1
    <VirtualHost bugzilla.yourhost.com>
            ServerAdmin webmaster@dummy-host.com
            DocumentRoot /usr/local/apache2/htdocs/bugs
            ServerName bugzilla.yourhost.com
            ErrorLog logs/testbugs_error_log
            CustomLog logs/testbugs_access_log common
    </VirtualHost>
    
    <VirtualHost developer.yourhost.com>
            ServerAdmin webmaster@dummy-host.com
            DocumentRoot /usr/local/apache2/htdocs
            ServerName developer.yourhost.com
            ErrorLog logs/testwas_error_log
            CustomLog logs/testwas_access_log common
    </VirtualHost>

  9. #8
    Linux Enthusiast
    Join Date
    Jun 2002
    Location
    San Antonio
    Posts
    621
    The issue is, his should work the way it is :-/ Check the full httpd.conf for other instances of NameVirtualHost. When you stop/start apache is there an error like "mixing * and non-* ports . . . "?

    Also of note is the fact that one returns a 200 code, while the other returns a 304. Try to telnet to port 80, to see what the 304 code redirects to. Something like:

    Code:
    $ telnet 192.168.1.1 80
    GET / HTTP/1.1
    Host&#58; www.adsolutions.com.au
    Remember, there should be two enters required after the Host: directive.

    Best,

    Samuel
    I respectfully decline the invitation to join your delusion.

  10. #9
    Just Joined!
    Join Date
    Oct 2004
    Posts
    5
    Thanks Thanks Thanks

    Code:
    Check the full httpd.conf for other instances of NameVirtualHost
    I removed the "Virtual Host Default Virtual Host" directives and now it all works.


    jledhead: Thanks for your advise, I did try what you suggested but was still having problems.

    Thanks to all that helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •