Giter VIP home page Giter VIP logo

play-scala-nginx's Introduction

play-scala-nginx

Configure nginx

First, follow steps listed in cert/README.md to generate self-signed certificate and private keys.

Next, download nginx and place cert in its root directory, also replace nginx.conf found in the conf directory.

To start and stop nginx, use commands below.

# start nginx
nginx

# stop nginx
nginx -s stop

Note that, in nginx.conf, we configure proxy_pass from HTTPS port 9005 to HTTP 9000 for both / for normal HTTP requests and /ws for websocket connection.

server {
    listen 9005 ssl;
    server_name localhost;

    ssl_certificate           ../cert/cert.crt;
    ssl_certificate_key       ../cert/cert.key;

    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    # access_log            logs/https.access.log;

    location / {
        proxy_pass          http://localhost:9000;
        # proxy_read_timeout  90;
        proxy_redirect      off;
    }

    location /ws {
        proxy_pass          http://localhost:9000;
        proxy_http_version  1.1;
        proxy_set_header    Upgrade $http_upgrade;
        proxy_set_header    Connection "upgrade";
        proxy_read_timeout  86400;
    }
}

Configure and run http/websocket app

sbt ~run

Then, the backend will be available at 2 URLs:

# http
http://localhost:9000

# https proxied by nginx
https://localhost:9005

There is a script for the index.html which configures the websocket to connect to HTTPS port 9005.

var wsUrl = 'wss://localhost:9005/ws/orders/table/' + tableId;
ws = new WebSocket(wsUrl);

Note that, the HTTP port 9000 should work too. We can avoid exposing this HTTP port 9000 by randomizing this port number via startup script and set it to environment variable. With this, we can tweak the config files of Nginx and Play to make sure Play app can expose to the random port and Nginx can proxy to it.

play-scala-nginx's People

Contributors

daedrag avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.