Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
I've Googled this thing for days and can find many instances of others having this same problem, but cannot find a solution that works for me. The solutions always say ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Trusted Penguin Dapper Dan's Avatar
    Join Date
    Oct 2004
    Location
    The Sovereign State of South Carolina
    Posts
    4,628

    Apache2: second virtual host resolves to first virtual host's index.html


    I've Googled this thing for days and can find many instances of others having this same problem, but cannot find a solution that works for me. The solutions always say to set up my virtual servers like I have them below. I have two domains with DNS resolving to the same IP address of my LAMP server. Here is the configuration from sites-enabled:
    Code:
    <VirtualHost *>
    DocumentRoot /website_one
    <Directory "/website_one">
    allow from all
    Options +Indexes
    </Directory>
    ServerName website_one.com
    </VirtualHost>
    
    <VirtualHost *>
    DocumentRoot /var/www/wordpress
    <Directory "/var/www/wordpress">
    allow from all
    Options +Indexes
    </Directory>
    ServerName website_two.com
    ServerAlias website_two.com
    </VirtualHost>
    Also in sites-enabled is file 000-default:
    Code:
    NameVirtualHost 123.456.789.100:80
    I have tried using "123.456.789.100:80" in the VirtualHost field of both instead of '*' but that gives me "server not found" on each.

    With the above configuration, website_one works perfectly. When I try to reach the second, doing in Firefox: "http://website_two.com" it should show me website_two which is wordpress. It doesn't. Rather, it takes me to the same webpage as website_one. I know wordpress is working because up till now, I've always accessed it as a page from website_one but now I want it to give it its own domain.

    Why am I getting website_one's index.html when trying to reach website_two instead of website_two's index.php for wordpress? This is my first attempt at setting up virtual hosts with Apache so be gentle with me...

    Any help or insight appreciated.
    Linux Mint + IceWM Registered:#371367 New Members: click here

  2. #2
    Linux Newbie rituraj.goswami's Avatar
    Join Date
    Aug 2008
    Location
    Guwahati
    Posts
    135
    can you get the server log messages. and what linux are you using? are your selinux and permissions ok?

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    49
    This sounds similar to an issue I have seen before which turned out to be because they were using <virtualhost *> rather than <virtualhost website_one.com:*>

    So you could either change these tags or add the vhost names into your /etc/hosts file which sould fix the issue.

  4. #4
    Linux Enthusiast gruven's Avatar
    Join Date
    Dec 2004
    Location
    Arkansas
    Posts
    541
    I run Gentoo, so YMMV with this solution (directories could be different, you may have symlinks in a directory to enable vhosts, etc... but this configuration has worked on several distros, including debian. Just adapt it as necessary).

    I leave my default vhost as the default, and only run websites from my home directories. Each virtual host is in a different file.

    Each one uses the layout here:
    Code:
    <VirtualHost *:80>
    	ServerName gruven.sytes.net
    	DocumentRoot /home/don/public_html/gruven
    	ServerAlias gruven.sytes.net
    </VirtualHost>
    And that is it. That is all I do to have different vhosts point to different directories. Just replace gruven.sytes.net and the root directory to adapt to your system.

    *edit
    Not sure if this makes a difference, but the naming scheme for each of my virtual host files is:
    Code:
    01_gruven.sytes.net_vhost.conf
    Just change the number to increase with each one, and change the name (gruven.sytes.net) to reflect the domain you are hosting in it. I put this in /etc/apache2/vhosts.d. I also have default_vhosts turned on in my apache config file.

    Linux User #376741
    Code is Poetry

  5. #5
    Linux Enthusiast gruven's Avatar
    Join Date
    Dec 2004
    Location
    Arkansas
    Posts
    541
    Quote Originally Posted by kazler View Post
    So you could either change these tags or add the vhost names into your /etc/hosts file which sould fix the issue.
    That would just affect local resolution, not internet resolution. Apache would have to direct traffic to that location, and it uses its own vhosts to do that.

    Linux User #376741
    Code is Poetry

  6. #6
    Just Joined!
    Join Date
    Dec 2006
    Posts
    5

    Wink

    I've had this same problem. My solution was checking in my listen.conf file and making sure you had <VirtualHost *:80> entries for all variations of your domain name, such as:

    <VirtualHost *:80>
    ServerName host-one.com
    DocumentRoot /home/somefile
    DirectoryIndex index.html, etc...
    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.host-one.com
    DocumentRoot /home/somefile
    DirectoryIndex index.html, etc...
    </VirtualHost>

    And so forth... I hope that helps you, I know how frustrating your situation is

  7. #7
    Linux Enthusiast gruven's Avatar
    Join Date
    Dec 2004
    Location
    Arkansas
    Posts
    541
    Quote Originally Posted by dalrq79 View Post
    I've had this same problem. My solution was checking in my listen.conf file and making sure you had <VirtualHost *:80> entries for all variations of your domain name, such as:

    <VirtualHost *:80>
    ServerName host-one.com
    DocumentRoot /home/somefile
    DirectoryIndex index.html, etc...
    </VirtualHost>

    <VirtualHost *:80>
    ServerName Index of /
    DocumentRoot /home/somefile
    DirectoryIndex index.html, etc...
    </VirtualHost>

    And so forth... I hope that helps you, I know how frustrating your situation is
    That would be annoying. I thought that the point of virtual hosts was to basically put the settings in one file and apache would handle the rest. Basically, you have to put them in two places doing that, and it seems pointless to me. Just my opinion though.

    Different distros do it different ways though.

    Linux User #376741
    Code is Poetry

  8. #8
    Just Joined!
    Join Date
    Dec 2006
    Posts
    5
    Quote Originally Posted by gruven View Post
    That would be annoying. I thought that the point of virtual hosts was to basically put the settings in one file and apache would handle the rest. Basically, you have to put them in two places doing that, and it seems pointless to me. Just my opinion though.

    Different distros do it different ways though.

    This is true. In this instance, I'm using Suse so it's httpd.conf file is littered with include entries. I guess just the way they do it, but hopefully that bit of advice might help you with your problem, as you can relate it to your distro...

  9. #9
    Linux Enthusiast gruven's Avatar
    Join Date
    Dec 2004
    Location
    Arkansas
    Posts
    541
    Quote Originally Posted by dalrq79 View Post
    This is true. In this instance, I'm using Suse so it's httpd.conf file is littered with include entries. I guess just the way they do it, but hopefully that bit of advice might help you with your problem, as you can relate it to your distro...
    I looked around my folders of apache configs, and I couldn't even find a listen.conf. This just goes to show you that different distros do some things extremely different.

    It probably would have helped though if we would have asked Dapper Dan what version he was running of apache, because they change their config's around in versions too.

    I know in Debian all you have to do is make a symlink from /etc/apache2/vhost-config-folder to /etc/apache2/vhost-enabled or something very similar.

    Let me ask you dalrq79, does Suse have a yast module to configure apache? And if so, does it change your listen.conf? Just curious so that maybe we can help others that have vhost problems. I know I do when I go do different distros sometimes.

    I usually just go to the apache website and create a barebones vhost config file for each site, and then just add and subtract things until it works. I have found that simple is usually better.

    In Gentoo, we have /etc/apache2/httpd.conf, and /etc/conf.d/apache2 for config files. My vhosts go in /etc/apache2/vhosts.d.

    We should start a apache sticky with the config files and vhosts howto's for each distro. hmmm....

    Linux User #376741
    Code is Poetry

  10. #10
    Just Joined!
    Join Date
    Dec 2006
    Posts
    5
    Quote Originally Posted by gruven View Post
    I looked around my folders of apache configs, and I couldn't even find a listen.conf. This just goes to show you that different distros do some things extremely different.

    It probably would have helped though if we would have asked Dapper Dan what version he was running of apache, because they change their config's around in versions too.

    I know in Debian all you have to do is make a symlink from /etc/apache2/vhost-config-folder to /etc/apache2/vhost-enabled or something very similar.

    Let me ask you dalrq79, does Suse have a yast module to configure apache? And if so, does it change your listen.conf? Just curious so that maybe we can help others that have vhost problems. I know I do when I go do different distros sometimes.

    I usually just go to the apache website and create a barebones vhost config file for each site, and then just add and subtract things until it works. I have found that simple is usually better.

    In Gentoo, we have /etc/apache2/httpd.conf, and /etc/conf.d/apache2 for config files. My vhosts go in /etc/apache2/vhosts.d.

    We should start a apache sticky with the config files and vhosts howto's for each distro. hmmm....

    Yes, Yast does have a config module for Apache, but it complete wrecks the httpd.conf file so i just built mine from scratch. Perhaps I'm doing something wrong.... haha Anyway, just making the adjustments to the vhost sections that you have listed above might help.

Page 1 of 2 1 2 LastLast

Posting Permissions

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