modified: server.js
This commit is contained in:
parent
ff25ff639a
commit
ee86fa303f
17
server.js
17
server.js
@ -307,24 +307,17 @@ function getClientIP(req) {
|
|||||||
console.log("ALL HEADERS:", JSON.stringify(req.headers, null, 2));
|
console.log("ALL HEADERS:", JSON.stringify(req.headers, null, 2));
|
||||||
console.log("========================");
|
console.log("========================");
|
||||||
|
|
||||||
// Проверяем X-Forwarded-For заголовок в первую очередь
|
// Используем req.socket.remoteAddress напрямую, так как nginx передает внутренний IP контейнера
|
||||||
let ip = req.headers["x-forwarded-for"]?.split(",")[0].trim();
|
let ip = req.socket?.remoteAddress;
|
||||||
|
|
||||||
// Если X-Forwarded-For не определен, пробуем другие заголовки
|
// Если remoteAddress недоступен, пробуем заголовки
|
||||||
if (
|
if (!ip || ip === "::1") {
|
||||||
!ip ||
|
|
||||||
ip === "127.0.0.1" ||
|
|
||||||
ip === "::1" ||
|
|
||||||
ip === "::ffff:127.0.0.1" ||
|
|
||||||
ip === "172.17.0.1"
|
|
||||||
) {
|
|
||||||
ip =
|
ip =
|
||||||
|
req.headers["x-forwarded-for"]?.split(",")[0]?.trim() ||
|
||||||
req.headers["x-real-ip"] ||
|
req.headers["x-real-ip"] ||
|
||||||
req.headers["x-client-ip"] ||
|
req.headers["x-client-ip"] ||
|
||||||
req.ip ||
|
req.ip ||
|
||||||
req.connection?.remoteAddress ||
|
req.connection?.remoteAddress ||
|
||||||
req.socket?.remoteAddress ||
|
|
||||||
req.connection?.socket?.remoteAddress ||
|
|
||||||
"unknown";
|
"unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user