Score:0

Reverse Proxy not showing client IP

cn flag
xJR

I've setup a reverse proxy and everything seems to be functionally fine however it looks like nginx is not correctly registering remote visit IP addresses and logs everything as coming from my server WAN IP, which wouldnt be a problem however one of the services im running is shlink which needs the remote IP to be passed in order to log locations

I'm running nginx via a SWAG docker in docker compose if that helps troubleshoot

An example below are all remote requests various devices and they are all being registered from the servers WAN IP

202.63.68.112 - - [19/May/2022:10:28:57 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 65536 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:28:59 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 7302130 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:01 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 65536 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:03 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 5045234 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:03 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 14906904 "-" "Mozilla/5.0 (Linux; Android 12; SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.61 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:05 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 65536 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:06 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 5041138 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:08 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 65536 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:10 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 6204402 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:10 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 65536 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:12 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 65536 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:12 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 3947506 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:22 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 22035471 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:22 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:22 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:22 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:22 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:22 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:23 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 2923535 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:23 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:23 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:23 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:23 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:24 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:24 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 499 0 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"
202.63.68.112 - - [19/May/2022:10:29:24 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 21001752 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1"
202.63.68.112 - - [19/May/2022:10:29:26 +1000] "GET /index.php/s/dGZegTxeeeMmro2/download HTTP/2.0" 206 4140047 "-" "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-G981U1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/17.0 Chrome/96.0.4664.104 Mobile Safari/537.36"

I have setup X forwarded for in the config below:

#### proxy.conf
---------------
# Proxy Connection Settings
proxy_buffers 32 4k;
proxy_connect_timeout 240;
proxy_headers_hash_bucket_size 128;
proxy_headers_hash_max_size 1024;
proxy_http_version 1.1;
proxy_read_timeout 240;
proxy_redirect  http://  $scheme://;
proxy_send_timeout 240;

# Proxy Cache and Cookie Settings
proxy_cache_bypass $cookie_session;
#proxy_cookie_path / "/; Secure"; # enable at your own risk, may break certain apps
proxy_no_cache $cookie_session;

# Proxy Header Settings
proxy_set_header Connection $connection_upgrade;
proxy_set_header Early-Data $ssl_early_data;
proxy_set_header Host $host;
proxy_set_header Proxy "";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Real-IP $remote_addr;


#### domain.subdomain.conf
---------------

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name domain.au;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app shlink;
        set $upstream_port 8080;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    }


}

Any ideas what I've done wrong?

us flag
Rob
That is expected, a site visitor makes a request to your reverse proxy and the reverse proxy makes a new request to the backend server. Typically the reverse proxy will include the IP-address of the visitor in a header such as an `X-forwarded-for` which can then be used in the backend. See also http://nginx.org/en/docs/http/ngx_http_realip_module.html
cn flag
xJR
@Rob thanks so much for taking the time to reply, in the attached logs is the X-Forwarded-for on line 24 what you are referring to? Should it be configured differently to allow client IP through? Sorry i am very new to this so trying to read up on it
djdomi avatar
za flag
paste your logs native to the question, don't use any nopaste services
cn flag
xJR
@djdomi - ive updated the post to include relevant information - thank you. Do you have any idea how i can resolve?
djdomi avatar
za flag
@xJR have you done the research on the documentation, which Rob did, suggested? When you paste configurations, please use each as a separate block and show the full path, as it is mandatory information. i would place the proxy.conf in the main directory and include it in the server aprt, remind, that each server part has to be seen as a separate instance and their force, you did not configure it.
cn flag
xJR
i think i may have written this post in a confusing way but what my actual issue is, is that proxy itself is not getting the remote IP of the person connecting, and therefor unable to pass the correct 'real ip' onto the services proxied. I have the x-forwarded-for included in the proxy.conf file in the post.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.