一、申请阿里云免费证书

二、配置nginx 配置https

把证书上传至nginx cert目录下

4.png

    server {    
        listen 80;
        listen 443 ssl;
        root /code/coding/zhangzhengshan;
        index index.php index.htm index.html;
        #server_name 114.55.116.177;
        server_name www.zhangzhengshan.com;
        access_log /home/wwwlogs/lvs_access.log;
        error_log /home/wwwlogs/nginx_error.log;
        #ssl on;
        ssl_certificate /usr/local/nginx/cert/3371704_www.zhangzhengshan.com.pem;
        ssl_certificate_key /usr/local/nginx/cert/3371704_www.zhangzhengshan.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers on;
        if ($server_port = "80") {
             return 301 https://$host$request_uri;
        }
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        
        location ~ .*.(gif|jpg|jpeg|png|bmp|ico|swf|mp3|wma)$ {
            expires 365d;
        }
        location ~ .*.(js|css)$ {
            expires 30d;
        }
        include enable-php.conf;
        
        location ~ /\.ht {
            deny all;
        }
        location  ~ /\.git {
            deny all;
        }
     }