2

I currently have multiple websites set up with the standard Apache virtual host configuration.

My question is how do I set up multiple websites built using Opa so that they run like they would with to with Apache virtual hosts.

ex. When a user types in www.example1.com the server redirects the user to OpaApp1 OR When a user types in www.example2.com the server redirects the user to OpaApp2

2 Answers2

1

You can recover the requested host with HttpRequest.get_host().

A sample app :

OpaApp1 = {{
  start(uri) = Resource.html("Hello", <>World 1</>)
}}

OpaApp2 = {{
  start(uri) = Resource.html("Hello", <>World 2</>)
}}

@server
start(uri:Uri.relative) =
  match HttpRequest.get_host()
  {some={some="www.example1.com"}} -> OpaApp1.start(uri)
  {some={some="www.example2.com"}} -> OpaApp2.start(uri)
  _ -> Resource.error_page("Error", <>Bad gateway</>, {bad_gateway}) // default

server = Server.simple_dispatch(start)
Fred
  • 1,092
  • 5
  • 9
  • Thanks, Does this mean I can compile OpaApp1.opa, OpaApp2.opa, and SomeRequestRedirectionApp.opa separately? Then as I add more OpaAppX.opa websites could I simply add a small addition to SomeRequestRedirectionApp.opa? – BrianTMaurer Dec 19 '11 at 06:50
  • No you have to compile it into one single binary. You can make different packages (for every apps), but it must in the end, end up in one binary. – Fred Dec 19 '11 at 21:58
  • Otherwise, i recommend using a load balancer like [nginx](http://www.nginx.com/) in front of your different web apps, and load balance them with nginx. This is a good solution because Opa is not multi-threaded (yet), so you will take advantage of your multi-core processor if you have one. – Fred Dec 19 '11 at 22:02
0

I'm no Apache guru, but I suppose you can configure different domains for different ports in which case you can run different Opa apps on different ports (--port switch). That may be more modular than just having one global app.

akoprowski
  • 3,297
  • 1
  • 18
  • 26