VirtualHosts fail in Apache

Discussion in 'Apache' started by nicolasfo, Jul 16, 2010.

  1. #1
    Hello everyone !

    I'm tring to set virtualhosts in apache2.

    In apache2.conf, I set :
    ServerName mylocalIP
    NameVirtualHost *

    I've made a first virtualhost like this :
    <VirtualHost *>
            ServerName  webmail.mydomain.tld
    
            # Indexes + Directory Root.
            DirectoryIndex index.php
            DocumentRoot /var/www/webmail/
    
            # Logfiles
            ErrorLog  /var/log/apache2/webmail/error.log
            CustomLog /var/log/apache2/webmail/access.log combined
    </VirtualHost>
    Code (markup):
    I've made a second virtualhost like this :
    <VirtualHost *>
            ServerName  phpbb.mydomain.tld
    
            # Indexes + Directory Root.
            DirectoryIndex index.php
            DocumentRoot /var/www/phpbb/
    
            # Logfiles
            ErrorLog  /var/log/apache2/phpbb/error.log
            CustomLog /var/log/apache2/phpbb/access.log combined
    </VirtualHost>
    Code (markup):
    I did a a2ensite webmail + a2ensite phpbb + apache2 reload.

    To test, I use a computer out of my network :
    - When I go to "webmail.mydomain.tld", I see my webmail -> OK
    - When I go to "phpbb.mydmain.tld", I see my webmail -> Not OK
    - When I go to "mydomain.tld", I see my webmail -> Not OK
    - When I go to "something.mydmain.tld", I see my webmail -> Not OK

    "something.mydomain.tld" isn't a virtualhost I created, it doesn"t exists.

    Question are how to make :
    - "webmail.mydmain.tld" goes to /var/www/webmail/
    - "mydmain.tld" goes to /var/www/
    - "something.mydmain.tld" goes to /var/www/ ?

    Thanks a lot :)
     
    nicolasfo, Jul 16, 2010 IP
  2. madaboutlinux

    madaboutlinux Member

    Messages:
    250
    Likes Received:
    7
    Best Answers:
    2
    Trophy Points:
    43
    #2
    Why will you see Webmail for the above 3 URLs, if their DocumentRoot is not pointing to /var/www/webmail/ ? They should point to their own DocumentRoot.

    BTW, make sure the A record for phpbb.mydmain.tld and mydmain.tld is set to your server IP. And a wildcard DNS record set to point to mydmain.tld.


    You need to add the VirtualHost entry for each of the URL you are trying to access including *.mydomain.tld for something.mydomain.tld to work. Make sure you set an A record for all the sub-domains including wirld-card i.e. * to point to your server IP. The entry should be placed in the DNS zone of the mydomain.tld file.
     
    madaboutlinux, Jul 17, 2010 IP
  3. nicolasfo

    nicolasfo Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Okay, and in the Bind conf file, must I specify my LAN IP adress, or my WAN IP adress ?
    Actually, all my Bind conf file is configured with LAN IP adress (192.168.x.x)

    Thanks a lot :)
     
    nicolasfo, Jul 19, 2010 IP
  4. madaboutlinux

    madaboutlinux Member

    Messages:
    250
    Likes Received:
    7
    Best Answers:
    2
    Trophy Points:
    43
    #4
    You should specify the WAN IP address in the DNS zone files. Make sure you have WAN IP address for all the entires of a domain. LAN IP won't do...
     
    madaboutlinux, Jul 19, 2010 IP
  5. rhtxpert

    rhtxpert Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yes u didnt set the WAN IP just check on it..!
     
    rhtxpert, Jul 20, 2010 IP
  6. nicolasfo

    nicolasfo Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hello,

    First, thanks for your replies, it was very helpful for me.
    I set my subdomains in my Bind configuration : this is more efficient this way...lol.

    I don't use my WAN IP, my Bind server is also used on my LAN, it works like this, do you judge I must use my WAN IP ? My server is behind a router and I forward 80 traffic to my LAN IP server ? Wait and see, it's not important at the moment, it works...

    I got a new problem now, with another kind of VirtualHost.
    I must make a redirection with apache to another server by the port 80 with this Virtualhost config :
    <VirtualHost *>
    ServerName glpi.mydomain.tld
            <Proxy *>
                    Order deny,allow
                    Allow from all
            </Proxy>
            RewriteEngine on
            ProxyPass               / http://192.168.x.x/glpi/
            ProxyPassReverse        / http://192.168.x.x/glpi/
    
            # Logfiles
            ErrorLog  /var/log/apache2/glpi/error.log
            CustomLog /var/log/apache2/glpi/access.log combined
    </VirtualHost>
    Code (markup):
    I activate "RewiteEngine", "Proxypass", "ProxyPassReverse" modules, and on my LAN, when I type http://192.168.x.x/phpbb it works.

    When I try to go to glpi.mydmain.tld, it doesn't display pictures, I got text, but no pictures. I repeat I works fine on my LAN.

    I do the same kind of VirtualHost with phpbb and I works from the WAN.

    Is there a module to activate or something ?

    Thanks a lot !:)
     
    nicolasfo, Jul 21, 2010 IP