6

Has anyone any idea of how to setup nginx behind a corporate firewall, to reverse proxy requests to servers outside the firewall?

The reason I want to do this is I am trying to use an application that doesn't support the standard http_proxy settings by fooling it to think the resources in question are inside the firewall (i.e. reverse proxying them with nginx).

I have tried the following:

First tried proxy_pass and passing the host:

http {

  upstream corporate_proxy  {
      server web-proxy.mycorp.com:8080;
  }

  server {
    listen 80;
    rewrite_log on;
    location / {
          proxy_buffering off;
          proxy_pass_header on;
          proxy_set_header Host "http://public-website.com";
          proxy_pass http://corporate_proxy;
    }
  }
}

Second tried rewriting and passing the url to the corporate firewall:

http {

  upstream corporate_proxy  {
      server web-proxy.corp.hpecorp.net:8080;
  }

  server {
    listen 80;
    rewrite_log on;
    location / {
          rewrite ^(.*)$ "http://public-website.com$1" break;
          proxy_buffering off;
          proxy_pass_header on;
          proxy_pass http://corporate_proxy;
    }
  }
}

This approach got me initially excited, however it is actually just doing a redirect, and not properly proxying, and ultimately fails. Is there something I am missing here?

Edit: Thanks to the commenter below that spotted my mistake, I had the protocol in the Host header var - removing it solved the problem - approach #1 seems to work just fine.

Mark D
  • 191
  • 1
  • 6
  • Your first example has an invalid value for the `Host` header. Nginx debug logs for request processing would probably be enlightening, too. – womble Oct 27 '15 at 20:52
  • You sir are a beaut! Fixing the host header totally sorted it for me - thanks a million! – Mark D Oct 27 '15 at 22:31
  • 4
    That's good, but what if the destination protocol is HTTPS? I couldn't find a way to override that – Nikolay Dimitrov May 04 '17 at 09:50

0 Answers0