Set the Preferred Domain for your Ghost Blog

Unlike in WordPress where you set a site url in the admin area and WordPress handles all the www/non-www redirects for you – ghost does not (yet).

Setting up the redirect is fairly easy, ssh into your server and open the nginx configuration for your site. Add one server block for each redirect you want to have:

As mentioned above, if you want another redirect add it in a seperate server block. Note that instead of rewriting that part of the url that differs, like we would do for apache, the new url is completely returned. This allows us to specify a HTTP response status (301 - permanent in this case) and is also faster than a rewrite.

After saving and closing the nginx.conf you will have to restart the webserver (either nginx -t && nginx -s reload or service nginx restart) and verify that we get the correct HTTP response:

curl -I

This should output something like:

HTTP/1.1 301 Moved PermanentlyServer: nginx/1.1.19Date: Tue, 21 Jan 2014 22:14:52 GMTContent-Type: text/htmlContent-Length: 185Connection: keep-aliveLocation:

That should be about it, if you want to know a little more on the syntax check this page or the official documentation.