nginx将http重定向到https和让二级域名重定向到顶级域名

新手上路,请多包涵

请问一下怎么让http重定向到https和二级域名重定向到顶级域名存在同一个nginx的conf里?

阅读 4k
1 个回答

HTTP重定向到HTTPS(HTTPS监听443端口。同一端口多个域名的话,需要设置server_name)

server {

listen  80;  
server_name domain.com;
rewrite ^(.*)$  https://$host$1 permanent;  

}

二级域名重定向到顶级域名:

server {

listen  80;
server_name *.domain.com;
rewrite ^/(.*) http://domain.com/$1 permanent;

}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题