Reverse proxy for a subdirectory with nginx and Play 2.1 applications

goal

Configure multiple Play 2.1 applications using nginx, using different subdirectories for each application.

App1 running on 127.0.0.1:4000 should be available at 127.0.0.1/dev
App2 running on 127.0.0.1:5000 should be available at 127.0.0.1/test

Configuration

nginx.conf

 worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; upstream app1 { server 127.0.0.1:4000; } upstream app2 { server 127.0.0.1:5000; } server { listen 80; server_name localhost; location /dev { rewrite /(.*) /$1 break; proxy_pass http://app1; } location /test { rewrite /(.*) /$1 break; proxy_pass http://app2; } } } 

App1 - application.conf

 application.context=/dev 

App2 - application.conf

 application.context=/test 

Problem

In this configuration, I can access both applications, but only html code is loaded. All static files (css, js, images) are not loaded.

I think this is a caching problem. I tried with various nginx options, with no luck. If I request a site for the first time, the browser responds (for css and js files, for example 127.0.0.1/dev/assets/stylesheets/main.css ) with a status of 200 , but without content - Content-Length: 0 . Next time, he answers 304 , still without content.

I'm not sure if this is a nginx or Play 2.1 configuration issue.

I would appreciate any help.

+6
source share
2 answers

Use local domains like http://test.loc/ and http://dev.loc instead of relying on subfolders. Although application.context should work, I have seen many posts complaining that they are not ...

The more the use of local domains is more like the final production environment, the easier it is to debug some URL-dependent things, for example, i.e. biscuits.

+1
source

Even if this does not answer your question directly, I got it to work in HAProxy by passing the X-Script-Name parameter:

 frontend public bind *:80 use_backend playapp if { path_beg /playapp } backend playapp acl is-ssl dst_port 443 reqadd X-Script-Name:\ /playapp reqadd X-Scheme:\ https if is-ssl option forwardfor server playapp1 127.0.0.1:9000 check 
0
source

All Articles