Nginx 如何实现url重定向
墨初 服务器 962阅读
现在用 nginx 服务器的站长越来越多,而今天就记录一下在 nginx 中设置 url 重定向的方法,方便别人也方便自己!
nginx url重定向的设置方法
1、所有的 HTTP 请求转为带 www 的 HTTPS 请求
server { listen [::]:80; listen 80; server_name 73so.com www.73so.com; # 修改成你自己的网址 return 301 https://www.73so.com$request_uri; } server { listen [::]:443 ssl http2; listen 443 ssl http2; # 修改成你自己的网址 server_name www.73so.com; }
2、将不带 www 的HTTP/HTTPS请求转成带 www 的HTTP/HTTPS请求
server { listen [::]:80; listen 80; server_name 73so.com www.73so.com; # 修改成你自己的网址 return 301 https://www.73so.com$request_uri; } server { listen [::]:443 ssl http2; listen 443 ssl http2; server_name 73so.com; # SSL code # 注意修改网址 return 301 https://www.73so.com$request_uri; } server { listen [::]:443 ssl http2; listen 443 ssl http2; server_name www.73so.com; # SSL code # othor code # 注意修改网址 }
3、将带 www 的 HTTP/HTTPS 的请求转换为不带 www 的 HTTPS 请求
server { listen [::]:80; listen 80 server_name 73so.com www.73so.com; # 注意修改网址 return 301 https://73so.com$request_uri; } server { listen [::]:443 ssl http2; listen 443 ssl http2; server_name www.73so.com; # ssl code # 注意修改网址 return 301 https://73so.com$request_uri; } server { listen [::]:443 ssl http2; listen 443 ssl http2; server_name 73so.com; # ssl code # 注意修改网址 }
标签:nginx