How to block search engines in the nginx

How to block search engines in the nginx

If you have three layered development structures (local dev, remote staging, remote production) like me, you want to search engines index your staging server. It is easy to prevent search engines from indexing your Nginx web server.

add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";

Add the line above in the server block virtualhost file and Google forget the way to go to your server.