3

I am trying to set up nginx to behave as a reverse proxy listening on a subdomain we control. I have followed examples found online and they mostly work with one exception that isn't clear to me.

Inspect the server block below:

server{
    listen *:80;
    server_name placehold.com;
    charset utf-8;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log error;

    location / {
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;

        proxy_pass http://google.com/;
    }
}

google.com is a placeholder for this test.

If i visit a url like "http://placehold.com/test" this works perfectly, it redirects me to some google error page and the url in the browser stays as types. But if I put a bare url like "http://placehold.com/" then it redirects my browser to the google homepage, the google url clearly showing in the browser.

How can I get the reverse proxy to properly mask the url for '/' urls as well as '/with/some/path' urls?

1 Answers1

2

Your proxy is working fine. Visitng http://google.com returns:

301 Moved Permanently
Location:https://www.google.com/

Your browser is being redirected to http://www.google.com

heavyd
  • 62,847
  • 18
  • 155
  • 177
  • ah, so you mean to tell me that my "problem" is just because I chose an improper test url, google.com? If I chose any other url which did not have a 3** redirect I would have seen the expected behaviour? – Radmilla Mustafa Jul 25 '14 at 20:59
  • Yep, sure looks that way. – heavyd Jul 25 '14 at 21:00