ExpressJS get real IP from ALB contain port

traleeee-gmo 0 Reputation points
2024-04-15T09:16:16.4233333+00:00

Hello! I'm currently develop and deploying new nodejs app on Azure and when i use the app.set('trust proxy', true); i get the real ip from the client but it contain strange port.
User's image

I'm already research but no solution on this. Yes, i can remove this just by using a simple js function. But i still want to know where this port come from?
Thank you!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,778 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 26,136 Reputation points Microsoft Employee
    2024-04-16T07:57:38.9066667+00:00

    @traleeee-gmo , To assist you better on this issue, since you have posted the question on Azure App Service? Is your WordPress webapp hosted on an Azure WebApp or on Azure VM or some other Azure service? Where exactly do you see this message/logs? If it's on App service, are you leveraging Windows or Linux tier?

    On an Azure VM, you would typically setup and config nodejs app, as you would on-prem.

    Just to highlight, your Node.js app needs to listen to the right port to receive incoming requests.

    App Service sets the environment variable PORT in the Node.js container, and forwards the incoming requests to your container at that port number. To receive the requests, your app should listen to that port using process.env.PORT. The following example shows how you do it in a simple Express app:

    In App Service, TLS/SSL termination happens at the network load balancers, so all HTTPS requests reach your app as unencrypted HTTP requests. If your app logic needs to check if the user requests are encrypted or not, inspect the X-Forwarded-Proto header.

    Checkout these docs for more info:

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.