Apache2, using vhosts?

Discussion in 'Web Design and Development' started by xper, Nov 21, 2008.

  1. xper macrumors 6502

    xper

    Joined:
    Dec 15, 2005
    Location:
    Sweden - Halmstad
    #1
    Hi!

    I´ve read the virtual host documention for Apache2 but i still cant get it to work.

    Currently i am using MAMP to develop my homepage, current adress is localhost:20000 and i still want to be able to use the localhost:port setup to get to the page localy, and be able to use my domain www.rogatio.com to get to the homepage, how do i solve that with vhosts?

    Currently it looks like this:

    Listen 20000

    NameVirtualHost localhost:20000

    <VirtualHost localhost:20000>
    ServerName localhost:20000
    DocumentRoot "/Applications/MAMP/htdocs_rogatio.com/"
    </VirtualHost>
     
  2. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #2
    Using this example:
    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>
    
    Change you ServerName directive.
     
  3. xper thread starter macrumors 6502

    xper

    Joined:
    Dec 15, 2005
    Location:
    Sweden - Halmstad
    #3
    Yes that is exactly the example that Apache provides and i dont understand an inch of it.
     
  4. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #4
    Look how you defined ServerName. You included a port. You should put just localhost, or your website.domain.tld, in there. In essence, you put in the ServerName directive whatever someone is going to type in their web browser to get to that site.
     
  5. xper thread starter macrumors 6502

    xper

    Joined:
    Dec 15, 2005
    Location:
    Sweden - Halmstad
    #5
    Ok, so now it looks like this:

    PHP:
    Listen 20000

    NameVirtualHost localhost
    :20000

    <VirtualHost localhost:20000>
    ServerName localhost:20000
    DocumentRoot 
    "/Applications/MAMP/htdocs_rogatio.com/"
    </VirtualHost>

    NameVirtualHost *:20000

    <VirtualHost *:20000>
    ServerName www.rogatio.com
    ServerAlias rogatio
    .com *.rogatio.com
    DocumentRoot 
    "/Applications/MAMP/htdocs_rogatio.com/"
    </VirtualHost>
    I can access localhost:2000 but not www.rogatio.com
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  7. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #7
    If you ping www.rogatio.com, does it return the IP of your system or localhost?
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    Make sure you have this in your httpd.conf just before your virtual host declarations. This should make sure permissions are setup properly.
    Code:
    <Directory "/Applications/MAMP/htdocs_rogatio.com">
     Order Deny,Allow
     Allow from all
    </Directory>
    You'll also need to edit the /etc/hosts file for the server name you're using. Open Terminal and do a,
    Code:
    sudo pico /etc/hosts
    It'll have something like,
    Code:
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1	localhost
    255.255.255.255	broadcasthost
    ::1             localhost
    At the end add the line
    Code:
    127.0.0.1 www.rogatio.com
    Then save it and restart the web server.
     

Share This Page