Nginx安装SSL安全证书

1、 在Nginx的安装目录下的config目录下创建cert目录,并且将下载的证书全部文件拷贝到cert目录中。如果申请证书时是自己创建的CSR文件,请将对应的私钥文件放到cert目录下并且命名为20180907.key;
2、  打开 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;
        }
    }
3、  重启Nginx服务器
4、  使用https域名访问网站
posted @ 2018-09-07 09:32  HUI9527  阅读(3621)  评论(0编辑  收藏  举报