ubuntu – How to setup multiple websites on a virtualbox with apache?
I am trying to set up multiple websites, test and live, as subdomains in a ubuntu-server 22.04 as guest in a Virtualbox. I installed apache2, php and mysql. Then i adjust the Virtualbox via NAT for port forwarding and create a rule where host port is 8000 and guest port is 80. then i restart the machine and can reach the apache2 site in the browser with localhost:8000.
That is what i expected. Now i wish to configure two subdomains. I create a file website.conf with this text inside:
## Test
<VirtualHost *:80>
DocumentRoot /var/www/html/test/
ServerName test.website.com
</VirtualHost>
## Live
<VirtualHost *:80>
DocumentRoot /var/www/html/live
ServerName live.website.com
</VirtualHost>
And set my /etc/apache2/apache2.conf
ServerName website.com
Then restart apache with systemctl.
After that, i configure /etc/hosts on the host
127.0.0.1:8000 website.com
Now i am trying to reach the websites via the browser.
I try test.website.com and live.website.com, but both say
“Server not found”
When i try localhost:8000 i get to the site behind test.website.com.
apache2ctl -t yields:
“Syntax OK”
apache2ctl -S yields:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server test.website.com (/etc/apache2/sites-enabled/website.conf:2)
port 80 namevhost test.website.com (/etc/apache2/sites-enabled/website.conf:2)
port 80 namevhost live.website.com (/etc/apache2/sites-enabled/website.conf:8)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
How can I enable both Subdomains?
Read more here: Source link
