Nginx安装SSL安全证书

一、 在Nginx的安装目录下的config目录下建立cert目录,而且将下载的证书所有文件拷贝到cert目录中。若是申请证书时是本身建立的CSR文件,请将对应的私钥文件放到cert目录下而且命名为20180907.key;
二、  打开 Nginx 安装目录下 conf 目录中的 nginx.conf 文件,找到:
HTTPS server配置项,粘贴如下配置

    server {
        listen 443 ssl; #删掉 ssl on; 配置项 ssl写在443端口后面

        server_name www.***.com; #你的域名
        
        root html; #你的网站根目录
        index index.php index.html index.htm; #网站默认访问文件
        
        ssl_certificate   cert\20180907.pem; #证书文件
        ssl_certificate_key  cert\20180907.key; #秘钥文件
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        
        location / {
            root html; #网站根目录
            index index.php index.html index.htm; #网站默认访问文件
        }
        
        location ~ \.php(.*)$  { #PHP必须的配置,不然浏览器访问会直接下载php源码文件
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
    }
三、  重启Nginx服务器
四、  使用https域名访问网站
相关文章
相关标签/搜索