How to setup multiple websites on a virtualbox with apache?

问题描述 投票:0回答:0

我正在尝试设置多个网站,测试和运行,作为 Virtualbox 中的来宾在 ubuntu-server 22.04 中的子域。我安装了 apache2、php 和 mysql。然后我通过 NAT 调整 Virtualbox 以进行端口转发,并创建一个规则,其中主机端口为 8000,来宾端口为 80。然后我重新启动机器,可以在浏览器中使用 localhost:8000 访问 apache2 站点。 这就是我所期望的。现在我想配置两个子域。我创建了一个文件

website.conf
,里面有这段文字:

## 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>

并设置我的

/etc/apache2/apache2.conf

ServerName website.com

然后用systemctl重启apache。 之后,我在主机上配置

/etc/hosts

127.0.0.1:8000    website.com

现在我正在尝试通过浏览器访问网站。 我尝试 test.website.comlive.website.com,但都说 “找不到服务器” 当我尝试 localhost:8000 时,我到达了 test.website.com.

后面的站点

apache2ctl -t
产量:

“语法正确”

apache2ctl -S
产量:

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

如何启用两个子域?

apache ubuntu virtual-machine virtualbox virtualhost
© www.soinside.com 2019 - 2024. All rights reserved.