0

I'm setting up a ghost instance in a subdirectory, and want to point the root (/) to a static page. This is what I have in my nginx conf.

location / { 
  rewrite ^ /blog/about break; 
}

location ^~ /blog {
  proxy_pass http://localhost:2368;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_buffering off;
}

The good news is that the redirect for the root works, in that the user is redirected to the right page (/blog/about). However, his URL address also works. I didn't expect this to happen with the rewrite, can someone help me point out what's wrong here?

Newy
  • 38,977
  • 9
  • 43
  • 59

1 Answers1

1

You need to change 'break' into 'last'.

The 'break' means that it is not going to try any other location block after the current one. I'm guessing your application is doing the redirect at that point. Your logs should confirm this.

Also, you should use:

proxy_redirect off;
LinuxJedi
  • 31
  • 3
  • Thanks for your tip, but unfortunately the redirecting behavior is still happening even after I switch 'break' to 'last'. The user's browser URL is still changed to /blog/about. – Newy Jul 09 '15 at 01:13
  • Added information in my answer about proxy_redirect. If that doesn't fix it then something external to this configuration is causing it. Possible other causes: 1. browser caching a 301 (try in incognito mode), 2. some other configuration in Nginx, 3. the application in localhost:2368 is providing the redirect header – LinuxJedi Jul 10 '15 at 06:17