3

For all our sites we have an include file which contains several things, amongst this line:

location / { 
    try_files $uri /index.php?$query_string;
}

For a single site, we do want to redirect all requests from mysite.com/ to mysite.com/blog, as a temporary "fix". The block looks like this:

server {
    server_name mysite.com;
    root        /var/www/mysite;
    include     conf.d/common.conf.inc;

    # Redirect blog
    location / {
        rewrite / /blog redirect;
    }
}

This fails however, with the following error:

Testing nginx configuration: nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/mysite:7

The question

How can we have a server block with location / {} for the try_files and redirect all requests from / to /blog?

2

You may try as a solution to make redirect only from exatly root location:

 location = / {
        rewrite / /blog redirect;
    }
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.