How to configure the game in a subdirectory behind the reverse Apache proxy?

I have an Apache 2 interface that serves two types of requests:

  • Requests to the root folder (e.g. http://mysite.com/ and http://mysite.com/help ) are handled by apache itself (PHP / Wordpress).
  • Specific requests to the subfolder '/ playapp' are sent to Play! through reverse proxy through 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 playback server as http://localhost:9000/Controller/action

Now, play! the page serves 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 result

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

So, the end user is trying to retrieve http://mysite.com/public/stylesheets/style.css , which returns 404 because it is not part of the Play! attachment.

What is the right way to configure Apache + Play to play here?

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

Also, I need some connectivity outside of the Play app. For example, I want the home route (/) to be mapped to my absolute root ( http://mysite.com/ ), rather than root.

+6
source share
4 answers

First, something important: apache2 cannot (easily) change links on pages. So, Play should provide the right ones.

Using a subdomain will make all of this completely transparent, but will allow you to resolve your issue.

You really have two questions in your question,

Fix subfolders for static resources

Using newly established routes

GET / playapp / public / staticDir: public

Do you use http.path ?

I believe the opposite should take this into account.

external links

  • Also, I need some connectivity outside of the Play app. For example, I deleted the home route (/), which should be mapped to my absolute root (http://mysite.com/), and not to the root game.

Well, that sounds simple: if it is outside the game application, then you are not using the return URL, so just set the absolute path in your links ... or are you using the opposite? If so, can you give an example?

+3
source

You have configured application.conf using

 XForwardedSupport=127.0.0.1 

and your apache.conf

 ProxyPreserveHost on 

An alternative, if this does not work, refers to the previous post.

I believe that the answer I gave in this other post will be relevant to your situation.

How to use "war.context" in the Play Framework configuration file?

Basically, this means reading some value from the properties file and pre-expecting that value for all your routes. This is the recommended method for servlet deployment, where the path changes from the one that uses the default playback setting.

+1
source

It would be foolish to expect Apache to rewrite HTML, JS, and CSS files. What about SWF files or dynamically generated URLs in JS? In any case, you get my drift. The ProxyPassReverse documentation says:

Only the HTTP response headers mentioned above will be rewritten. Apache will not rewrite other response headers and will not rewrite URL links inside HTML pages. This means that if Proxy content contains absolute URLs, they will bypass proxies. A third-party module that will look inside HTML and rewrite URL links is Nick Kew mod_proxy_html.

As one of the suggested comments, the much more successful approach is to configure another DNS name (for example, play.ripper234.org) and create a configuration such as:

 <VirtualHost> ServerName play.ripper234.org ProxyPass / http://localhost:9000/ ProxyPassReverse / http://localhost:9000/ </VirtualHost> 

Even this did not β€œsave” you if the files were returned to Play! will use a fully qualified url like http: // localhost: 9000 / or http://www.yahoo.com/ or something else.

As in order to recommend you a different web server, I really think you should stick with Apache. It has a very reasonable and powerful configuration, and it is fast enough for all your needs. In general, Apache is not particularly slow. Web servers are better suited for embedded use, and there are web servers that are better suited to work with as many static pages as possible. You have nothing to worry about until you become really big.

+1
source

Play 1.x supports the setting of "http.path".

Playback of the 2.1 snapshot already supports the configuration of the application.context configuration to place the application context in a subdirectory.

Check out this commit:

Allow the root context with configuration [application.context].

0
source

Source: https://habr.com/ru/post/905068/


All Articles