I'm part of a team working on a web application which is often deployed in large corporate environments where a proxy server is used. We need some way to detect traffic coming via a proxy and log when that is the case to aid in debugging issues found at the client end. At present we have a simple test which checks for various headers such as 'HTTP_X_FORWARDED_FOR' etc and trips a switch to mark the session as possibly being behind a proxy.

My question is - how can we quickly and easily simulate a connection that would trip such a check using desktop tools such as Charles.app?

有帮助吗?

解决方案

Not sure about charles.app, but if you're able to configure Nginx locally, then this should work:

upstream myservice {
    server 127.0.0.1:8000;
}

server {
    listen       8001;
    server_name  127.0.0.1;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_pass http://myservice;
    }
}

This assumes your server is listening on 127.0.0.1:8000. To connect through the proxy, go to 127.0.0.1:8001.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top