Search code examples
nginxdotcloud

Redirecting from subdomain to folder on Dotcloud


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?


Solution

  • 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;
    }