Posts Tagged ‘content based routing’

Configure Apache2 and NginX as Content based router

Content based routing is to send received request to particular destination depending on the request content. The configuration bellow will be using a custom HTTP header as the content to decide the destination

Apache2

Create a file named a2cbr in /etc/apache2/sites-available, and copy the following content to a file named a2cbr

<VirtualHost *:10000>
    ServerName localhost
    ProxyRequests Off
    RewriteEngine On

    <Directory>
        AllowOverride All
        <Limit GET HEAD POST PUT DELETE OPTIONS>
        Order Allow,Deny
        Allow from all
        </Limit>
    </Directory>

    RewriteCond %{HTTP:routing} xadmin
    RewriteRule ^/a2cbr(.*) http://localhost:9000/service/EchoService [P]
</VirtualHost>

NginX

Create a file named nginxcbr in /etc/nginx/sites-available, and copy the following content to a file named nginxcbr

server {
   listen *:15000;
   server_name localhost;

   location  / {
       if ($http_routing ~ 'xadmin') {
          rewrite ^/nginxcbr(.*) /service/EchoService;
           proxy_pass http://localhost:9000;
       }
    }
}
<pre>
Advertisements