# Multiple Apache / Tomcat Instances each in its own Jail



## cmon (May 4, 2010)

Hi everyone,

i'm trying to setup 2 or 3 apache instances on my server. i want them to be available to the outside on urls like
dev.mydomain.com
test.mydomain.com
prod.mydomain.com
this already implies that they should all run on the default port and access shall be routed by the third-level-domain, since i have only one public ip.

now i think that should be possible by using jails (i already set up two jails with ezjail).

my question is now, where does the routing of the third-level domain happen? is it possible at all? Each jail has its internal IP (127.0.0.20, 127.0.0.30) and its hostname (dev, prod), but where is the connection between the hostname and the IP? do i have to set up that routing myself? do i have to use pf?

since i actually want to forward the requests from apache to tomcat, it would be an alternative for me to have one apache instance with several virtual hosts that point to the different tomcat instances in jails (with different ports, if needed), but if it is possible to have multiple apache instances made available on different thirdleveldomains, it would be my preferred way to do it...

has anyone experience in such a setup? help is much appreciated!

cheers simon


----------



## SirDice (May 4, 2010)

cmon said:
			
		

> my question is now, where does the routing of the third-level domain happen? is it possible at all? Each jail has its internal IP (127.0.0.20, 127.0.0.30) and its hostname (dev, prod), but where is the connection between the hostname and the IP? do i have to set up that routing myself? do i have to use pf?


Normally you would use port forwarding to forward port 80 to the internal IP address. Since you have multiple domains that need to be routed to different servers you would need a proxy and split the traffic according to the HTTP/1.1 Host: header.


----------



## cmon (May 4, 2010)

Thank you for your answer!
do you happen to know how i setup such a proxy?  and if possible, is there a proxy that routes all requests to an internal server depending on the thirdlevel domain (e.g not only on port 80)? i intend to install a postgres instance in each jail as well, and when i connect to the databases from outside, it would be nice if i could just alter the servername (dev.mydomain.com:5432, prod.mydomain.com:5432 etc.)


----------



## SirDice (May 4, 2010)

The proxy works on layer 7 and is only able to handle HTTP(S) requests. It works by looking at the HTTP/1.1 Host: header. Postgresql doesn't use HTTP so it cannot work in a similar fashion.


----------



## cmon (May 4, 2010)

thank you for the info!

i managed to get it running now. I installed nginx on the host for proxying. it routes requests to the appropriate server in its jail (for now apaches, will change that to tomcat directly, since the additional apaches would be overhead).

i guess i have to settle with different ports for the databases in the jails, or does anyone have a better idea? (i need to administer them from outside also...)

anyway, here the relevant snippet of my nginx.conf, if anyone is interested...



http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  prod.yourdomain.com http://www.yourdomain.com yourdomain.com;

        #charset koi8-r;

        access_log  /var/log/nginx_prod.access.log;

        location / {
                proxy_pass      http://127.0.0.30:80;
        }
    }

    server {
        listen       80;
        server_name  dev.yourdomain.com;
        access_log   /var/log/nginx_dev.access.log;
        location / {
                proxy_pass      http://127.0.0.20:80;
        }
    }

}


Cheers again, simon


----------

