Skip to content

Latest commit

 

History

History
executable file
·
33 lines (24 loc) · 592 Bytes

nginx 配置 301 永久重定向.md

File metadata and controls

executable file
·
33 lines (24 loc) · 592 Bytes

nginx 配置 301 永久重定向

将 HTTP 永久重定向到 HTTPS:

# redirect http to https
server {
  listen 80;
  server_name avincheng.com;
  return 301 https://avincheng.com$request_uri;
}

将带的 www 二级域名永久重定向到对应的一级域名:

# redirect www to root
server {
  server_name www.avincheng.com;
  return 301 $scheme:https://avincheng.com$request_uri;
}

重启 nginx 服务:

sudo systemctl restart nginx

参考文献