Setup a VirtualHost on the Pi
http://httpd.apache.org/docs/2.4/vhosts/
We'll create a website named joebob.com
We must first setup the virtual host on the Pi, then define the hostname on the machine we'll load it from (Windows)
On the Pi
-
We'll use
geditinstead ofvias a text editor.
You can use either, just substitue one for the other or installgedit$ sudo apt install gedit
-
Navigate to
/var/www/htmland create a new directory namedvhosts:
If it doesn't already exist$ sudo mkdir /var/www/html/vhosts -
Create a new directory within the
vhostsdirectory-- enter the vhosts directory $ cd /var/www/html/vhosts -- create a new sub-directory $ sudo mkdir joebob.com -
Create a new
index.htmlfile within the new directory
...and add this to the file:-- enter the joebob.com directory $ cd joebob.com -- create a new file $ sudo touch index.html -- open the file in an editor (in our case gedit - cuz vi sux) $ sudo gedit index.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hosted!</title> </head> <body> <h1>This is a hosted site</h1> </bodyv </html> -
Create a new
.conffile in the/etc/apache2/sites-availabledirectory by copying the default one in there:-- change to the sites-available directory $ sudo cd /etc/apache2/sites-available -- copy the file $ sudo cp 000-default.conf joebob.com.conf -
Edit the file that was just created:
and define the following:$ sudo gedit joebob.com.conf... ServerName joebob.com ServerAlias www.joebob.com -- optional ServerAdmin wemaster@joebob.com -- optional DocumentRoot /var/www/html/vhosts/joebob.com/ ... -
Activate the host by running the apache command:
$ sudo a2ensite joebob.com -
Reload the apache server:
$ sudo systemctl reload apache2
On Windows
Navigate to C:/Windows/System32/drivers/etc and edit the hosts file
Add the IP and domain name to the end of the file
...
10.163.37.227 joebob.com