我是在 ubuntu/debian 上使用 system.d 和服务的新手。我正在尝试在同一个 Apache2 上为多个站点提供服务。
viktor@viktor-i7-7700k:~$ ls -la /etc/apache2/
total 96
drwxr-xr-x 8 root root 4096 fev 3 16:13 .
drwxr-xr-x 133 root root 12288 fev 3 16:13 ..
-rw-r--r-- 1 root root 7224 ago 12 18:33 apache2.conf
drwxr-xr-x 2 root root 4096 fev 3 16:13 conf-available
drwxr-xr-x 2 root root 4096 fev 3 16:13 conf-enabled
-rw-r--r-- 1 root root 1782 jul 16 2019 envvars
-rw-r--r-- 1 root root 31063 jul 16 2019 magic
drwxr-xr-x 2 root root 12288 fev 3 16:13 mods-available
drwxr-xr-x 2 root root 4096 fev 3 16:13 mods-enabled
-rw-r--r-- 1 root root 320 jul 16 2019 ports.conf
drwxr-xr-x 2 root root 4096 fev 3 16:13 sites-available
drwxr-xr-x 2 root root 4096 fev 3 16:13 sites-enabled
我需要配置三个server实例分别监听8081、8082、8083端口。例如,在访问 http://host1.com:8081, http://host2.com:8082
和 http://host3.com:8083
时,HTML 页面位于 var /var/mysites/host1/index.html
中,默认情况下应分别呈现 /var/mysites/host2/index.html
和 /var/mysites/host3/index.html
。此外,我们应该能够使用以下命令启动、停止和重新启动 apache serer:
sudo apache2ctl-host1 start; sudo apache2ctl-host2 start; sudo apache2ctl-host1 start;
sudo apache2ctl-host1 stop; sudo apache2ctl-host2 stop; sudo apache2ctl-host1 stop;
sudo apache2ctl-host1 restart; sudo apache2ctl-host2 restart; sudo apache2ctl-host1 restart;
要测试我的实例,需要满足以下条件:
通过运行 dpkg --get-selections | grep apache2
命令验证 Apache2 网络服务器安装。
通过运行 sudo apache2ctl-host1 start
来启动服务器实例;须藤 apache2ctl-host2 开始; sudo apache2ctl-host3 start
;
通过运行 sudo lsof -i:8081 | grep apache2
、sudo lsof -i:8082 | grep apache2
和 sudo lsof -i:8083 | grep apache2
命令验证端口。
通过运行 curl host1.com:8081,curl host2.com:8082 and curl host3.com:8083
命令获取继续的 HTML。
页面不能是 403 或 404 错误页面,即以下命令必须以非零代码退出:
curl host1.com:8081 | grep 403\ Forbidden
curl host1.com:8082 | grep 403\ Forbidden
curl host1.com:8083 | grep 403\ Forbidden
curl host1.com:8081 | grep 404\ Not \ Found
curl host1.com:8082 | grep 404\ Not \ Found
curl host3.com:8083 | grep 404\ Not \ Found
此外,HTML 文件 /var/save/mysites/host1/index.html
、/var/save/mysites/host2/index.html
和 /var/save/mysites/host3/index.html
与呈现的 HTML 文件应该完全相同。
答案 0 :(得分:0)
您应该只使用一个 apache 并使用“listen”选项将其配置为侦听 3 个(或更多)不同的端口:
Listen 10080
Listen 10443
Listen 20080
Listen 20443
然后您可以配置您需要的任何虚拟主机,以在特定端口上响应:
<Virtualhost *:10080>
ServerName aDomain.com
#Other conf
</virtualhost>
<Virtualhost *:10443>
ServerName anotherDomain.com
#Other conf
</virtualhost>
<Virtualhost *:20080>
ServerName aThirdOne.Domain.io
#Other conf
</virtualhost>
<Virtualhost *:20443>
ServerName another.Domainof.any.kind
#Other conf
</virtualhost>
更多详细信息和配置选项可以在官方文档中找到:https://httpd.apache.org/docs/2.4/vhosts/examples.html