John Siu Blog

Tech - Business Tool, Personal Toys

Nginx Config

☰ Table of Content

Some quick nginx config.

Regex string must be put inside double quote.

/index.php/YYYY/MM/DD/<post> to /blog/<post>

1
location ~ "^/index.php/\d{4}/\d{2}/\d{2}/(.*)$" { return 301 https://johnsiu.com/blog/$1; }

/index.php/<post> to /blog/<post>

1
location ~ "^/index.php/(.*)$" { return 301 https://johnsiu.com/blog/$1; }

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

1
location /<post> { return 301 https://johnsiu.com/blog/<post>; }

Multiple Domains Redirect

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

1
2
3
4
5
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

Update: 2022-05-12
comments powered by Disqus