Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

  1. #11
    Join Date
    Feb 2009
    Location
    Texas
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    Quote Originally Posted by cdenley View Post
    Generally, there is one vhost configuration per file. Once you create a new "site", you would need to enable it (sudo a2ensite site2). Putting multiple vhost configurations in /etc/apache2/sites-available/default would work, but isn't really the standard way of doing things in ubuntu.

    You shouldn't edit apache2.conf to configure virtual hosts (sites). It is only for global configurations unrelated to any module or listening configuration. Also, you shouldn't edit httpd.conf for anything in ubuntu (I've seen it suggested in other threads).
    Your are complete right! And believe me, I've checked, read several documents before posting, but Ubuntu configuration is kind of different.

    Like I said, site is enable (and I tried via two files/sites before, with no success) but I'll try again from scratch. What I'm planning to do this

    -NOT TOUCHING /etc/apache2/apache2.conf, I WILL NOT ADD ANY LINE HERE
    -Create two files (for each virtual host) under /etc/apache2.conf/sites-available/ like deafult and site2
    -Enable both sites via command: a2ensite

    Can someone please post two "fakes" virtual hosts sites configuration like an example or guide to me ... I will only change the site content pointers to /var/www and /var/site2, it will help a lot

    Thanks,

  2. #12
    Join Date
    Feb 2009
    Location
    Texas
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    Wohoo! just found this super article/guide (which is Debian): http://www.debian-administration.org/articles/357 can't wait for lunch so I can test it ...

  3. #13
    Join Date
    Feb 2009
    Location
    Texas
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    OK, is working now, yeah! so I am happy ... but I am kind of confused, this is what I did (following this document: http://www.debian-administration.org...7#virtual_host and here are questions

    1st...

    Code:
            <Directory /var/www/mydomain.com/docs>
                    Order Deny,Allow
                    Allow from all
                    # Don't show indexes for directories
                    Options -Indexes
            </Directory>
    If I follow that structure, apache complains about, it says can not use both directives at same time or something like that. Unfortunately, did not save the error

    2nd
    I had to create a two folders under /var/wwww One is the parent folder for the 2nd site and a folder inside that one, for docs ... why? I thought I can create anything on /var/ and then point the VirtualHost file to that.

    3rd and final doubt
    I had to create another site under /etc/apache2/sites-available/ . One was there already, "default" ... I create another one blahblahblah.com and edit it; I put something inside like in point 1st. Do I have to create separate files for each site in order to work or this is just for good admin purposes?

    Thanks in advance,

  4. #14
    Join Date
    Feb 2009
    Location
    Texas
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    OK, almost there, but getting a funny error when retrieving my second site... if I do not append "www" at the beggining, it just displays the other site instead. For instance ...

    If I put www.fake1.com browser displays--> www.fake1.com (right)

    If I put fake1.com browser displays--> fake1.com (right)

    Now...

    If I put: www.fake2.com browser displays--> www.fake2.com content (right)

    If I put fake2.com browser displays--> fake1.com (wrong!!!)

    Why I'm getting the wrong website content when "www" is omitted??? I do not understand. Here's the exact content of each file, which now I am copy/pasting in its total

    For fake1.com

    Code:
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            #I want to be able to access the web site using www.fake1.com
            ServerName www.fake1.com
            DocumentRoot /var/www/fake1.com/docs
    
            <Directory /var/www/fake1.com/docs>
                    Order Deny,Allow
                    Allow from all
                    # Don't show indexes for directories
                    Options -Indexes
            </Directory>
    </VirtualHost>
    For fake2.com

    Code:
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            #I want to be able to access the web site using www.fake2.com
            ServerName www.fake2.com
            DocumentRoot /var/www/fake2.com/docs
    
            <Directory /var/www/fake2.com/docs>
                    Order Deny,Allow
                    Allow from all
                    # Don't show indexes for directories
                    Options -Indexes
            </Directory>
    </VirtualHost>
    This is driving me crazy...am I missing something or this is a normal behaviour or what?

  5. #15
    Join Date
    Nov 2008
    Beans
    62
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    I'm not sure if this will help but maybe you need to put your domain names in your /etc/hosts file similar to this, say the local ip is 192.168.1.10 is nated to your public ip:

    Code:
    127.0.0.1       localhost
    127.0.1.1       LinuxServer
    
    192.168.1.10 fake1.com www.fake1.com
    192.168.1.10 fake2.com www.fake2.com
    
    
    # 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
    ff02::3 ip6-allhosts
    or maybe try to check your www redirecting at your registrar or your DNS service.

  6. #16
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    Quote Originally Posted by jocampo View Post
    OK, almost there, but getting a funny error when retrieving my second site... if I do not append "www" at the beggining, it just displays the other site instead. For instance ...

    If I put www.fake1.com browser displays--> www.fake1.com (right)

    If I put fake1.com browser displays--> fake1.com (right)

    Now...

    If I put: www.fake2.com browser displays--> www.fake2.com content (right)

    If I put fake2.com browser displays--> fake1.com (wrong!!!)

    Why I'm getting the wrong website content when "www" is omitted??? I do not understand. Here's the exact content of each file, which now I am copy/pasting in its total

    This is driving me crazy...am I missing something or this is a normal behaviour or what?
    Since fake1 config is loaded first by Apache it acts as a default for any servernames that it doesn't find a match for. So fake1.com, fake2.com get served by the www.fake1.com virtual host. If you want fake2.com to match to www.fake2.com then i think you can just add it as a ServerAlias in that virtual host config.

  7. #17
    Join Date
    May 2008
    Location
    Puerto Rico
    Beans
    65
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    Quote Originally Posted by DaithiF View Post
    If you want fake2.com to match to www.fake2.com then i think you can just add it as a ServerAlias in that virtual host config.
    I was about to suggest the same:

    Code:
    ServerName www.fake2.com
    ServerAlias fake2.com
    Also, if I was troubleshooting for myself, one option I might try is: disabling www.fake1.com as the default Apache site, but creating it as a non-default site (using the correspondent sites-available config). So you'll probably need something like:

    Code:
    sudo a2dissite default && sudo a2ensite fake1.com
    (I hope I got that line right ). Good luck.
    Last edited by Kolipoki; August 26th, 2009 at 02:34 PM.
    - "We are not because of our skills, but because of our choices" -- Dumbledore, in "The Prisoner of Azkaban"
    - "Say it like if I was 8 years old" -- Denzel Washington, in "Philadelphia"

  8. #18
    Join Date
    Feb 2009
    Location
    Texas
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    Quote Originally Posted by DaithiF View Post
    Since fake1 config is loaded first by Apache it acts as a default for any servernames that it doesn't find a match for. So fake1.com, fake2.com get served by the www.fake1.com virtual host. If you want fake2.com to match to www.fake2.com then i think you can just add it as a ServerAlias in that virtual host config.
    DaithiF, I think you are right, it took me some hours to realize that and I came with this solution (maybe not too elegant) please see below...

    Adina:
    Thanks for your help anyway ... but problem is that I have a Public IP. And yes, the A records were edited so both are pointing to my webserver/public IP, and the CNAME record "www" is also pointing to my public IP.

    This is my solution (not sure if is the more elegant or the only one)

    Fake2 file (now)

    Code:
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            #I want to be able to access the web site using www.fake2.com
            ServerName www.fake2.com
            DocumentRoot /var/www/fake2.com/docs
    
            <Directory /var/www/fake2.com/docs>
                    Order Deny,Allow
                    Allow from all
                    # Don't show indexes for directories
                    Options -Indexes
            </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            #I want to be able to access the web site using www.fake2.com
            ServerName fake2.com
            DocumentRoot /var/www/fake2.com/docs
    
            <Directory /var/www/fake2.com/docs>
                    Order Deny,Allow
                    Allow from all
                    # Don't show indexes for directories
                    Options -Indexes
            </Directory>
    </VirtualHost>
    On same second file, I added another entry for Servername without "www". It did the trick. Now fake2 loads no matter what , with or without the "www" ...

    Thank you all guys for your help. I'll put a SOLVED tag and hopefully this will help others. I've noticed Apache configuration is not so complex but intuitive, problem is that Apache lacks of Ubuntu specific documentation; most of How To online describe processes for other distros. Ubuntu has a different folder structure.

    Thanks again!

  9. #19
    Join Date
    Feb 2009
    Location
    Texas
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    Quote Originally Posted by Kolipoki View Post
    I was about to suggest the same:

    Code:
    ServerName www.fake2.com
    ServerAlias fake2.com
    Also, if I was troubleshooting for myself, one option I might try is: disabling www.fake1.com as the default Apache site, but creating it as a non-default site (using the correspondent sites-enabled config file). So you'll probably need something like:

    Code:
    sudo a2dissite default && sudo a2ensite fake1.com
    (I hope I got that line right ). Good luck.
    More elegant solution than mine! ... thanks ... maybe I'll try it this weekend just to validate Apache Behaviour. I appreciate your help!

  10. #20
    Join Date
    May 2008
    Location
    Puerto Rico
    Beans
    65
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Help with Apache VirtualHosts. Using 1 IP for two sites. One is not loading

    Quote Originally Posted by jocampo View Post
    On same second file, I added another entry for Servername without "www". It did the trick. Now fake2 loads no matter what , with or without the "www" ...

    Thank you all guys for your help. I'll put a SOLVED tag and hopefully this will help others. I've noticed Apache configuration is not so complex but intuitive, problem is that Apache lacks of Ubuntu specific documentation; most of How To online describe processes for other distros. Ubuntu has a different folder structure.

    Thanks again!
    Actually, I forgot to mention, I might be wrong, but I think you can also include both names for the ServerName directive. Like:

    Code:
    ServerName www.fake2.com fake2.com
    That would save you from repeating the whole stuff. Please someone correct me if I'm wrong.
    - "We are not because of our skills, but because of our choices" -- Dumbledore, in "The Prisoner of Azkaban"
    - "Say it like if I was 8 years old" -- Denzel Washington, in "Philadelphia"

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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