Back

How to Get the User’s Real IP Instead of the Server IP

  • 0
  • Self Hosted
  • React Native
  • Web
  • Auth
theaksaa
25 Feb, 2025, 02:44

Hi everyone,

I have a problem where, when a user logs in, the saved IP address is the server’s IP instead of the user’s real IP. I followed this guide: How to Run Appwrite Behind Nginx, but I’m not sure how to fix it.

I’m using a Next.js app with SSR for login and registration. Here’s my function for creating a session:

TypeScript
export async function createSessionClient(): Promise<AppwriteClient> {
    const client = new Client()
        .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!)
        .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT!);

    const cookieStore = await cookies();
    const session = cookieStore.get("auth-session");

    if (!session || !session.value) {
        throw new Error("No session");
    }

    client.setSession(session.value);

    return {
        get account() {
            return new Account(client);
        },
    };
}

How can I get the user’s real IP instead of the server’s IP? Any help would be really appreciated!

Thank you!

TL;DR
Issue: User's IP not being captured correctly, showing server's IP instead. Problem arises during login where the server IP is saved. Following a tutorial to implement Appwrite behind Nginx. Solution: To capture the user's real IP instead of the server's IP, consider using a trusted proxy like Nginx. Configure Nginx with "real_ip_header" and "set_real_ip_from" directives, passing the correct IP from the user through to your application. This way, the user's actual IP will be captured.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more