Skip to content

Instantly share code, notes, and snippets.

@hakobera
Created October 22, 2012 14:10
Show Gist options
  • Save hakobera/3931679 to your computer and use it in GitHub Desktop.
Save hakobera/3931679 to your computer and use it in GitHub Desktop.
NGINX vs Node static server
var cluster = require('cluster'),
connect = require('connect');
var numCPUs = parseInt(process.argv[2]);
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
var server = connect().use(connect.static(__dirname + '/'));
server.listen(process.env.PORT || 18081);
}
var connect = require('connect');
var server = connect().use(connect.static(__dirname + '/'));
server.listen(process.env.PORT || 18081);
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.0;
gzip_types text/plain
text/xml
text/css
application/xml
application/xhtml+xml
application/rss+xml
application/atom_xml
application/javascript
application/x-javascript
application/x-httpd-php;
gzip_disable "MSIE [1-6]\.";
gzip_disable "Mozilla/4";
gzip_comp_level 1;
gzip_proxied any;
gzip_vary on;
gzip_buffers 4 8k;
gzip_min_length 1100;
include /etc/nginx/conf.d/*.conf;
}
var http = require('http'),
fs = require('fs');
var server = http.createServer(function (req, res) {
if (req.url === '/logo.png') {
res.writeHead(200, { 'Content-Type': 'image/png' });
fs.createReadStream(__dirname + '/logo.png').pipe(res);
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
fs.createReadStream(__dirname + '/index.html').pipe(res);
}
});
server.listen(process.env.PORT || 18081);
var cluster = require('cluster'),
http = require('http'),
static = require('node-static');
var file = new(static.Server)(__dirname + '/');
var numCPUs = parseInt(process.argv[2]);
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
var server = http.createServer(function(req, res) {
file.serve(req, res);
});
server.listen(process.env.PORT || 18081);
}
var http = require('http'),
static = require('node-static');
var file = new(static.Server)(__dirname + '/');
var server = http.createServer(function (req, res) {
req.on('end', function() {
file.serve(req, res);
});
});
server.listen(process.env.PORT || 18081);
var cluster = require('cluster'),
http = require('http'),
st = require('st');
var numCPUs = parseInt(process.argv[2]);
var mount = st({
path: __dirname + '/',
url: '/'
});
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
var server = http.createServer(function(req, res) {
mount(req, res);
});
server.listen(process.env.PORT || 18081);
}
var http = require('http'),
st = require('st');
var mount = st({
path: __dirname + '/',
url: '/'
});
var server = http.createServer(function (req, res) {
mount(req, res);
});
server.listen(process.env.PORT || 18081);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment