Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Play on a sub-directory, behind an Apache reverse proxy?

I have an Apache 2 frontend, that serves two kinds of requests:

  • Requests to the root folder (e.g. http://mysite.com/ and http://mysite.com/help) are served by the apache itself (PHP/Wordpress).
  • Specific requests to the '/playapp' subfolder are forwarded to Play! via a reverse proxy via mod-proxy:

mod-proxy.conf

ProxyPass        /playapp/ http://localhost:9000/
ProxyPassReverse /playapp/ http://localhost:9000/

The end result is that requests to say http://mysite.com/playapp/Controller/action reach the Play server as http://localhost:9000/Controller/action

Now, Play! serves the page correctly, but all links, including javascript, css and links to other pages, are broken. For example, if a view uses:

#{stylesheet 'style.css' /}

Then the rendered result is

<link rel="stylesheet" type="text/css" href="/public/stylesheets/style.css" charset="utf-8" ></link>

So the end user tries to fetches http://mysite.com/public/stylesheets/style.css, which returns a 404 because it's not actually part of the Play! app.

What's the correct way to configure Apache + Play to play along here?

The result I'm looking for is for Play! to return URLs such as this in the final rendered HTML (or perhaps for Apache to rewrite the URLs accordingly): http://mysite.com/playapp/public/stylesheets/style.css

Also, I do need some ability to link outside of the Play app. For example, I want the home route (/) to be mapped to my absolute root (http://mysite.com/), not to Play's root.

like image 974
ripper234 Avatar asked Jan 04 '12 09:01

ripper234


1 Answers

First, something important: apache2 can't (easily) change links in the pages. So Play must provide the right ones already.

Using subdomain will make all of this completely transparent, but let's tackle your question.

You really have two points in your question,

Fix subfolders for static resources

  • The result I'm looking for is for Play! to return URLs such as this in the final rendered HTML (or perhaps for Apache to rewrite the URLs accordingly): http://mysite.com/playapp/public/stylesheets/style.css

Using routes just set

GET /playapp/public/ staticDir:public

Are you using http.path ?

I think reverse should take it into account....

outside links

  • Also, I do need some ability to link outside of the Play app. For example, I wan the home route (/) to be mapped to my absolute root (http://mysite.com/), not to Play's root.

Well this sounds easy: if it's outside the play app then you are not using a reverse url, so just put the absolute path in your links... or are you using a reverse? If so, can you provide an example?

like image 107
Stefano Avatar answered Sep 22 '22 11:09

Stefano