From 8b5aa07b1fbfb50735dd90450b191f32bc22694a Mon Sep 17 00:00:00 2001 From: tlanyan Date: Tue, 12 Jan 2021 17:48:27 +0800 Subject: [PATCH] feat: log real ip --- ghproxy.conf | 3 +++ index.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ghproxy.conf b/ghproxy.conf index f5d95ee..7f447e1 100644 --- a/ghproxy.conf +++ b/ghproxy.conf @@ -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; } } diff --git a/index.php b/index.php index f332798..73739cb 100644 --- a/index.php +++ b/index.php @@ -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);