feat: log real ip

This commit is contained in:
tlanyan 2021-01-12 17:48:27 +08:00
parent 232c3907a7
commit 8b5aa07b1f
2 changed files with 5 additions and 1 deletions

View File

@ -31,6 +31,9 @@ server {
}
location ^~ /http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_pass http://localhost:8080;
}
}

View File

@ -29,10 +29,11 @@ $loop->run();
function handler(Psr\Http\Message\ServerRequestInterface $req) {
$ip = $req->getHeader('REMOTE_ADDR')[0];
$url = $req->getUri()->getPath();
// strip start /
$url = substr($url, 1);
echo "request url: ", $url, PHP_EOL;
echo "IP:", $ip, ", request url: ", $url, PHP_EOL;
if (substr($url, 0, 4) !== 'http') {
return serveStaticFiles($url);