Permanent redirects with Nginx

Recently, I had the need to redirect all traffic from one domain to identical URLs on a new domain.  Luckily, NGINX provides a simple way to accomplish this.

The following will work as an available site for domain on any NGINX version after 0.9.1:

server {
return 301$request_uri;

The server will listen on port 80 for request to and redirect to the same request at

Note that the server is being asked to provide a 301 status code to inform the requesting client that the redirect is permanent. If you are wishing to redirect encrypted traffic then you will need a similar block listening at port 443.