Skip to content

Instantly share code, notes, and snippets.

@miladoll
Created July 18, 2020 05:31
Show Gist options
  • Save miladoll/a2f1631cde965766e05a1bac0dfc36f6 to your computer and use it in GitHub Desktop.
Save miladoll/a2f1631cde965766e05a1bac0dfc36f6 to your computer and use it in GitHub Desktop.
# Nginx で
# www.hogehoge.com -> hogehoge.com
# http://{www.}hogehoge.com -> https://hogehoge.com
# に一気に正規化する設定の例
# server コンテキスト
set $redirect_canon_url "";
set $canon_host $host;
if ( $host ~ ^www\.(.*)$ ) {
set $canon_host $1;
}
if ( $scheme = "http" ) {
set $redirect_canon_url "canon";
}
if ( $host ~ ^www\. ) {
set $redirect_canon_url "canon";
}
if ( $redirect_canon_url = "canon" ) {
return 301 https://$canon_host$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment