HOw to run multiple applications in play framework on the same port

前端 未结 3 1459
半阙折子戏
半阙折子戏 2020-12-30 16:30

I am new to Play Framework. I am using Play 2.0.2 and I want to run multiple applications on Play on the same port.

It should be like http://localhost:9000/P

3条回答
  •  攒了一身酷
    2020-12-30 17:32

    That's not possible with play alone, since each application runs in its own process and there can only be one process listening on one port at one time. What you can do is run your play applications on ports 9001 and 9002 and then run a server like nginx on port 9000 and configure it to route requests for the different URLs to your play applications.

    See this example: http://www.cyberciti.biz/tips/using-nginx-as-reverse-proxy.html The only difference to your case is that you would have one server {...} block with two location blocks in it. It would look something like:

    upstream play1 {
          server localhost:9001;
    }
    
    upstream play2  {
          server localhost:9002;
    }
    
    server {
        listen       localhost:9000;
        server_name  www.example.com;
    
        access_log  /var/log/nginx/log/www.example.access.log  main;
        error_log  /var/log/nginx/log/www.example.error.log;
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    
        ## send requests to play1 ##
        location /Project1/ {
            proxy_pass  http://play1;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_redirect off;
            proxy_buffering off;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    
        ## send requests to play2 ##
        location /Project2/ {
            proxy_pass  http://play2;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_redirect off;
            proxy_buffering off;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    
    }
    

提交回复
热议问题