I like to set up apache2 on my RPi4 to serve a couple of named sites, but the howto:s I have found state that I must do the following to access them:
- Create the virtual host configs in sites-available and enable them in apache, then restart apache. (Check)
- Edit the /etc/hosts file to include an entry for the virtual hosts with the IP address set to the RPi IP address (Check?)
- If the sites are accessed from other devices, edit the hosts file also on them to suit. (???)
The problem with this is the need to edit the hosts file, especially on devices like phones and tablets (not available for editing).
Question
Is there some workaround for this or am I hosed?
I do not want to mess with dynamic dns systems or the like, makes it hard to maintain on multiple RPi:s.
Workaround?
Maybe the only way is to not use multiple virtual hosts but instead create a couple of webroot level directories, one per site, on a single host....
That would mean something like:
Code: Select all
/var/www/mysite.tst/public_html/site1
/var/www/mysite.tst/public_html/site2
/var/www/mysite.tst/public_html/site3This would be the only host running so the sites are accessed via url:s like http://<rpi-address>/site2/
I.e. all using the same IP address....
PS:
I have read that one should avoid using /var/www/html as the base directory since it is likely going to be modified if apache2 updates.
So therefore I have suggested the /var/www/mysite.txt dir above.
DS