1

I have a webserver on my RaspberryPi with apache2. I can browse the website with pi's local IP address like 192.168.x.x. I want to browse it without IP in my LAN like, http://local.mypi.com.

How can I do it? Thanks

2
  • 1
    Unless the website is externally reachable https is going to be difficult. Moreso if you dont control the mypi.com. Is accessing it over http an option, and is this all "lan only"? Also, what model router do you have/how is your dns configured?
    – davidgo
    Commented Jan 3, 2022 at 7:41
  • http is an option. Model of router will be varied because I will use the Pi at lots of network but it is still lan only. Let me edit my question for http then. Commented Jan 4, 2022 at 7:21

1 Answer 1

1

In order to browse by domain name rather then IP address, 2 things need to happen -

  1. You need a way to resolve the domain name and
  2. Your web server needs to respond with the correct config.

(I've not discussed HTTPS here, as this would seem entirely impractical).

Resolving the domain name

How you resolve the domain name will depend on your setup. The easiest way is to modify the "hosts" file on the computers that will need to access the site. (Almost all OS's have a hosts file). You need administrator privileges, and add a line like

  192.168.x.x   local.mypi.com

There are other ways to achieve this, however they are dependent on the network and devices. Sometimes (rarely) you can assign computer names on the router, and on more advanced routers you can sometimes modify the DNS configuration.

Another solution would be to run a DNS server on the Pi. The problem with this is that you will need to get clients to use the Pi's DNS server, and this could mean running a DHCP server and disabling the one on the router.

If you are only looking at Linux and Mac devices (ie not Windows), you may be able to use a "Zeroconf" implentation on your Pi. Configuring the web server

There are 2 modes for HTTP on Apache - name based and IP based. If you use IP based configuration you can only run set of websites. Name based virtual hosting will allow you to run multiple websites, but you will need to specify a different config for each. Name based virtual hosting is more common.

If you are using IP based virtual hosting you don't need to worry about domain to IP address mapping on the server - the server does not care about the domain name used.

If you are using name based virtual hosting you will need to add configuration for your domain name like the following to your apache config

 <VirtualHost *:80>
 ServerName local.mypi.com
 DocumentRoot "/path/to/websitefiles"
 </VirtualHost>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .