-
-
Save VldMrgnn/b98e4dde569677cf96777198101a8586 to your computer and use it in GitHub Desktop.
Basic load balancing NodeJS (Nginx + PM2 + Express)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express'; | |
// ... So much space for unstable dependency imports ... | |
let app = express(); | |
// ... Insert your own routing magic ... | |
export default app; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"apps": [ | |
{ | |
"name": "Solve World Hunger", | |
"script": "www.js", | |
"instances": 3, | |
"exec_mode": "fork", | |
"env_devqa": { | |
"PORT": 8000 | |
} | |
} | |
], | |
"deploy": { | |
"devqa": { | |
"user": "", | |
"host": "", | |
"ref": "origin/devqa", | |
"repo": "", | |
"path": "/var/www", | |
"post-deploy": "npm isntall; pm2 startOrRestart devqa.json" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nginx Sample App Conf | |
# Upstream | |
# | |
upstream worldhunger_upstream { | |
least_conn; | |
server 127.0.0.1:8001; | |
server 127.0.0.1:8002; | |
server 127.0.0.1:8003; | |
} | |
server { | |
listen 80; | |
server_name worldhungerfixednextproblem.com; | |
location / { | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_pass http://worldhunger_upstream; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import app from 'app'; | |
import https from 'http'; | |
let instance = +process.env.NODE_APP_INSTANCE || 0; | |
let port = (+process.env.PORT || 3000) + instance; | |
let server = http.createSerevr( app ); | |
app.set( 'port', port ); | |
server.listen( port ); | |
// ... Instance logging, you get the idea... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment