How to set-up my webserver properly on my local network?

16,444

Solution 1

There's two ways:

  1. Setup your own DNS and configure it.
  2. Add entries the hosts file on each file system you want to access the site.

I'm assuming that you can't change the DNS settings on your router and don't want to setup and configure Bind. To add entries to the hosts file, open up the file (/etc/hosts on Linux c:\windows\system32\drivers\etc\hosts on Window) and add lines like:

192.168.0.1  abp.bhc.com
192.168.0.1  wiki.bhc.com
192.168.0.1  server.bhc.com

Solution 2

If you don't have an internal dns server you can put the ip-adress from your server in the hosts file of all clients and the server like shf301 said. The apache have to be configured with virtual hosts like this:

NameVirtualHost *:80
<VirtualHost *:80>
   ServerAdmin [email protected]
   DocumentRoot c:/www/wiki
   ServerName wiki.bhc.com
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin [email protected]
  DocumentRoot c:/www/server
  ServerName server.bhc.com
</VirtualHost>

Documentation: apache virtual hosts

Share:
16,444

Related videos on Youtube

Arlen Beiler
Author by

Arlen Beiler

I like programming, astronomy, history, language, and music. Come unto me, all ye that labor and are heavy laden, and I will give you rest. Take my yoke upon you and learn of me for I am meek and lowly in heart and ye shall find rest unto your soul. For my yoke is easy and my burden is light.

Updated on September 17, 2022

Comments

  • Arlen Beiler
    Arlen Beiler over 1 year

    I have an intranet (inside the network) website, but it is somewhat of a pain. First of all, this is a home network, if that helps anyone. I have a computer running Apache web server with PHP, and I want to point 3 URLs on the local network to it. I have had some success, but it isn't always dependable. For DNS and DHCP I have a Thompson Speedtouch ST546 v6 DSL router.

    Edit: I need it for intranet websites, not just file hosting, as I do quite a bit with CMSs.


    Rewrite for clarity: I have a computer with three subdomains on the local network pointing to IP address 10.0.0.2, abp.bhc.com, wiki.bhc.com, and server.bhc.com, along with the webserver's personal dns name. I use the SpeedTouch for the DNS, and have complete control over it. It usually works, after I fiddle with it for an hour.

    My question is whether there is a more elegant solution than manually adding the domain each time I need another one. It usually seems to work, though.

    Here is my current VH file:

    NameVirtualHost 10.0.0.2
    
    <VirtualHost 10.0.0.2>
    ServerName abp.bhc.com
    DocumentRoot "htdocs/abp"
    </VirtualHost>
    <VirtualHost 10.0.0.2>
    ServerName server.bhc.com
    DocumentRoot "htdocs/server"
    </VirtualHost>
    <VirtualHost 10.0.0.2>
    ServerName wiki.bhc.com
    DocumentRoot "htdocs/wiki"
    Alias /wiki htdocs/wiki/wbhc/index.php
    </VirtualHost>
    

    Duh, I figured out my immediate problem. The IP Address was set wrong, apparantly because I recently got a new LAN adapter. My question about whether there is a better solution still stands.

    • Linker3000
      Linker3000 over 13 years
      What type of URLs - ones you can use on your internal network or public ones for the world at large?
    • Tamara Wijsman
      Tamara Wijsman over 13 years
      @ArlenBeiler: It's unclear what you have tried and what the exact problem is. What OS do you run?
    • Arlen Beiler
      Arlen Beiler over 13 years
      Just on the local network.
    • Tamara Wijsman
      Tamara Wijsman over 13 years
      @ArlenBeiler: It's still confusing. Is your rewrite the current configuration or is it how you want to have things? Can you give an examples with IP addresses to clarify what the domains are (supposed to) point at?
    • Tamara Wijsman
      Tamara Wijsman over 13 years
      "I have a computer with three subdomains on the local network pointing to IP address 10.0.0.2", how is that computer (the server?) pointing to that IP addreses? By a DNS server, by Hosts file or by VH file? Your other computers are not going to see it you only configure that computer, as they are set to request the router for DNS information which would probably forward the request to your ISP DNS...
    • Tamara Wijsman
      Tamara Wijsman over 13 years
      @ArlenBeiler: There doesn't exist any other solution to point 3 URLs on the local network to your server; you either configure it client-wise in the Hosts file or configure a DNS server that contains the address records. In either way, you will need to point the clients to your server (or your router if you can set address records there)...
    • Arlen Beiler
      Arlen Beiler over 13 years
      I know about all that and everything. I want to know if there is a better way than Telneting into the speedtouch and adding the subdomain like that. Is there a good DNS server that I can install on my computer that would do the trick? Or is this the best way? In other words, I have it working, but is there a better way?
    • Tamara Wijsman
      Tamara Wijsman over 13 years
      @ArlenBeiler: BIND is the De Facto Standard DNS, you could configure the address records there and set it to forward any unrecognized DNS requests to your router. Then, you could configure your server as the Primary DNS and your router as the Secondary DNS on the clients. This way, you only need to change the configuration on the server, instead of using telnet towards the router. But it's up to you if you want to spend the effort getting BIND working or one of the alternatives...
    • Tamara Wijsman
      Tamara Wijsman over 13 years
      @ArlenBeiler: You might find questions that help you on our sister site ServerFault, or get help regarding setting up BIND (or an alternative).
    • Tamara Wijsman
      Tamara Wijsman over 13 years
      Yeah, you've got a lot of similar answers at around the same time. I would suggest picking the most informative one...
    • Arlen Beiler
      Arlen Beiler over 13 years
      If you'd just put your above comment in an answer, that is the one I'd accept.
  • Arlen Beiler
    Arlen Beiler over 13 years
    That is working fine (or is it, maybe that's the problem!).
  • Chuck
    Chuck over 13 years
    You'll need an ip for each name you want to set up, unless you don't mind using other ports besides 80.
  • Tamara Wijsman
    Tamara Wijsman over 13 years
    He doesn't need that for an intranet (= local network) host.
  • Arlen Beiler
    Arlen Beiler over 13 years
    I am using virtual servers.
  • Arlen Beiler
    Arlen Beiler over 13 years
    I am using a static IP.
  • Arlen Beiler
    Arlen Beiler over 13 years
    Oops, kasterma, I just realized what you mean. I suppose I could, but I am looking for a bit more elegant solution.
  • Tamara Wijsman
    Tamara Wijsman over 13 years
    @ArlenBeiler: And the second part of the answer?
  • Arlen Beiler
    Arlen Beiler over 13 years
    The DNS is set on the SpeedTouch and it usually works.
  • DataWizard
    DataWizard over 13 years
    Oh, you're right. Silly me, I misread his question. Thanks. :)
  • Tamara Wijsman
    Tamara Wijsman over 13 years
    @ArlenBeiler: You've got to provide more detail if you want us to give you an appropriate answer, DNS is a way too broad topic to just say that it's set. As your SpeedTouch isn't a DNS server but rather a DNS forwarder my guess is that you have just configured the SpeedTouch to forward DNS requests to your ISP DNS, some routers allow to forward specific requests to internal domains though but it's unclear if your router does that...
  • Arlen Beiler
    Arlen Beiler over 13 years
    The SpeedTouch has its own DNS server, which I configured somewhat.
  • Arlen Beiler
    Arlen Beiler almost 13 years
    Well, I can change the DNS settings on my router, but I'm not sure about setting up BIND. I'll accept this one since option #1 is the most helpful.