By Alan


2017-10-29 10:24:24 8 Comments

I need to pass a host proxy URL to connect to other URLs mentioned as proxy pass in nginx.

Example: If I have to connect to google.com through a Linux server box, I have to set proxy as xyz.org:80 and only then I can connect to google.com.

So how can I achieve it in nginx config?

My Nginx config file sample goes like this:

    server{
       listen     80;
       server_name   *;
      return 301     https://$host$request_uri;
    }
    location / {
      sendfile            on;
      try_files           $uri $uri/ /index.html
                          /keepalive.html;
    }
    location /xyz{
       proxy_pass     google.com/
    }

Here, I need to pass my proxy xyz.org:80 in the Nginx config itself and only then I can connect to google.com/.

So basically, every request from my server box should pass via xyz.org:80 to the proxy_pass location mentioned in nginx config.

I tried mapping the http host and served host and passing it in the location but it is not working:

map $http_host $served_host {
        default $http_host;
        xyz.org:80 www.google.com;
    }

location /xyz{
           proxy_pass     google.com/;
         proxy_set_header Host $served_host;
        }

0 comments

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] Keycloak Redirect url with nginx is going to http rather than https

  • 2018-04-03 12:02:15
  • Atulya Nair
  • 750 View
  • 2 Score
  • 2 Answer
  • Tags:   nginx jboss

7 Answered Questions

[SOLVED] How to preserve request url with nginx proxy_pass

2 Answered Questions

[SOLVED] Express - req.ip returns 127.0.0.1

0 Answered Questions

How to write NGINX config file to use ReactJS? (on Docker)

  • 2018-09-30 18:01:56
  • Wilson López Romero
  • 42 View
  • 0 Score
  • 0 Answer
  • Tags:   reactjs docker nginx

0 Answered Questions

Nginx as a forward proxy

0 Answered Questions

Passing a proxy URL before using proxy pass in Nginx config

1 Answered Questions

Nginx win server 2012 - Configure proxy pass

  • 2017-07-31 15:02:09
  • johns193
  • 221 View
  • 0 Score
  • 1 Answer
  • Tags:   nginx proxy

2 Answered Questions

How to point many paths to proxy server in nginx

0 Answered Questions

2 Answered Questions

[SOLVED] nginx and trailing slash with proxy pass

Sponsored Content