https方式nginx 代理tomcat访问不带www的域名301重定向跳转到www的域名帮助seo集中权重

时间:2022-04-24 14:47:19

比如我要把

http://gucanhui.com

http://www.gucanhui.com

跳转到https://www.gucanhui.com

用F12的network可以看到状态码301,一定不能是302

需要注意的是,只需要nginx开启ssl就行了,tomcat和nginx还是走http就行

所以证书配置,只需要在nginx上配置

配置http不带www的跳转到https带www的

server {
listen ;
server_name gucanhui.com;
return https://www.gucanhui.com$request_uri;
}

然后http带www的跳转到https带www的

server {
listen ;
server_name www.gucanhui.com; #charset koi8-r; #access_log logs/host.access.log main; location / { return https://www.gucanhui.com$request_uri;
}

然后再443端口配置证书和跳转就行了

 # HTTPS server
#
server {
listen ssl;
server_name www.gucanhui.com; ssl_certificate gucanhui.com.crt;
ssl_certificate_key gucanhui.com.key; ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; location / {
proxy_pass http://127.0.0.1:8080;
}
}