Score:1

How to Make NGINX to use System Proxy?

jp flag

I am trying to setup a nginx server that forwards the incoming request to a corporate porxy (its a mcafee proxy) with a proxy header Host and the actual destination host something like proxy_set_header Host xyz.com:443.

This works perfectly fine for http requests but not for https

here is my nginx.conf (assuming no proxy auth required)

server {
        listen       80;

        location /test/ {
            proxy_pass http://my-corporate-proxy:8080/;
            proxy_set_header Host mytargetdomain.com:443;
        }

here my expectation is when i hit http://localhost:80/test/api/health the request should go to nginx and then to http://my-corporate-proxy:8080/api/health with Host header and from my proxy it should initiate a https request like https://mytargetdomain.com/api/health.

but this doesnt happening in case of https.

is there any way I can make it work ? or if I make nginx honour system proxy that should also fine.

Thanks in advance.

Michael Hampton avatar
cz flag
Don't use nginx for this. Use a proper forward proxy server.
V Shunmugam avatar
jp flag
thanks Michael for responding. Cant we use nginx as a proper forward proxy? Reason we are restricted to nginx is for some security reasons (restricted by our org). Adding to my original question, can nginx use system proxy ? If yes how ? I knew it doesn't by default. Please advice
Martin Fjordvald avatar
co flag
Nginx is a reverse proxy; you're trying to use it as a forward proxy which it was not designed for. It is somewhat possible but you'll keep running into issues most likely.
Score:0
in flag

This setting might work. The proxy setting of OS must allow the nginx service go through. i.e. If Windows Nginx + Proxifier, in the Proxifier menu, [Profile][Advanced][Sevices and other users]...options, must be checked to enable nginx service pass.

http{

...  


upstream service_behind_proxy  {
            server my-corporate-service-behind-proxy:8080;
        }

server {
        listen       80;

        location /test/ {
            proxy_pass http://service_behind_proxy;
            proxy_set_header Host mytargetdomain.com:443;
        }

}
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.