0

Is it possible to redirect from a subdomain to a folder using the application nginx.conf on Dotcloud?

I want to redirect http://blog.domain.com to http://www.domain.com/blog

I may be wrong but as I understand the content of the application level nginx.conf is inserted into a server block of the main nginx.conf.

I've tried the following directive in the nginx.conf but it doesn't work:

rewrite http://blog.domain.com http://www.domain.com/blog/ permanent;

Has anyone else managed to do this?

Mark Unsworth
  • 3,027
  • 2
  • 20
  • 21

1 Answers1

0

Ok, so I figured this out. Whilst Ifs are considered evil in nginx this was the best I could do:

if ($http_host = "blog.domain.com") {
    rewrite ^/(.*)$ http://www.domain.com/blog/$1?$args;
}
Mark Unsworth
  • 3,027
  • 2
  • 20
  • 21
  • [Here's](http://serverfault.com/a/426763/134641) another way without using the `if` directive. – ivvi May 23 '13 at 13:50
  • @seron Unfortunately the way that Dotcloud works you can't declare another server directive; they inject your nginx config inside the main server directive for the domain. – Mark Unsworth Jun 07 '13 at 10:16