Skip to content

Instantly share code, notes, and snippets.

@cyx
Forked from jmervine/01_nginx.conf
Created July 25, 2013 15:50
Show Gist options
  • Save cyx/6081103 to your computer and use it in GitHub Desktop.
Save cyx/6081103 to your computer and use it in GitHub Desktop.
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /home/t/nginx/conf/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
userid on;
userid_name vrid;
userid_domain example.com;
userid_expires max;
split_clients "${uid_set}${uid_got}" $bucketid {
10% "bucketOne";
* "bucketTwo";
}
upstream @appone {
server 0.0.0.0:3000;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header X-Bucket-ID $bucketid;
add_header X-Bucket-ID $bucketid;
proxy_pass http://@appone;
}
}
}
[jmervine@jmervine01 ~]$ curl localhost -i
HTTP/1.1 200 OK
Server: nginx/1.4.2
Date: Thu, 25 Jul 2013 05:58:46 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
X-Bucket-ID: bucketTwo
Set-Cookie: vrid=fwAAAVHwvpZmaHXrAwMFAg==; expires=Thu, 31-Dec-37 23:55:55 GMT; domain=example.com; path=/
Hello bucketTwo
[jmervine@jmervine01 ~]$ curl localhost -i
HTTP/1.1 200 OK
Server: nginx/1.4.2
Date: Thu, 25 Jul 2013 05:58:52 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
X-Bucket-ID: bucketOne
Set-Cookie: vrid=fwAAAVHwvpxmaHXrAwMGAg==; expires=Thu, 31-Dec-37 23:55:55 GMT; domain=example.com; path=/
Hello bucketOne
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
var bucketId = request.headers['x-bucket-id'];
response.end("Hello "+bucketId+"\n");
});
server.listen(3000);
console.log("Server running at http://127.0.0.1:3000/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment