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):

enter image description here

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:

enter image description here

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 [email protected]
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

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

<VirtualHost *:80>
ServerAdmin [email protected]
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

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.

  • Thanks for formatting the code! Could you please also edit your question to let us know the URL that produced the 404 message?
    – Bob Brown
    Feb 12, 2020 at 23:25
  • I tried accessing the pages from my both my public IP address & my Pi 4 IP address as to why I've masked the actual URL. Feb 12, 2020 at 23:42
  • 1
    Well, you only masked it in one place. Might want to visit that image again. If you didn't include a host name in the URL, Apache can't pick a configuration file.
    – Bob Brown
    Feb 12, 2020 at 23:45
  • "I haven't set my DNS records for my real website domains yet" - so, how do you expect your webserver to know whenever it should serve Website1 or Website2 if the request is for Feb 13, 2020 at 8:13
  • What's in /var/log/apache2/error.log?
    – Dougie
    Feb 13, 2020 at 9:29

2 Answers 2


Virtual hosts depend upon a host name in the HTTP/1.1 Host: header, and so probably cannot be made to work without those DNS entries. The browser determines the host name from the URL and sets up the correct Host: header. Apache uses that header to select the correct virtual host. Based on the comments, you got the 404 error because you also disabled the default page. No default, no Host: header, 404.

For testing, you could edit the hosts file of the computer that's running the web browser rather than enabling the DNS, or just turn DNS on and See What Happens™.

On Win10, the hosts file is located here: C:\Windows\System32\drivers\etc\hosts Don't forget to remove those entries when you're done testing.

Also, I don't see in your question that you've enabled the sites. Use a2ensite Website1.com (Assuming that the configuration file is Website1.com.conf) Once the sites are enabled, you must restart Apache with sudo systemctl restart apache2

Also, I believe it's good practice to use all lowercase in those file names. DNS will resolve host names in a case-insensitive manner, and Apache will treat them that way, but I'd worry that something else might break since the file system is not case-insensitive. (Fix the DNS first.)

  • I thought that I would have to edit the Hosts file in my Raspberry Pi versus on Windows since I've installed the LAMP stack server on my Pi 4. Is this correct? Feb 12, 2020 at 23:30
  • Edit the hosts file on the computer running the web browser, not the web server. That's how the name will get in the HTTP header. (And, if my answer actually corrects the problem, please don't forget to accept it; that keeps it from popping up seeking more answers.)
    – Bob Brown
    Feb 12, 2020 at 23:32
  • Yes, I have already enabled both sites using "a2ensite" & restarted Apache. I've also disabled the default 000 file as well. Feb 12, 2020 at 23:46
  • Aha! If you disabled the default, and there's no host name in the header to select a virtual site, you get a 404!
    – Bob Brown
    Feb 12, 2020 at 23:47
  • So do I need to re-enable the 000 default using sudo a2ensite? Also, when testing on my localhost, do I test through my Pi's IP address, public IP address, or do I just enter in the exact domain names for testing, and it will show the test sites on my localhost from the Virtual Hosts configurations? Feb 12, 2020 at 23:52

Okay, so now I figured out with the problem was. I've done EVERYTHING RIGHT, EXCEPT for having the proper permissions on the directories to enable or disable these sites. I have my permissions all messed up. Thanks for your support, Bob. I can totally understand why it would have been too difficult to pinpoint such an issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.