/passenger-nodejs-websocket-demo

Phusion Passenger: Node.js WebSocket demo

Primary LanguageCSSMIT LicenseMIT

Phusion Passenger: Node.js WebSocket demo

This application demonstrates WebSocket support in the Phusion Passenger application server for Node.js, through the use of the awesome Socket.io library. Passenger supports all major modern web technologies, such as WebSockets, entirely out of the box. You don't have to do anything: WebSocket support just works.

If you like this demo, please tweet about it or follow us on Twitter.

See also: >> What is Phusion Passenger, and why should I care?

Node.js

Phusion Passenger

Getting started

Preparations

  1. Install Phusion Passenger 4.0.45 or later.

  2. Clone this repository:

    git clone https://github.com/phusion/passenger-nodejs-websocket-demo.git
    cd passenger-nodejs-websocket-demo
    
  3. Install dependencies:

    npm install socket.io
    

Running the demo in Passenger Standalone

Run:

passenger start --sticky-sessions

Access the demo application at http://0.0.0.0:3000/ and see it in action.

Sticky sessions are required for long polling support.

Running the demo in Passenger for Nginx

Create a virtual host in your Nginx configuration file:

server {
    listen 3000;
    server_name passenger-nodejs-websocket.demo;
    root /path-to/passenger-nodejs-websocket-demo/public;
    passenger_enabled on;

    # Sticky sessions are required for long polling support!
    passenger_sticky_sessions on;
}

Add passenger-nodejs-websocket.demo to your /etc/hosts:

echo 127.0.0.1 passenger-nodejs-websocket.demo | sudo tee -a /etc/hosts

Then restart Nginx, and access the demo application at http://passenger-nodejs-websocket.demo:3000/

Running the demo in Passenger for Apache

Phusion Passenger currently does not support WebSockets on Apache. Having said that, Socket.io gracefully falls back to long polling when run on Apache, so the demo still works.

Create a virtual host in your Apache configuration file:

# Comment out if you already have a "Listen 3000" directive somewhere.
Listen 3000
# Comment out when using Apache >= 2.4.
NameVirtualHost *:3000

<VirtualHost *:3000>
    ServerName passenger-nodejs-websocket.demo
    DocumentRoot /path-to/passenger-nodejs-websocket-demo/public

    # Sticky sessions are required for long polling support!
    PassengerStickySessions on
</VirtualHost>

Add passenger-nodejs-websocket.demo to your /etc/hosts:

echo 127.0.0.1 passenger-nodejs-websocket.demo | sudo tee -a /etc/hosts

Then restart Apache, and access the demo application at http://passenger-nodejs-websocket.demo:3000/

Running the demo in Node.js without Passenger

Run:

node app.js

Then access the demo application at http://0.0.0.0:3000/

Next steps

Please enjoy Phusion Passenger, a product by Phusion. :-)

About Phusion Passenger


5 minute intro: Making Node.js deployment enjoyable (DotJS Paris 2013)


Phusion Passenger used in Game of Thrones Ascention

Phusion Passenger™ is a web server and application server, designed to be fast, robust and lightweight. It takes a lot of complexity out of deploying web apps, adds powerful enterprise-grade features that are useful in production, and makes administration much easier and less complex. Phusion Passenger supports Ruby, Python, Node.js and Meteor, and is being used by high-profile companies such as Apple, Pixar, New York Times, AirBnB, Juniper etc as well as over 350.000 websites.

Learn more: Website | Documentation | Support resources | Github | Twitter | Blog