Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Created April 27, 2015 22:36
Show Gist options
  • Save mostlygeek/578d16b3bd4a0515aa92 to your computer and use it in GitHub Desktop.
Save mostlygeek/578d16b3bd4a0515aa92 to your computer and use it in GitHub Desktop.
override x-forwarded-for for openresty
# NGINX
location / {
set $forwarded_for $proxy_add_x_forwarded_for;
if ($http_x_verify_ip) {
set $forwarded_for $http_x_verify_ip;
}
proxy_set_header X-Forwarded-For $forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8000;
}
#NODE JS TEST
var http = require('http');
var srv = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var clientip = req.headers['x-forwarded-for'] || 'na';
res.end("x-forwarded-for: " + clientip + "\n")
});
srv.listen(8000, "127.0.0.1", function() {
console.log("listening");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment