I have a simple express app. which is Dockerized. This is Repository.
I used nginx as a reverse proxy there. when I visit http://45.33.97.232:3000, it gives me the actual IP.
But, when I visit http://45.33.97.232/, It gives me the same server IP. But I need actual Client IP here.
And I am using Server IP in nginx config file. but I have a restriction, I can't write Server IP in nginx config file.
This is my nginx config file,
server {
listen 80 default_server;
server_name 45.33.97.232;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://45.33.97.232:3000; #port where you are serving your express app.
}
}
In nginx if you want to pass through the IP address of the remote user to your backend web server you have to set X-Forwarded-For header to this remote ip, Like this:
proxy_set_header X-Forwarded-For $remote_addr;
and if you do not want to use server IP you can use the domain in your Nginx config file.