Find the answer to your Linux question:
Results 1 to 8 of 8
I am rather new to running a webserver so please excuse me if I have missed something obvious or this is a stupid question. I have a Redhat server running ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    4

    Virtual Host Not Working


    I am rather new to running a webserver so please excuse me if I have missed something obvious or this is a stupid question.

    I have a Redhat server running Apache and I need to host a second website on it. I tried setting up virtual hosts by editing the httpd.conf file but the new url just sends me straight to my main website.
    Here is the relevant code from my httpd.conf file:

    Code:
    NameVirtualHost *:80
    
    <VirtualHost *:80>
    ServerName www,mywebsite,com
    ServerAlias mywebsite,com *.mywebsite,com
    DocumentRoot /home/user/public_html
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerName www,newwebsite,com
    DocumentRoot /home/user/public_html/newwebsite
    </VirtualHost>
    (The commas are there because it would not allow me to post urls.)


    Is there a step that I am missing?

  2. #2
    Just Joined! jr0sco's Avatar
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    41
    A good place to look for problems is in the log file normally located in /var/log/httpd/error.log

    Code:
    less /var/log/httpd/error.log
    Edit the httpd.conf and set:

    Code:
    LogLevel debug
    Also have you restarted the httpd service

    Code:
    /etc/init.d/httpd restart
    Everytime you change the conf file for httpd you need to restart the service for changes to take affect.

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Posts
    4
    I have been restarting Apache after every change to httpd.conf. I do not have an error.log file but I do have files named error_log, error_log.1, error_log.2, error_log.3, and error_log.4.

    All of these files are filled with "file does not exist" errors for various pages in my website. These date back further than my changes to httpd.conf.

    Is there something special that I have to set up with DNS?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    This configuration would not work cause the virtual hosts collide. apache simply won't know which webpage he should serve. Set up the virtual hosts correctly as explained in the documentations and you're settled.

  6. #5
    Just Joined! jr0sco's Avatar
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    41
    Quote Originally Posted by aRGeeBee View Post
    Is there something special that I have to set up with DNS?
    Well the vhost config section seems fine. How is the DNS setup? DNS Server or hosts file?

    Can you post your full httpd.conf file

  7. #6
    Just Joined!
    Join Date
    Aug 2010
    Posts
    4
    Quote Originally Posted by Kloschüssel View Post
    This configuration would not work cause the virtual hosts collide. apache simply won't know which webpage he should serve. Set up the virtual hosts correctly as explained in the documentations and you're settled.
    How do they collide? Can you please explain.

    Quote Originally Posted by jr0sco View Post
    Well the vhost config section seems fine. How is the DNS setup? DNS Server or hosts file?

    Can you post your full httpd.conf file
    I have my server with theplanet so I just have the domain pointed at their nameservers.

  8. #7
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    I just revisited Apache-Dokumentation zu virtuellen Hosts - Apache HTTP Server and it seems I was wrong in my opinion. Sorry.

    To test your configuration send modified header data that specify your exact host. If the server THEN does not respond with the correct website, something is broken.

    I.e. send along with the GET the header "Host www.newwebsite.com". If you haven't set up or got your ip already, it is enough to manually mention the entry in /etc/hosts, such that the DNS resolution points to the correct server.

    Next step (if it doesn#t work) would be to check what kind of headers arrive at the server and if they are rewritten in some or the other way by the server.

    You could anyway provide some ServerAlias'es in your configuration that are written without the initial www. Most servers redirect requests to www.somesite to somesite directly, thus it would not match your virtual host name.

  9. #8
    Just Joined!
    Join Date
    Aug 2010
    Posts
    4
    Thank you all for your help. It turns out that the issue was due to an unusual server configuration and has since been resolved.

Posting Permissions

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