Find the answer to your Linux question:
Results 1 to 10 of 10
Hello, I have successfully setup LAMP using Kubuntu 10.04, MYSQL, Apache2, and PHP on my laptop. I have successfully setup site3(dot)com on my computer. However, I cannot setup site2 or ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    27

    Unhappy How can I setup multiple sites


    Hello,
    I have successfully setup LAMP using Kubuntu 10.04, MYSQL, Apache2, and PHP on my laptop.
    I have successfully setup site3(dot)com on my computer.

    However, I cannot setup site2 or site1. They all point to the same site.
    Pinging all three sites gives the same response: 127.0.0.1

    Here is a snippet from the /etc/hosts file:
    Code:
    127.0.0.1          localhost      site3(dot)com        site2(dot)com        site1(dot)com
    127.0.1.1        ryy
    Here is the error message I get when I reload Apache:
    Code:
    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
    [Tue Aug 17 17:51:50 2010] [warn] VirtualHost site1(dot)com:0 overlaps with VirtualHost site2(dot)com:0, the first has precedence, perhaps you need a NameVirtualHost directive
    [Tue Aug 17 17:51:50 2010] [warn] VirtualHost site3(dot)com:0 overlaps with VirtualHost site1(dot)com:0, the first has precedence, perhaps you need a NameVirtualHost directive

    Here is config file for a single site:
    Code:
    <VirtualHost site1(dot)com>
    ServerAdmin webmaster(at)localhost
    #We want to be able to access the web site using www(dot)dev(dot)example(dot)com or dev(dot)example(dot)com
    ServerAlias site1(dot)com
    DocumentRoot /home/ryy/Sites/public_html/site1(dot)com
    #if using awstats
    ScriptAlias /awstats/ /usr/lib/cgi-bin/
    #we want specific log file for this server
    CustomLog /var/log/apache2/example(dot)com-access.log combined
    </VirtualHost>
    Has anyone run into this problem before?

    Is NameVirtualHost directive the way to go? What changes do I need to make to implement it?
    Many thanks in advance for your help.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,933
    All you probably need to do is make sure that your virtual host directives dont point to the same website. If you've cut and pasted your <VirtualHost ...> nodes, then you've probably not done all the renaming properly.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    53
    probably you want to use the IP address not the dns name - b/c the later will incur dns lookup at least once in every request.

    am presuming your dns records actually point to your machine (and hence the request will contain these names), else is a little more tricky. not sure about your example with them all pointing to the localhost address, seems unlikely that's how you'd want to proceed anyway...

    these settings are for a machine with two nic cards - a private ip address (for lan access) and a public ip address (accessible from the internet).

    am being explicit about port 80 but if you don't run ssl then can drop that part in the NameVirtualHost and VirtualHost

    make sure you are listening on all interfaces - or else name them explicitly - usually this is in listen.conf
    Code:
    Listen 80
    this is recommended for global.conf or somewhere consistent across your apache configuration - can also set per vhost but gets more complicated.
    Code:
    UseCanonicalName on
    these i find much easier to keep together in the vhost config file(s)
    Code:
    NameVirtualHost public-ip:80
    NameVirtualHost private-ip:80
    should always have this one to help identify when your vhost matching fails - will help keep your sanity...

    Code:
    <VirtualHost _default_>
            DocumentRoot /srv/www/htdocs
            ServerName www.site0.com
            CustomLog /var/log/apache2/default.log combined
    </VirtualHost>
    these virtual host are using same configuration whether found on lan (via internal dns) or from internet.

    site1:
    Code:
    <VirtualHost public-ip:80 private-ip:80>
    # identity
            DocumentRoot /srv/www/site1
            ServerName www.site1.com
            CustomLog /var/log/apache2/site1.log combined
    </VirtualHost>
    site2:
    Code:
    <VirtualHost public-ip:80 private-ip:80>
            DocumentRoot /srv/www/site2
            ServerName www.site2.com
            CustomLog /var/log/apache2/site2.log combined
    </VirtualHost>
    should get you going...

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Aug 2010
    Posts
    27
    chaosless: Are you saying that your solution will only work if I have two NICs?

    Roxoff: Yes, I did copy and paste all the VH nodes.
    But I replaced all the instances of site1(dot)com with site2(dot)com and the document roots point to different directories.

  6. #5
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,933
    @chaosless, I think you're trying to do this the wrong way round. This user wants to host multiple websites on a single IP, not multiple IPs on a single server.

    @ryy705 you must ensure that the DNS for www.site1.com and www.site2.com both resolve to the same IP address. This is straightforward if you have access to the DNS config for both domains. You can use chaosless' virtual hosts configuration above, just make sure that you put <VirtualHost www.site1.com:80> rather than an IP address as the introduction. Also, remember to restart apache after you do this, 'cos it's really easy to forget then spend ages trying to work out why your changes had no effect...
    Linux user #126863 - see http://linuxcounter.net/

  7. #6
    Just Joined!
    Join Date
    Jul 2010
    Posts
    53
    @roxoff this is the best performance way i've found to have multiple websites on a single ip. only reason i'd shown a 2nd ip is to delineated between a lan ip and a wan ip since that is the most common setup in a business setup, e.g. intranet/extranet and all that jazz. am running several websites on a single ip using it. am always glad to find a better way of course.

    usually you don't want dns involved in your vhost evaluation - only, as you say, to make sure dns for your multiple sites points to your ip. once the browser has found your ip via its dns and encodes the server name it expects into the header then you are able to determine what vhost they are looking for just from the header. UseCanonicalName is very helpful in this regard.

    once setup this way, if you watch the logs (separated by different vhosts, and for _default_ match) is pretty easy to resolve any further vhost matching issues.
    Last edited by chaosless; 08-20-2010 at 02:45 PM. Reason: be nicer

  8. #7
    Linux Engineer jledhead's Avatar
    Join Date
    Oct 2004
    Location
    North Carolina
    Posts
    1,077
    just using namebased virtual hosts is all you need.

    site1.example.com site2.example.com and site3.example.com all have the same ip and route to the same machine. edit your hosts file so the machine knows all those ips resolve to itself (no dns lookups) and then use namebased vhosts
    https://encrypted.google.com/search?...+hosts&spell=1
    the first 2 links should get you what you need for 1.3 and 2.2 apache (respectively)

    you could also search this forum for NameVirtualHost and a config would look similar to this:
    Code:
    NameVirtualHost *:80
    
    <VirtualHost *:80>
    ServerName www.domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot /www/domain
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerName www.otherdomain.tld
    DocumentRoot /www/otherdomain
    </VirtualHost>

  9. #8
    Just Joined!
    Join Date
    Aug 2010
    Posts
    5
    Quote Originally Posted by ryy705 View Post
    Hello,
    Here is config file for a single site:
    Code:
    <VirtualHost site1(dot)com>
    ServerAdmin webmaster(at)localhost
    #We want to be able to access the web site using www(dot)dev(dot)example(dot)com or dev(dot)example(dot)com
    ServerAlias site1(dot)com
    DocumentRoot /home/ryy/Sites/public_html/site1(dot)com
    #if using awstats
    ScriptAlias /awstats/ /usr/lib/cgi-bin/
    #we want specific log file for this server
    CustomLog /var/log/apache2/example(dot)com-access.log combined
    </VirtualHost>
    Hi,

    As I can see from your config it is missing ServerName Directive. The config should look as follows.

    Code:
    <VirtualHost site1(dot)com>
    ServerAdmin webmaster(at)localhost
    ServerName site1(dot)com
    #We want to be able to access the web site using www(dot)dev(dot)example(dot)com or dev(dot)example(dot)com
    ServerAlias www(dot)site1(dot)com
    DocumentRoot /home/ryy/Sites/public_html/site1(dot)com
    #if using awstats
    ScriptAlias /awstats/ /usr/lib/cgi-bin/
    #we want specific log file for this server
    CustomLog /var/log/apache2/example(dot)com-access.log combined
    </VirtualHost>
    This should resolve your problem.

    Regards,

    Mohan

  10. #9
    Just Joined!
    Join Date
    Aug 2010
    Posts
    27

    jledhead is a Genius

    I had posted this message on other forums as well. And no other forum came close to this one. You are all geniuses.

    jledhead: Your solution worked perfectly. Thank you.
    One question though. When I restart apache2 I get the following error message:
    Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
    NameVirtualHost *:80 has no VirtualHosts
    NameVirtualHost *:80 has no VirtualHosts

    Should I worry about this?

  11. #10
    Linux Engineer jledhead's Avatar
    Join Date
    Oct 2004
    Location
    North Carolina
    Posts
    1,077
    I think the error is harmless. What you are doing by using the *:80 is saying to match for any listening ip on port 80. If this machine has multiple ip's/nics associated, you could say
    Code:
    NameVirtualHost 1.2.3.4
    and then repeat that for every IP you want apache to listen for.

    Then the virtual host container would say
    Code:
    <VirtualHost 1.2.3.4>
    If you only have 1 ip and then you can either add the ip like above, or just keep using the *:80. At least thats my understanding of it and its never given me a problem.

Posting Permissions

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