Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Can I make a subdirectory of localhost behave like a root directory for a site?



Dave M G writes:
 > What I'd like to be able to do is make it so that on my local machine, 
 > when accessing each web site's directory, the server behaves as if the 
 > web site's own directory is it's root directory. Then I can test at home 
 > and upload to my hosting service without having relative links break on me.
 > 
 > Is this possible in any way?

Yes.  This is *precisely* what is meant by a virtual host, you just
don't want it to be out there on the Internet (until you say so, of
course!)  What you need to do is create aliases for localhost (on the
loopback interface, eg, with

127.0.0.1   website_one
127.0.0.1   website_two

in /etc/hosts; you may need to tell /etc/nssswitch.conf to pay
attention to "files" for DNS services; if you're running a local
nameserver it may be preferable to do it that way, with an address
on the LAN---this is beyond the scope of your question, though).

Then in your apache configuration, something like

# The restriction to an unroutable interface will keep these sites
# from leaking out to the Internet.
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
        ServerName website_one
        DocumentRoot /var/www/website_one/

        # all your usual paraphernalia goes here

</VirtualHost>

and from your browser, visit http://website_one/ (not
http://localhost/website_one/!!)

Doing this with the loopback interface is something I've never
actually tried, but it should work.

HTH



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links