Play Proxy

Setting up a front end HTTP server – Play Framework

Home
Working with Play
Common topics
Deploying your application
You can easily deploy your application as a stand-alone server by setting the application HTTP port to 80:
$ /path/to/bin/ Note: you probably need root permissions to bind a process on this port.
However, if you plan to host several applications in the same server or load balance several instances of your application for scalability or fault tolerance, you can use a front end HTTP server.
Note that using a front end HTTP server will rarely give you better performance than using Play server directly. However, HTTP servers are very good at handling HTTPS, conditional GET requests and static assets, and many services assume a front end HTTP server is part of your architecture. §Set up with ligd
This example shows you how to configure ligd as a front end web server. Note that you can do the same with Apache, but if you only need virtual hosting or load balancing, ligd is a very good choice and much easier to configure.
The /etc/ligd/ file should define configuration like this:
dules = (
“mod_access”,
“mod_proxy”,
“mod_accesslog”)
$HTTP[“host”] =~ ” {
lance = “round-robin” = ( “/” =>
( ( “host” => “127. 0. 1”, “port” => 9000)))}
lance = “round-robin” = ( “/” => (
( “host” => “127. 1”, “port” => 9001),
( “host” => “127. 1”, “port” => 9002)))}
See ligd’s documentation for more details about how to configure mod_proxy. §Set up with nginx
This example shows you how to configure nginx as a front end web server. Note that you can do the same with Apache, but if you only need virtual hosting or load balancing, nginx is a very good choice and much easier to configure.
Note: nginx has extensive documentation about how to configure it as a load balancer. See the HTTP Load Balance Guide for detailed information.
The /etc/nginx/ file should define upstream and server block like this:
upstream playapp {
server 127. 1:9000;}
server {
listen 80;
server_name location / {
proxy_pass playapp;}}
For more details, see a full example configuration, and if you want to use nginx to do SSL termination, see the documentation here.
Note: make sure you are using version 1. 2 or greater of Nginx otherwise chunked responses won’t work properly.
§Set up with Apache
The example below shows a simple set up with Apache d server running in front of a standard Play configuration.
LoadModule proxy_module modules/


ProxyPreserveHost On
ServerName ProxyPass /excluded!
ProxyPass / ProxyPassReverse /

§Advanced proxy settings
When using an HTTP frontal server, request addresses are seen as coming from the HTTP server. In a usual set-up, where you both have the Play app and the proxy running on the same machine, the Play app will see the requests coming from 127. 1.
Proxy servers can add a specific header to the request to tell the proxied application where the request came from. Most web servers will add an X-Forwarded-For header with the remote client IP address as first argument. If the proxy server is running on localhost and connecting from 127. 1, Play will trust its X-Forwarded-For header.
However, the host header is untouched, it’ll remain issued by the proxy. If you use Apache 2. x, you can add a directive like:
ProxyPreserveHost on
The Host header will be the original host request header issued by the client. By combining theses two techniques, your app will appear to be directly exposed.
If you don’t want this play app to occupy the whole root, add an exclusion directive to the proxy config:
ProxyPass /excluded!
§Apache as a front proxy to allow transparent upgrade of your application
The basic idea is to run two Play instances of your web application and let the front-end proxy load-balance them. In case one is not available, it will forward all the requests to the available one.
Let’s start the same Play application two times: one on port 9999 and one on port 9998.
start
Now, let’s configure our Apache web server to have a load balancer. In Apache, add the following configuration:

ServerName

SetHandler balancer-manager
Order Deny, Allow
Deny from all
Allow from.


BalancerMember localhost:9999
BalancerMember localhost:9998 status=+H


Order Allow, Deny
Allow From All
ProxyPass /balancer-manager!
ProxyPass / balancermycluster/
ProxyPassReverse / balancermycluster/

