https的支持

2019年07月18日 06:07:39

1、在阿里云购买SSL证书,选择免费的。https://common-buy.aliyun.com/?spm=5176.2020520163.cas.3.72cbnT9pnT9pvl&commodityCode=cas#/buy

2、购买完成后还需要进入申请,最终审核成功下载证书,并传到服务器。

3、记得要开发443防火墙

iptables -A INPUT -p tcp --dport 443 -j ACCEPT
service iptables save

配置参考

#/etc/nginx/nginx.conf

# Settings for a TLS enabled server.

  server {

    listen    443 ssl http2 default_server;

    listen    [::]:443 ssl http2 default_server;

    server_name _;

    root     /usr/share/nginx/html;

    ssl_certificate "/data/cert/kacoro.com/2521486_www.kacoro.com.pem";

    ssl_certificate_key "/data/cert/kacoro.com/2521486_www.kacoro.com.key";

    ssl_session_cache shared:SSL:1m;

    ssl_session_timeout 10m;

    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_prefer_server_ciphers on;

    # Load configuration files for the default server block.

    include /etc/nginx/default.d/*.conf;

    location / {

    }

    error_page 404 /404.html;

      location = /40x.html {

    }

    error_page 500 502 503 504 /50x.html;

      location = /50x.html {

    }

  }

#/etc/nginx/conf.d/kacoro.com.conf

 upstream sample {

  server 127.0.0.1:3000;

  keepalive 64;

}

server {

  listen 443;

  server_name kacoro.com www.kacoro.com;

  location / {

     proxy_redirect off;

     proxy_set_header X-Real-IP $remote_addr;

     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

     proxy_set_header X-Forwarded-Proto $scheme;

     proxy_set_header Host $http_host;

     proxy_set_header X-NginX-Proxy true;

     proxy_set_header Connection "";

     proxy_http_version 1.1;

     proxy_pass http://sample;

   }

}

server {

  listen 80;

  server_name kacoro.com www.kacoro.com;

  rewrite ^(.*)$ https://$host$1 permanent;

}