You can do virtual hosting on backend and configure reverse proxy. No need to setup cname. Just set abc.example.com and xyz.example.com to 222.111.123.1 and you are done.
Code:
upstream abcexamplecom {
server 192.168.1.2 weight=5 max_fails=2 fail_timeout=10s;
server 192.168.1.3 weight=5 max_fails=2 fail_timeout=10s;
}
upstream xyzexamplecom {
server 192.168.1.2:88 weight=5 max_fails=2 fail_timeout=10s;
#server 192.168.1.3:88 weight=5 max_fails=2 fail_timeout=10s;
}
server {
server_name abc.example.com;
location / {
proxy_pass http://abcexamplecom;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_cache cache;
proxy_cache_valid 200 24h;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_ignore_headers Expires Cache-Control;
proxy_redirect off;
proxy_buffering on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
server_name xyz.example.com;
location / {
proxy_pass http://xyzexamplecom;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_cache cache;
proxy_cache_valid 200 24h;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_ignore_headers Expires Cache-Control;
proxy_redirect off;
proxy_buffering on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Note proxy_set_header will pass actual virtual host name to Apache. Next, you configure apache as usual on port 80 and 88 for two web sites with two different DocumentRoot and log files. However, for ssl you must use 2 unique ips. For http port 80 you can host 100s of website using above technique. The example are nginx reverse proxy specific but applies to any other reverse proxy software out there.