比如我要把

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       80;
        server_name  gucanhui.com;
        return       301 https://www.gucanhui.com$request_uri;
    }

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

server {
        listen       80;
        server_name  www.gucanhui.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            
            return       301 https://www.gucanhui.com$request_uri;
        }

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

 # HTTPS server
    #
    server {
        listen       443 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;
        }
    }

 

相关文章:

  • 2021-09-17
  • 2022-02-11
  • 2021-07-18
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
相关资源
相似解决方案