How to tell nginx to redirect all pages of the website to root?

configuration, nginx, redirect

Solution

The following should do what you want:

server {
  listen 80;

  root /var/www/mysite;
  location = / { try_files /index.html = 404;}

  location / { rewrite ^ / permanent; }
}

Problem

I'm closing down a website and I need nginx to redirect all users to the root and not just show them the same page on all website urls. For now I have this: ``` server { listen 80; root /var/www/mysite; rewrite ^.*$ /index.html last; } ``` However this doesn't redirect, but rather shows `index.html` content everywhere. How do I do a redirect so that `mysite.com/somepage` would redirect to `mysite.com` which, in turn, would show index.html page?

Original source