简体   繁体   中英

Apache2: Hosting Multiple Sites (Ubuntu Server

I am new working with system.d and services on ubuntu/debian. I'm trying to serve multiple sites on the same 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

I need to configure three instances of server to listen on ports 8081, 8082, and 8083 respectively. For example, on visiting h ttp://host1.com:8081, http://host2.com:8082 and http://host3.com:8083 the HTML pages are in var /var/mysites/host1/index.html , /var/mysites/host2/index.html and /var/mysites/host3/index.html respectively should be rendered by default. Also, we should be able to start, to stop and restart the apache serer using the following commands:

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;

To test my instances, it was required these conditions:

The Apache2 webserver installation is verified by running the dpkg --get-selections | grep apache2 dpkg --get-selections | grep apache2 command.

The server instances are started by running sudo apache2ctl-host1 start ; sudo apache2ctl-host2 start; sudo apache2ctl-host3 start ;

The port is verified by running the sudo lsof -i:8081 | grep apache2 sudo lsof -i:8081 | grep apache2 , sudo lsof -i:8082 | grep apache2 sudo lsof -i:8082 | grep apache2 and sudo lsof -i:8083 | grep apache2 sudo lsof -i:8083 | grep apache2 commands.

Th HTML conted is fetched by running the curl host1.com:8081,curl host2.com:8082 and curl host3.com:8083 commands.

The page must not be a 403 or 404 error page, ie., the following commands must exit with non-zero code:

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

Also, the HTML files /var/save/mysites/host1/index.html , /var/save/mysites/host2/index.html and /var/save/mysites/host3/index.html and the rendered HTML files snhoud be exactly same.

You should just use one apache and configure it to listen on 3 (or more) different ports using the "listen" option:

Listen 10080
Listen 10443
Listen 20080
Listen 20443

Then you can configure any virtualhost you need, to respond on a specific port:

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

More details and configuration options can be found on the official documentation: https://httpd.apache.org/docs/2.4/vhosts/examples.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM