用nginx做站的时候,经常遇到一些跳转需求,比如
- 根据子域名不同跳转至其他网站
- 如果用户打了IP或者example.com要跳转至www.example.com
- 启用了https以后,需要将原来整站http跳转至https
- 网站临时维护,需要暂时把网站跳转到临时维护页面,详情看我之前的博客:https://blog.terrynow.com/2021/01/01/nginx-setup-maintain-page/
server { listen 80; server_name mail.example.com; #根据子域名不同跳转至其他网站 rewrite ^/(.*)$ http://exmail.qq.com permanent; } server { listen 80; server_name mail.example.com; #根据子域名不同跳转至其他网站 #这种会根据后面的网址换的,上面那种网址写死了 rewrite ^/(.*)$ http://exmail.qq.com/$1 permanent; } server { # 只要域名不是www.example.com都跳转到www.example.com if ($http_host != www.example.com) { #return 301 http://www.example.com$request_uri; rewrite ^(.*)$ https://www.example.com$1 permanent; } } server { listen 80; server_name _; #全站http跳转至https location / { rewrite ^/(.*)$ https://www.example.com/$1 permanent; } } server { #*** listen 80; #可能有多个域名,某一个域名的转到https if ($http_host = crm.example.com) { return 301 https://crm.example.com$request_uri; } #rewrite all traffic to https #rewrite ^/(.*) https://www.example.com/$1 permanent; #or或者全部http转到https #return 301 https://$host$request_uri; #跳转到子应用 #location / { # if ( $request_uri = "/" ) { # rewrite "/" http://www.example.com/mdayi break; # } #} #首页跳转到子应用mdayi,比如tomcat的某个应用 location =/ { rewrite / /mdayi; } }
文章评论
cialis for sale Avcnoq Laalhl - canadian pharmacy cialis 20mg Ynymlk