I have Apache installed on an Ubuntu virtual machine.
Typing http://localhost
in the browser brings up the Apache intro site, so I know Apache works.
I created the file /home/test/webs/testapp/index.html
:
This is a <b>test</b>.
I created the file /etc/apache2/sites-available/testapp.conf
:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName testapp
ServerAlias testapp
DocumentRoot /home/test/webs/testapp
<Directory /home/test/webs/testapp>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I enabled the virtual host:
sudo a2ensite testapp.conf
I restarted the Apache server:
systemctl reload apache2
But when I go to http://localhost/testapp
, Apache responds:
Not Found
The requested URL was not found on this server. Apache/2.4.41 (Ubuntu)
Server at localhost Port 80
What else do I have to do to get my virtual host to work on Ubuntu?
In your config file you have:
But in your URL you are using:
You will need your DNS server to map
testapp
to the IP address of your server. Or, edit your/etc/hosts
file, adding a line such as:Replace 127.0.0.1 with your server's IP address if you are trying to reach it from a different machine.
Then, you can access the host using the url
http://testapp
If you want to access the site using
http://localhost/testapp
, you don't need to do any of this. Instead, you can just use the default virtualhost.