skip to Main Content

I’m building an API hosting on AWS (Elastic Beanstalk service).

I read a lot of things on this issue, but I can’t figure out why it’s not working in my case.

I’ve set up HTTPs listener on my load balancer
enter image description here

And here is my logs

 {
May 31 15:00:24 ip-172-31-45-140 web: connection: 'upgrade',
May 31 15:00:24 ip-172-31-45-140 web: host: 'api.website.app',
May 31 15:00:24 ip-172-31-45-140 web: 'x-real-ip': '172.xx.xx.xxx',
May 31 15:00:24 ip-172-31-45-140 web: 'x-forwarded-for': '172.xx.xx.xxx',
May 31 15:00:24 ip-172-31-45-140 web: 'content-length': '17',
May 31 15:00:24 ip-172-31-45-140 web: 'content-type': 'application/x-www-form-urlencoded',
May 31 15:00:24 ip-172-31-45-140 web: 'user-agent': 'App/19 CFNetwork/1237 Darwin/20.4.0',
May 31 15:00:24 ip-172-31-45-140 web: 'if-none-match': 'W/"d8a-WUss32mkaKBHy8bMoUkg04aC7OQ"',
May 31 15:00:24 ip-172-31-45-140 web: accept: 'application/json, text/plain, */*',
May 31 15:00:24 ip-172-31-45-140 web: 'accept-language': 'fr-fr',
May 31 15:00:24 ip-172-31-45-140 web: 'accept-encoding': 'gzip, deflate, br'
}

And here is /etc/nginx/conf.d/00_application.conf

location / {
    proxy_pass          http://127.0.0.1:8080;
    proxy_http_version  1.1;

    proxy_set_header    Connection          $connection_upgrade;
    proxy_set_header    Upgrade             $http_upgrade;
    proxy_set_header    Host                $host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
}

My app is running on NodeJS

So if you already had this issue, would be helpful 🙂

Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Ok I finally figure out why i hadn't client IP.

    I was using ELB in SSL/TCP mode, and in this case, client ip is not provided. I switched to ALB and everything is working great. (Even Websockets)


  2. For anyone wondering, the client info should be available to the clients when you enable proxy support on your TCP mode load balancer:

    https://aws.amazon.com/blogs/aws/elastic-load-balancing-adds-support-for-proxy-protocol/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search