Skip to content

Instantly share code, notes, and snippets.

@adamay000
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamay000/0aa4c378e4f9ba050557 to your computer and use it in GitHub Desktop.
Save adamay000/0aa4c378e4f9ba050557 to your computer and use it in GitHub Desktop.
Simple node server for test
events {
worker_connections 1024;
}
http {
# ロードバランサ
# 交互に中継する
upstream lb {
server localhost:8081;
server localhost:8082;
}
# localhost:8080 リバースプロキシサーバ
# localhost:8081とlocalhost:8082を交互に受け渡す
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://lb;
}
}
}
// Usage:
// $ node node.server.test.js [port]
// 引数で渡したポートで起動するサーバ
// アクセスされるとServer listening on [port].とだけ返す
//
// 今回は
// $ node node.server.test.js 8081
// $ node node.server.test.js 8082
// で二つ立てた
var http = require('http'),
port = process.argv.length > 1 ? process.argv[2] : 8001,
msg = 'Server listening on ' + port + '.';
http.createServer(function(request, response) {
response.writeHead(200, {'Content-type': 'text/plain'});
response.end(msg);
}).listen(port);
console.log(msg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment