apacheraspberry-pihostapd

RaspberryPi as hotspot without internet accessed via a domain name


I have a RPi set up as a hotspot (hostapd) that I use to access a web server set up on the RPi.

This RPi is not connected to the internet, it's just to serve some local pages.

I have Apache installed and so I can easily access it via a browser with the address http://192.168.42.1

The question is how can I use a domain to access it instead?

say I want to connect to the WiFi of the RPi (losing my internet connection) then on my browser go to http://example.com and load/redirect me to http://192.168.42.1 instead.


Solution

  • You can add a hosts entry in the device from which you want to access your raspberry pi using a domain. Let us assume your Pi's IP is 192.168.1.69 assuming the domain you want to use is local-pi.com Example: In an ubuntu based system: add the following lint to your /etc/hosts file:

    192.168.1.69       local-pi.com
    

    In a windows based system add the following line to your C:\Windows\System32\Drivers\etc\hosts file:

    192.168.1.69       local-pi.com
    

    In the apache server configuration of your pi add the following line:

    ServerAlias       local-pi.com