I have an API powered by a mean stack and served using PM2. It exposes a HTTP endpoint at http://89.89.89.89:8080 (example IP) - I can access this directly using my browser.
I have installed Nginx and I'm using the following configuration to redirect requests to the API on the same server.
server {
listen 8081;
server_name example.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}
The above works and I can access the API at http://89.89.89.89:8081 (Nginx Port), however requests to the target are from 127.0.0.1. I would like to forward the real user's IP address to PM2. I've searched and tried several solutions but can't get this to work.
Any assistance or pointers in the right directions are appreciated.