Nginx配置HTTPS与HTTP2.0

server
{
    //配置80端口301到443
    //强制使用https
    listen 80;
    server_name hamm.cn;
    return 301 https://$server_name$request_uri;
}

server
{
    //使用https 443端口并开启http2
    listen 443 ssl http2;
    server_name www.hamm.cn hamm.cn;
    if ( $http_host = www.hamm.cn ) {
        //www跳转到根域
        rewrite  (.*)  https://hamm.cn$1;
    }
    index index.php index.html;
    root  /home/wwwroot/hamm.cn/;
    ssl on;
    //设置证书
    ssl_certificate /asserver/https/hamm.cn/pem.pem;
    ssl_certificate_key /asserver/https/hamm.cn/key.key;
    ssl_session_timeout 5m;
    //设置使用协议版本
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
    ssl_session_cache builtin:1000 shared:SSL:10m;
    
    include enable-php.conf;
    
    //长期缓存的静态文件
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }
    //短期缓存的静态文件
    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }
    
    location ~ /.well-known {
        allow all;
    }
    
    location ~ /\.
    {
        deny all;
    }
    
    access_log off;
}