Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Last active November 24, 2016 05:05
Show Gist options
  • Save pokutuna/5ad6b04ada0d9991a80f11b2dfbfe903 to your computer and use it in GitHub Desktop.
Save pokutuna/5ad6b04ada0d9991a80f11b2dfbfe903 to your computer and use it in GitHub Desktop.
nginx proxy_set_header
use strict;
use warnings;
my $app = sub {
my ($env) = @_;
return [ 200, [ 'Content-Type' => 'text/plain' ], [ "HTTP_HOST: $env->{HTTP_HOST}" ] ];
};
#!/bin/bash
trap 'kill $(jobs -p) && sudo nginx -s quit' EXIT
sudo nginx -c $PWD/nginx.conf
plackup &
open 'http://localhost:5001'
open 'http://localhost:5002'
wait
events {
worker_connections 1024;
}
http {
server {
listen 5001;
proxy_set_header Host header1;
proxy_set_header Host header2;
location / {
proxy_pass http://localhost:5000;
# => HTTP_HOST: header1, header2
}
}
server {
listen 5002;
proxy_set_header Host header1;
location / {
proxy_set_header Host header2;
proxy_pass http://localhost:5000;
# => HTTP_HOST: header2
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment