Nginx+php配置https

首先去阿里云的ca证书下载你自己的证书文件,没有的就买。下载的时候注意下载对应的,nginx下载nginx的。apache下载apache的。

然后就是nginx的配置文件修改了

server {

     listen 443;

     server_name www.域名.com; # 你的域名

     ssl on;

     ssl_certificate /cert/214403122310501.pem; # 改成你的证书路径加名字

     ssl_certificate_key /cert/214403122310501.key; #你的证书路径加名字

     ssl_session_timeout 10m;

     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;

     root          /home/www  #站点目录

     location / {

         index index.php index.html;

         if (!-e $request_filename) {

         rewrite ^/(static|assets|img|js|css|font)/.* break;

         rewrite ^/(.*)$ /index.php/$1 last;

     }

 }

     error_page  500 502 503 504 /50x.html;

         location = /50x.html {

             root  html;

        }

     location ~ \.php {

         fastcgi_pass  127.0.0.1:9000;

         fastcgi_index index.php;

         fastcgi_split_path_info ^(.+\.php)(.*)$;  #增加这一句

         fastcgi_param PATH_INFO $fastcgi_path_info; #增加这一句             

         fastcgi_param SCRIPT_FILENAME  /home/www$fastcgi_script_name;

         include fastcgi_params;

     }

 }

#将http转https

server {

     listen 80;

     server_name www.域名.com;     # 你的域名

     rewrite ^(.*)$ https://$host$1 permanent;     # 把http转https请求

 }

注意:检查防火墙

vim /etc/sysconfig/iptables把443端口也开放

重启iptable和nginx 就好了

这是我遇到的坑,找了好多文档都没提到这个

你可能感兴趣的:(Nginx+php配置https)