Nginx Config

Table of Contents

Some quick nginx config.

Regex string must be put inside double quote.

/index.php/YYYY/MM/DD/<post> to /blog/<post>
location ~ "^/index.php/\d{4}/\d{2}/\d{2}/(.*)$" { return 301$1; }
/index.php/<post> to /blog/<post>
location ~ "^/index.php/(.*)$" { return 301$1; }```

This is mainly use to redirect Ghost permalink, which has no prefix, to Hugo format.

location /<post> { return 301<post>; }

Multiple Domains Redirect

Redirect all traffic hitting nginx to <your domain>. Not affect domain defined in other server block.

server {
  listen  80;
  server_name _;
  return 302 https://<your domain>$request_uri;

302(temporary) is used instead of 301(permanent) in case you want to use those domains in the future.

John Siu
Minimize the Effort, Maximize the Effect!
comments powered by Disqus