Running
node.js
as a service behind
ngnix/varnish
why?
$ ssh me@production.com
me@srv:~$ node /opt/myapp/index.js
$ ssh me@production.com
me@srv:~$ node /opt/myapp/index.js
X
$ ssh me@production.com
me@srv:~$ screen
Screen version 4.00.03jw4 (FAU) 2-May-06
Copyright (c) 1993-2002 Juergen Weigert, Michael Schroeder
Copyright (c) 1987 Oliver Laumann
This program is free software; you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation; either version 2, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License along with this program (see the file
COPYING); if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA.
Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to screen@uni-erlangen.de
To use byobu (formerly screen-profiles), exit screen and run 'byobu'.
[Press Space or Return to end.]
me@srv:~$ node /opt/myapp/index.js
me@srv:~$ node /opt/myapp/index.js
[detached from 2254.pts-0.srv]
me@srv:~$
me@srv:~$ node /opt/myapp/index.js
[detached from 2254.pts-0.srv]
me@srv:~$
X
me@srv:~$ while true ; do
> node /opt/myapp/index.js
> done
me@srv:~$ while true ; do
> node /opt/myapp/index.js
> done
X
•forever https://github.com/foreverjs/forever
•monit https://mmonit.com/monit/
•pm2 http://pm2.keymetrics.io
•systemd https://freedesktop.org/wiki/Software/systemd/
•upstart http://upstart.ubuntu.com
•etc …
upstart
# /opt/myapp/index.js
require("http").createServer(function (req, res) {
res.writeHead(200, { "Content-Type": "text/html" });
res.end("<h1>Hello, Fullstack JS Berlin!</h1>");
}).listen(1337, "0.0.0.0");
$ sudo vi /etc/init/myapp.conf
# /etc/init/myapp.conf
description "myapp"
author "thiagoalessio"
start on started mountall
stop on shutdown
respawn
respawn limit 99 5
script
exec sudo -u myapp /usr/bin/node /opt/myapp/index.js >> /var/log/myapp.log 2>&1
end script
post-start script
echo "myapp was started" >> /opt/myapp/logs/myapp.log
end script
$ sudo start myapp
myapp start/running, process 1351
Running node.js as a service behind nginx/varnish
$ sudo stop myapp
myapp stop/waiting
Running node.js as a service behind nginx/varnish
•automatically starts
on machine boot

