AaronEsteban
Posts: 16
Joined: Fri Jan 31, 2020 7:12 pm

Hosting Multiple Websites on RPi 4 - Help Needed

Wed Feb 12, 2020 9:51 pm

So I've already set everything as for port forwarding in my router settings, I've set a static IP address for the RRi 4, and have already managed to get 1 page visible through my Pi web server.

The problem began when I went to set up the "Virtual Host" files in Apache2 to point to each domain that I plan on hosting on the RPi 4. Now no page shows, and the message I keep seeing says the following:

"404 Not Found
The requested URL was not found on this server.

Apache/2.4.38 (Raspbian) Server at MY-PUBLIC-IP-ADDRESS-HERE Port 80"


As shown in the image below (404 message):
Image


I have website1.com inside of "/var/www/website1.com/public_html/index.php"
and I have website2.com inside of "/var/www/website2.com/public_html/index.php"

My Apache2 folder inside of directory "/etc/apache2/" looks like this:

Image


And here is how I've set up my Virtual Host file (for website1.com) inside the directory "/etc/apache2/sites-available/Website1.com.conf":

"<VirtualHost *:80>
ServerAdmin admin@Website1.com
ServerName Website1.com
ServerAlias www.Website1.com
DocumentRoot /var/www/Website1/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>"


AND the other file is a duplicate for website2.com inside of directory "/etc/apache2/sites-available/Website1.com.conf":


"<VirtualHost *:80>
ServerAdmin admin@Website2.com
ServerName Website2.com
ServerAlias www.Website2.com
DocumentRoot /var/www/Website2/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>"



I haven't set my DNS records for my real website domains yet, but as far as I remember, I should have been able to test on my localhost or check through my public IP address that is forwarding to my RPi 4 IP address to preview these 2 separate domains/websites.

Does it look like I've structured the Apache Virtual Hosts properly? Thanks.

knute
Posts: 589
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Hosting Multiple Websites on RPi 4 - Help Needed

Thu Feb 13, 2020 3:42 am

AaronEsteban wrote:
Wed Feb 12, 2020 9:51 pm
I have website1.com inside of "/var/www/website1.com/public_html/index.php"
and I have website2.com inside of "/var/www/website2.com/public_html/index.php"


"<VirtualHost *:80>
ServerAdmin admin@Website1.com
ServerName Website1.com
ServerAlias www.Website1.com
DocumentRoot /var/www/Website1/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>"


AND the other file is a duplicate for website2.com inside of directory "/etc/apache2/sites-available/Website1.com.conf":


"<VirtualHost *:80>
ServerAdmin admin@Website2.com
ServerName Website2.com
ServerAlias www.Website2.com
DocumentRoot /var/www/Website2/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>"
You have to put your HTML files in the directory that you specify in DocumentRoot and yours don't match. I wouldn't use a name like website1.com and I wouldn't mix case on names either.

When you open your browser it needs to be able to resolve the website name, Website1.com, to your address. If it doesn't it isn't going to find it.

User avatar
Skraaj
Posts: 29
Joined: Wed Nov 20, 2019 11:35 pm
Contact: Website

Re: Hosting Multiple Websites on RPi 4 - Help Needed

Thu Feb 13, 2020 8:35 pm

I had a similar problem. You have to modify hosts file of the pc you are accessing the server with. It needs to resolve website1.com and website2.com to the same ip.

If you set up your dns it should work properly.
codedoneright.eu – newbie friendly raspberry tutorials

AaronEsteban
Posts: 16
Joined: Fri Jan 31, 2020 7:12 pm

Re: Hosting Multiple Websites on RPi 4 - Help Needed

Thu Feb 13, 2020 8:40 pm

Yes, you are right. Host file on Windows ( or whichever OS you are testing on) should be edited to match websites & IP.

I've already resolved the issue last night. I did EVERYTHING CORRECTLY, except I wasnt using proper "superuser" permissions to enable the sites & restarting Apache.

Thanks for your share though. You are right.

Skraaj wrote:
Thu Feb 13, 2020 8:35 pm
I had a similar problem. You have to modify hosts file of the pc you are accessing the server with. It needs to resolve website1.com and website2.com to the same ip.

If you set up your dns it should work properly.

Return to “Networking and servers”