The important part is balancermycluster. This declares a load balancer. The +H option means that the second Play application is on standby. But you can also instruct it to load balance.
Apache also provides a way to view the status of your cluster. Simply point your browser to /balancer-manager to view the current status of your clusters.
Because Play is completely stateless you don’t have to manage sessions between the 2 clusters. You can actually easily scale to more than 2 Play instances.
To use WebSockets, you must use mod_proxy_wstunnel, which was introduced in Apache 2. 4.
Note that ProxyPassReverse might rewrite incorrectly headers adding an extra / to the URIs, so you may wish to use this workaround:
ProxyPassReverse / localhost:9999
ProxyPassReverse / localhost:9998
§Configuring trusted proxies
Play supports various forwarded headers used by proxies to indicate the incoming IP address and protocol of requests. Play uses this configuration to calculate the correct value for the remoteAddress and secure fields of RequestHeader.
It is trivial for an HTTP client, whether it’s a browser or other client, to forge forwarded headers, thereby spoofing the IP address and protocol that Play reports, consequently, Play needs to know which proxies are trusted. Play provides a configuration option to configure a list of trusted proxies, and will validate the incoming forwarded headers to verify that they are trusted, taking the first untrusted IP address that it finds as the reported user remote address (or the last IP address if all proxies are trusted. )
To configure the list of trusted proxies, you can configure This takes a list of IP address or CIDR subnet ranges. Both IPv4 and IPv6 are supported. For example:
[“192. 168. 0/24”, “::1”, “127. 1”]
This says all IP addresses that start with 192. 0, as well as the IPv6 and IPv4 loopback addresses, are trusted. By default, Play will just trust the loopback address, that is::1 and 127. 1. §Trusting all proxies
Many cloud providers, most notably AWS, provide no guarantees for which IP addresses their load balancer proxies will use. Consequently, the only way to support forwarded headers with these services is to trust all IP addresses. This can be done by configuring the trusted proxies like so:
[“0. 0/0”, “::/0”]
Play supports two different versions of forwarded headers:
the legacy method with X-Forwarded headers
the RFC 7239 with Forwarded headers
This is configured using, with valid values being x-forwarded or rfc7239. The default is x-forwarded.
x-forwarded uses the de facto standard X-Forwarded-For and X-Forwarded-Proto headers to determine the correct remote address and protocol for the request. These headers are widely used, however, they have some serious limitations, for example, if you have multiple proxies, and only one of them adds the X-Forwarded-Proto header, it’s impossible to reliably determine which proxy added it and therefore whether the request from the client was made using or. rfc7239 uses the new Forwarded header standard, and solves many of the limitations of the X-Forwarded-* headers.
For more information, please read the RFC 7239 Configuring HTTPS
Found an error in this documentation? The source code for this page can be found here. After reading the documentation guidelines, please feel free to contribute a pull request. Have questions or advice to share? Go to our community forums to start a conversation with the community.
Every Proxy - Apps on Google Play

Every Proxy – Apps on Google Play

Run your own proxy server on your Android device. The application handles the following protocols:HttpHttpsSocks4Socks5No root permissions are your Android network connection from another device. This is useful if you have a VPN connection on your Android device that you would like to share. This is also useful to route your traffic through your Android around network providers restrictions on tethering. Connect your hotspot as usual then proxy your and calls through Every Proxy. The proxy will bind to the IP Address assigned to your Android device. If you would like to use a different IP Address please search, on your favorite search engine, for “android change ip address”. You can also bind the proxy server to “0. 0. 0” through the settings, doing so will expose the proxy on all currently assigned IP mode is thentication is enabled for both the HTTP/S and Socks let us know if you would like any additional features by using the Google Group. Also please ask your questions on the Google you find this application useful please leave a star rating or feedback. All feedback is testing opt-in: group: #! forum/every-proxyHowto website:
Play Framework Scala Proxy For Http Post - Stack Overflow

Play Framework Scala Proxy For Http Post – Stack Overflow

I’m using play! framework with scala and trying to create a proxy for requests, GET and POST.
The GET actions seems to be working, the issue is with the POST action, where I’m not able to pass the payload of the request.
I tried several things, like the code below, but none seems to be working.
def postAction(query: String) = { implicit request =>
val data = if (! = None) else “”
(DEMO_URL + query)(data)(resp => Ok()(“application/json”))}
Last thing to mention is that I’m new to both play! and scala.
asked Nov 10 ’14 at 15:31
HasanAboShallyHasanAboShally17. 9k7 gold badges27 silver badges34 bronze badges
5
I had to add the ()
The code now is much simpler and looks like this:
def postAction(query: String) = () { implicit request =>
(DEMO_URL + query)()(resp =>
Ok()(“application/json”))}
answered Nov 13 ’14 at 10:23
Not the answer you’re looking for? Browse other questions tagged java scala playframework proxy playframework-2. 0 or ask your own question.

Frequently Asked Questions about play proxy

Leave a Reply

Your email address will not be published. Required fields are marked *