Nginx配置https

nginx.conf配置

http请求配置,监听80端口跳转到https请求

server{
    listen 80;
    server_tokens off;
    server_name www.whmake.site;
    keepalive_timeout 5;
    client_max_body_size 50m;
    rewrite ^(.*)$ https://$host$1 permanent;
}

https请求配置, 监听443端口

server {
    listen 443 ssl;
    server_tokens off;
    server_name www.whmake.site;
    keepalive_timeout 5;
    client_max_body_size 50m;
    root /usr/local/www/softwares/whmake;
    index index.php index.html;
    include /www/server/panel/vhost/nginx/proxy/whmake.local/*.conf;
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/whmake.local.conf;
    #REWRITE-END
    ssl_certificate cloud.tencent.com_bundle.crt; #填写您的证书文件名称,例如:cloud.tencent.com_bundle.crt
    ssl_certificate_key cloud.tencent.com.key; #填写您的私钥文件名称,例如:cloud.tencent.com.key
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;  # 可参考此 SSL 协议进行配置
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;   #可按照此加密套件配置,写法遵循 openssl 标准
    ssl_prefer_server_ciphers on;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }

    access_log  /www/wwwlogs/whmake.log;
    error_log  /www/wwwlogs/whmake.error.log;
}