i have a nodejs/express application and am logging with morgan:
var morgan = require ("morgan");
var app = express();
app.use(morgan(':date[iso] :remote-addr :method :url :status :res[content-length] - :response-time ms'));
but in my logfiles (redirected from 'npm start') i find lines like this:
2014-12-21T10:02:59.365Z 127.0.0.1 GET / 304 - - 2.389 ms
showing 127.0.0.1 as remote address for all requests. i do use angular's $routeProvider after the index.html is loaded but even the / request returns 127.0.0.1.
app.get('/partials/:name', routes.partials);
app.get('*', function (req, res) {
res.setHeader('Content-type', 'text/html');
res.charset = 'UTF-8';
res.sendFile(__dirname + '/pub/index.html');
});
am i missing something? shouldn't the actual requester be logged here?
Is your server behind a proxy?
Try:
app.enable("trust proxy");
(Insert line before using morgan middleware)
Two conditions must be met.
As pasimako showed code:
app.enable("trust proxy");
and with nginx configuration (from this question):
proxy_set_header X-Forwarded-For $remote_addr;
For me works only that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With