www.webdeveloper.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 32

Thread: Viritual host

  1. #1
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67

    Viritual host

    Hi!
    I'm setting up a second virtual host to be able to preview my php-pages.
    I've added two v-hosts: "G-Sun 2009" and "flyt"
    The apache service is starting but when I try to go to the two v-hosts I'm only ending up in my default httpdoc folder (C:\Webserver).
    What's wrong?

    httpd-vhosts.conf:
    Code:
    <Directory "C:\Documents and Settings\Geir\My Documents\Web-design">
      Order Deny,Allow
      Allow from all
    </Directory>
    
    #
    # Use name-based virtual hosting.
    #
    ##NameVirtualHost *:80
    
    #
    # VirtualHost example:
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for all requests that do not
    # match a ServerName or ServerAlias in any <VirtualHost> block.
    #
    <VirtualHost *:80>
      DocumentRoot "C:\Webserver"
      ServerName localhost
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "C:\Documents and Settings\Geir\My Documents\Web-design\G-Sun 2009"
        ServerName G-Sun2009
    ##    ServerAlias www.dummy-host.example.com
    ##    ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
    ##    CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
    </VirtualHost>
    
    <VirtualHost *:80>
       DocumentRoot "C:\Documents and Settings\Geir\My Documents\Web-design\Flyt"
        ServerName flyt
    ##    ServerAlias www.dummy-host.example.com
    ##    ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
    ##    CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
    </VirtualHost>
    hosts:
    Code:
    127.0.0.1       localhost
    127.0.0.1       G-Sun2009
    127.0.0.1       flyt
    Thanks!

  2. #2
    Join Date
    Aug 2009
    Posts
    84
    Try changing your hosts file to:

    Code:
    127.0.0.1            localhost
    192.168.1.12       G-Sun2009 flyt
    (replace 192.168.1.12 with whatever IP address is assigned to your box)

  3. #3
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67
    Thanks, but I think I have dynamically IP on my modem..

  4. #4
    Join Date
    Aug 2009
    Posts
    84
    You should replace 192.168.1.12 in my previous post with your private LAN IP address, not public IP (dynamic) assigned by your ISP.

    127.0.0.1 is a loopback interface, which I suspect windows will always resolve to 'localhost', that is why you always see your default website.

    But apart from 127.0.0.1 your PC must have another local IP address assigned on your network. You can check it by typing:

    Code:
    ipconfig
    into command line window.

  5. #5
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67
    Thanks! But no success..

    Ran ipconfig and changed hosts to:
    Code:
    127.0.0.1       localhost
    10.0.0.1       G-Sun2009
    10.0.0.1       flyt
    But, no change.
    Is it better having my virtual hosts like flyt.localhost ?

  6. #6
    Join Date
    Jan 2009
    Posts
    3,346
    You can use the same IP for all the virtual hosts. You'll need to use the lan IP assigned by DHCP or statically set manually. So your hosts file would read something like:
    Code:
    192.168.0.2       localhost
    192.168.0.2       G-Sun2009
    192.168.0.2       flyt
    Then in your virtual hosts section of your apache conf would be something like:
    <VirtualHost *:80>
    ServerName localhost
    ServerAdmin youremail@domain
    DocumentRoot "C:/Webserver/"
    ServerPath /
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    </Directory>
    <Directory C:/Webserver/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>
    </VirtualHost>

    <VirtualHost *:80>
    ServerAdmin youremail@domain
    DocumentRoot "C:/Webserver/G-Sun2009/"
    ServerName G-Sun2009
    ServerPath /G-Sun2009
    </VirtualHost>

    <VirtualHost *:80>
    ServerAdmin youremail@domain
    DocumentRoot "C:/Webserver/flyt/"
    ServerName flyt
    ServerPath /flyt
    </VirtualHost>
    This assumes a folder structure of:

    C:/webserver (localhost)
    ------flyt (flyt site)
    ------G-Sun2009 (G-Sun2009 site)

    Remember that you'll have to restart apache every time you edit the config file in order to see any changes. Also on Windoze systems you sometimes have to log out and back in (or reboot) to get the changes in your hosts file to work properly.

  7. #7
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67
    Is this the "lan IP assigned by DHCP"?
    Code:
    Ethernet adapter Local Area Connection 2:
    
            Connection-specific DNS Suffix  . : lan
            IP Address. . . . . . . . . . . . : 10.0.0.1
            Subnet Mask . . . . . . . . . . . : 255.255.255
            Default Gateway . . . . . . . . . : 10.0.0.138
    ..from ipconfig
    Last edited by G-Sun; 11-28-2009 at 12:27 PM.

  8. #8
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67
    Is it necessary that all my virtual host are in subdirectories of localhost (as you typed it above, C:Webserver/ ..)?

    Thanks!

  9. #9
    Join Date
    Jan 2009
    Posts
    3,346
    IP Address. . . . . . . . . . . . : 10.0.0.1
    Yes that is your LAN IP.

    Is it necessary that all my virtual host are in subdirectories of localhost (as you typed it above, C:Webserver/ ..)?
    Not really but it is much easier to maintain if the webroot is pointed to a folder and all virtual hosts are pointed to sub folders. Alternatively, you can make a localhost folder just like the other two and point the localhost virtual host to that folder.

  10. #10
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67
    Ok, I've changed it like you said.
    But the same: When I type http://flyt/ in my browser, I get directed to localhost (c:webserver/)..

    httpd-vhosts.conf:
    Code:
    <VirtualHost *:80>
    ServerName localhost
    ServerAdmin youremail@domain
    DocumentRoot "C:/Webserver/"
    ServerPath /
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    </Directory>
    <Directory C:/Webserver/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerAdmin youremail@domain
    DocumentRoot "C:/Documents and Settings/Geir/My Documents/Web-design/G-Sun 2009/"
    ServerName G-Sun2009
    ServerPath "/G-Sun 2009"
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerAdmin youremail@domain
    DocumentRoot "C:/Documents and Settings/Geir/My Documents/Web-design/Flyt/"
    ServerName flyt
    ServerPath /Flyt
    </VirtualHost>
    httpd.conf:
    Code:
    DocumentRoot "C:/Documents and Settings/Geir/My Documents/Web-design/"

  11. #11
    Join Date
    Jan 2009
    Posts
    3,346
    Did you restart apache after making the changes?

  12. #12
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67
    Quote Originally Posted by criterion9 View Post
    Did you restart apache after making the changes?
    Yes

  13. #13
    Join Date
    Jan 2009
    Posts
    3,346
    Wouldn't it be easier to use:
    C:/Documents and Settings/Geir/My Documents/Web-design/
    for your localhost so the ServerPath will direct correctly? Is there a particular reason you want localhost directed to a completely different location from all the others?

  14. #14
    Join Date
    Feb 2009
    Location
    Norway
    Posts
    67
    Quote Originally Posted by criterion9 View Post
    Wouldn't it be easier to use:

    for your localhost so the ServerPath will direct correctly? Is there a particular reason you want localhost directed to a completely different location from all the others?
    Well c:webserver has been a testserver (Dreamweaver)
    and C:/Documents and Settings/Geir/My Documents/Web-design/
    are the location for my projects.
    If I get these virtual hosts up and running, I don't really need the testserver anymore. But until then I'd like to keep it.
    ..unless changing is necessary.

  15. #15
    Join Date
    Jan 2009
    Posts
    3,346
    Maybe you need to add a "directory" section to each one since it won't be inheriting from a parent directory?

    Something like this for each one:
    <Directory C:/Webserver/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles