如何配置nginx支持https访问------nginx开启ssl

1、申请ssl证书过程就不在多说,很多IDC都有免费域名型证书。

下面我贴出配置文件

server{
         listen 443;
         server_name test.ildd.cc;
         root /usr/local/nginx/html/test.ildd.cc;
         index index.php index.html; 
         ssl on;
         ssl_certificate /usr/local/nginx/cert/test.ildd.cc.crt;
         ssl_certificate_key /usr/local/nginx/cert/test.ildd.cc.key;
         ssl_session_timeout 5m;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
         ssl_prefer_server_ciphers on;

          location ~* .php$ {
          fastcgi_index   index.php;
          fastcgi_pass    127.0.0.1:9000;
          include           fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
                                 }
     }
     server{
         listen 80;
         server_name test.ildd.cc;
         rewrite ^/(.*)$ https://test.ildd.cc:443/$1 permanent;
     }

第二个server的意思是去重定向http的协议

重启nginx服务区测试访问

[root@2df7fb5c5f50 nginx]# nginx -t
 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
 nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
 [root@2df7fb5c5f50 nginx]# nginx -s reload

发表评论

登录... 后才能评论