HTTPS

作者: UncleZ_strive | 来源:发表于2019-09-26 17:29 被阅读0次

    1.HTTPS注意事项

    Https不支持续费,证书到期需重新申请新并进行替换。
      Https不支持三级域名解析,如 test.m.oldboy.com。
      Https显示绿色,说明整个网站的url都是https的,并且都是安全的。
      Https显示黄色,说明网站代码中有部分URL地址是http不安全协议的。
      Https显示红色,要么证书是假的,要么证书已经过期。

    2.HTTPS证书

    • 创建存放ssl证书的路径
    [root@Nginx ~]# mkdir -p /etc/nginx/ssl_key
    [root@Nginx ~]# cd /etc/nginx/ssl_key
    

    1.生成证书 (密码1234)

    [root@Nginx ~]# openssl genrsa -idea -out server.key 2048
    

    2.生成自签证书,同时去掉私钥的密码

    openssl req -days 36500 -x509 \
    -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
    

    3.配置nginx

    [root@web01 conf.d]# cat s.oldux.com.conf 
    server {
        listen 443 ssl;
        server_name s.oldxu.com;
        root /code;
        ssl_certificate ssl_key/server.crt;
        ssl_certificate_key ssl_key/server.key;
    
        location / {
            index index.html;
        }
    }
    server {
        listen 80;
        server_name s.oldxu.com;
        return 302 https://$http_host$request_uri;  
    }
    

    3.HTTPS优化相关参数

    server {
        listen 443 ssl;
        server_name nginx.bjstack.com;
        
        ssl_certificate ssl_key/1524377920931.pem;
        ssl_certificate_key ssl_key/1524377920931.key;
        ssl_session_cache shared:SSL:10m;   #在建立完ssl握手后如果断开连接,在session_timeout时间内再次连接,是不需要在次建立握手,可以复用之前的连接
        ssl_session_timeout 1440m;           #ssl连接断开后的超时时间
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用的TLS版本协议
        ssl_prefer_server_ciphers on;        #Nginx决定使用哪些协议与浏览器进行通讯
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #配置加密套间
    
    l   ocation / {
            root /soft/code;
            index index.html index.htm;
        }
    }
    server {
            listen 80;
            server_name nginx.bjstack.com;
            return 302 https://$server_name$request_uri;
    }
    

    4.HTTPS配置过程

    先配置好后端的web节点
    在负载均衡上申请证书(如果之前申请过也可以推送)
    配置nginx负载均衡--->http协议
    配置域名劫持
    配置nginx负载均衡--->转为https协议

    HTTPS实例

    需求: 部分URL走https,部分不走https
    [root@lb01 conf.d]# cat proxy_s.oldxu.com.conf 
    upstream webs {
        server 172.16.1.7:80;
        server 172.16.1.8:80;
    }
    
    server {
        listen 443 ssl;
        ssl_certificate ssl_key/server.crt;
        ssl_certificate_key ssl_key/server.key;
    
        server_name s.oldxu.com;
        location / {
            proxy_pass http://webs;
            include proxy_params;
        }
    }
    server {
        listen 80;
        server_name s.oldxu.com;
        
        if ($request_uri ~* "^/login") {
            return 302 https://$http_host$request_uri;
        }
    
        location / {
            proxy_pass http://webs;
            include proxy_params;
        }
    }
    
    需求: 当用户请求s.oldxu.com/abc时走http,其他的所有都走https?
    [root@lb01 conf.d]# cat proxy_s.oldxu.com.conf 
    upstream webs {
        server 172.16.1.7:80;
        server 172.16.1.8:80;
    }
    
    server {
        listen 443 ssl;
        ssl_certificate ssl_key/server.crt;
        ssl_certificate_key ssl_key/server.key;
    
        server_name s.oldxu.com;
        location / {
            proxy_pass http://webs;
            include proxy_params;
        }
    }
    server {
        listen 80;
        server_name s.oldxu.com;
        
        if ($request_uri !~* "^/abc") {
            return 302 https://$http_host$request_uri;
        }
    
        location / {
            proxy_pass http://webs;
            include proxy_params;
        }
    }
    

    相关文章

      网友评论

          本文标题:HTTPS

          本文链接:https://www.haomeiwen.com/subject/eopwuctx.html