•easily update code
after deployments
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
super fast!
$ sudo vi /etc/varnish/default.vcl
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = "127.0.0.1";
.port = "1337";
}
#
# … rest of the file …
Running node.js as a service behind nginx/varnish
$ sudo stop myapp
myapp stop/waiting
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
concurrency
$ sudo vi /etc/nginx/sites-enabled/default
# /etc/nginx/sites-enabled/default
upstream varnish { server 127.0.0.1:6081; }
upstream nodejs { server 127.0.0.1:1337; }
server {
listen 80;
server_name _;
root /opt/myapp;
location ~* .(jpg|css|png)$ { access_log off; }
location /non-cacheable-content { proxy_pass http://nodejs; }
location / { proxy_pass http://varnish; }
}
Running node.js as a service behind nginx/varnish
thank you ;D
@thiagoalessio
github.com/thiagoalessio

More Related Content

PDF
Running node.js as a service behind nginx/varnish
PDF
Steam Learn: Composer
PDF
How to create your own hack environment
PDF
Jenkins and Groovy
PDF
Setup a New Virtualenv for Django in Windows
ODP
Nodejs Intro - Part2 Introduction to Web Applications
PDF
Vagrant plugin development intro
PPTX
nginx + uwsgi emperor + bottle
Running node.js as a service behind nginx/varnish
Steam Learn: Composer
How to create your own hack environment
Jenkins and Groovy
Setup a New Virtualenv for Django in Windows
Nodejs Intro - Part2 Introduction to Web Applications
Vagrant plugin development intro
nginx + uwsgi emperor + bottle

What's hot (20)

PPT
Nodejs Intro Part One
PPTX
Simple webapps with nginx, uwsgi emperor and bottle
PPTX
Jenkins X on AKS
PDF
Hello git
PPTX
Build & test Apache Hawq
PPTX
Grunt and Bower
PDF
SlideShare API ''Get Slideshow Information'' method example with Groovy
ODP
Redmine on amazon ec2
PDF
2 docker engine_hands_on
 
PPT
Node.js Cloud deployment
PDF
CI : the first_step: Auto Testing with CircleCI - (MOSG)
PDF
Node.js x Azure, cli usage, website deployment
PDF
node.js app deploy to heroku PaaS
PDF
Provisioning with Puppet
PPTX
Deploy Node.js application in Heroku using Eclipse
PDF
CraftCamp for Students - Introduction to git
PDF
OSS AWS 핸즈온 강의
PDF
Usando docker en Azure
PDF
Greach - The Groovy Ecosystem
PDF
Git - Intro to the Basics of DVCS
Nodejs Intro Part One
Simple webapps with nginx, uwsgi emperor and bottle
Jenkins X on AKS
Hello git
Build & test Apache Hawq
Grunt and Bower
SlideShare API ''Get Slideshow Information'' method example with Groovy
Redmine on amazon ec2
2 docker engine_hands_on
 
Node.js Cloud deployment
CI : the first_step: Auto Testing with CircleCI - (MOSG)
Node.js x Azure, cli usage, website deployment
node.js app deploy to heroku PaaS
Provisioning with Puppet
Deploy Node.js application in Heroku using Eclipse
CraftCamp for Students - Introduction to git
OSS AWS 핸즈온 강의
Usando docker en Azure
Greach - The Groovy Ecosystem
Git - Intro to the Basics of DVCS

Similar to Running node.js as a service behind nginx/varnish (20)

PDF
How to deploy node to production
PDF
Nicolas-Embleton - Deploying node.js with forever and nginx
PDF
[Js hcm] Deploying node.js with Forever.js and nginx
PDF
Webconf nodejs-production-architecture
PPTX
A Node.js Developer's Guide to Bluemix
PDF
AMS Node Meetup December presentation Phusion Passenger
PDF
Spacebrew Server Workshop @ ITP
PPTX
Node.js, Vagrant, Chef, and Mathoid @ Benetech
PDF
Nginx cheat sheet
PPTX
Building and Scaling Node.js Applications
PDF
Getting started docker notes
PDF
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
KEY
Writing robust Node.js applications
PDF
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
PPTX
Cloud Foundry: Hands-on Deployment Workshop
PDF
Node.js - async for the rest of us.
PDF
Building servers with Node.js
PDF
Node.js - A Quick Tour
PDF
Scalable Distributed System Architecture
PDF
Nodejs - A-quick-tour-v3
How to deploy node to production
Nicolas-Embleton - Deploying node.js with forever and nginx
[Js hcm] Deploying node.js with Forever.js and nginx
Webconf nodejs-production-architecture
A Node.js Developer's Guide to Bluemix
AMS Node Meetup December presentation Phusion Passenger
Spacebrew Server Workshop @ ITP
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Nginx cheat sheet
Building and Scaling Node.js Applications
Getting started docker notes
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
Writing robust Node.js applications
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Cloud Foundry: Hands-on Deployment Workshop
Node.js - async for the rest of us.
Building servers with Node.js
Node.js - A Quick Tour
Scalable Distributed System Architecture
Nodejs - A-quick-tour-v3

Recently uploaded (20)

PPTX
oracle_ebs_12.2_project_cutoveroutage.pptx
PPTX
Lesson-3-Operation-System-Support.pptx-I
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
PDF
C language slides for c programming book by ANSI
PPTX
Why 2025 Is the Best Year to Hire Software Developers in India
PPTX
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
PPTX
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx
PPTX
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
PDF
Mobile App for Guard Tour and Reporting.pdf
PDF
IDM Crack Activation Key 2025 Free Download
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
Presentation - Summer Internship at Samatrix.io_template_2.pptx
PPTX
UNIT II: Software design, software .pptx
PPTX
Greedy best-first search algorithm always selects the path which appears best...
PPTX
Comprehensive Guide to Digital Image Processing Concepts and Applications
PPT
chapter01_java_programming_object_oriented
PDF
OpenEXR Virtual Town Hall - August 2025
PDF
10 Mistakes Agile Project Managers Still Make
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PPTX
MCP empowers AI Agents from Zero to Production
oracle_ebs_12.2_project_cutoveroutage.pptx
Lesson-3-Operation-System-Support.pptx-I
Top 10 Project Management Software for Small Teams in 2025.pdf
C language slides for c programming book by ANSI
Why 2025 Is the Best Year to Hire Software Developers in India
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
Mobile App for Guard Tour and Reporting.pdf
IDM Crack Activation Key 2025 Free Download
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Presentation - Summer Internship at Samatrix.io_template_2.pptx
UNIT II: Software design, software .pptx
Greedy best-first search algorithm always selects the path which appears best...
Comprehensive Guide to Digital Image Processing Concepts and Applications
chapter01_java_programming_object_oriented
OpenEXR Virtual Town Hall - August 2025
10 Mistakes Agile Project Managers Still Make
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
MCP empowers AI Agents from Zero to Production

Running node.js as a service behind nginx/varnish