Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse proxy for a subdirectory with nginx and Play 2.1 apps

Goal

Setup multiple Play 2.1 applications with nginx using different subdirectory for each application.

App1 running on 127.0.0.1:4000 should be accessible under 127.0.0.1/dev
App2 running on 127.0.0.1:5000 should be accessible under 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

With this configuration I can access both applications, but only html code is loaded. All static files (css, js, images) aren't loaded.

I think this is caching problem. I've tried with different nginx parameters, without luck. If I request the site for the first time the browser responds (for css and js files, e.g. 127.0.0.1/dev/assets/stylesheets/main.css) with status 200 but without content - Content-Length: 0. For the next time it responds with 304, still without content.

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

I will appreciate any help.

like image 903
Lukasz R. Avatar asked Apr 05 '13 14:04

Lukasz R.


1 Answers

Use local domains like http://test.loc/ and http://dev.loc instead of relying on subfolders. Although application.context should work I saw many posts complaining that they don't...

What's more using local domains is more similar to the final - production enviroment, so it's just easier to debug some url depended things, like ie. cookies.

like image 183
biesior Avatar answered Oct 20 '22 23:10

biesior