Customer IP is showing localhost 127.0.0.0 under loadbalancer

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
один год назад
The application is running under a load balancer(aws) and the machines are Linux. Client IP is showing 127.0.0.0. The nopCommerce version is 4.5.x. Can anyone please help me to figure out it?
один год назад
Because load balancers intercept traffic between clients and servers, your server access logs only contain the IP address of the load balancer.

The data you are looking for is in the "X-Forwarded-For" request header
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html

Have you enabled the UseHttpXForwardedProto setting in the appsettings.json
один год назад
MikeEpprecht wrote:
Because load balancers intercept traffic between clients and servers, your server access logs only contain the IP address of the load balancer.

The data you are looking for is in the "X-Forwarded-For" request header
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html

Have you enabled the UseHttpXForwardedProto setting in the appsettings.json


Thanks MikeEpprecht for your answer. Yes I enabled it and now it is showing a private IP like 10.0.10.121. The http to https redirection from cloudflare.
один год назад
Indeed, I get the client's/customer's IP. To get the client IP I have to change the config file of nginx like below.

server {

    #server_name yourstore.com www.yourstore.com;
    server_name yourstore.com www.yourstore.com;

    location / {
    proxy_pass         http://localhost:5000;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Real-IP $remote_addr;  # Use X-Real-IP to forward client IP
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/yourstore.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/yourstore.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    #include snippets/self-signed.conf;
    #include snippets/ssl-params.conf;

}

server {

    listen 80 default_server;


    server_name _;


    return 301 https://$host$request_uri;

}

Then from nopCommerce side, I need to add all the loadbalancer IP as KnownProxies. The HostingConfig of appsettings.json(Nop.Web==>App_Data==>appsettings.json) should look like

"HostingConfig": {
  "UseProxy": true,
  "ForwardedProtoHeaderName": "X-Forwarded-Proto",
  "ForwardedForHeaderName": "X-Forwarded-For",
  "KnownProxies": "yourapplicationloadbalancerip,yournetworkloadbalancerip"
},


Some useful link
1. https://stackoverflow.com/questions/50163351/asp-net-core-behind-nginx-with-http2-remote-ip-always-127-0-0-1
2. https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-8.0&viewFallbackFrom=aspnetcore-2.1&tabs=linux-ubuntu
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.