Java技术升华JavaScriptJava技术问答

Nginx配置SSL

2018-10-15  本文已影响241人  ChangLau

必要条件

域名、然后可以在(阿里云、腾讯云)申请免费SSL证书

域名列表png

配置SSL关联到对应域名

一般申请注册阶段就配置好了

WX20181015-222059@2x.png

下载证书

下载证书.png

Nginx配置SSL

由于我的服务通过Nginx部署,所以下载Nginx认证证书。配置Nginx

上传文件.png nginx配置.png

https协议默认监听443接口,通过http请求过来的内容,会通过rewrite进行强制转换为https,然后转发到443接口。所以此配置会强制将http请求转化为https请求。现在如果完成了以上配置,就可以看到请求全部转化为https啦。


另一种配置方式

server {  
    listen 80;
    server_name  www.coffeecola.cn;
    return 301 https://www.coffeecola.cn$request_uri;
}

server {
   listen 443 ssl;
   server_name www.coffeecola.cn;

   ssl on;
   ssl_certificate   /etc/nginx/cert/215095583230016.pem;
   ssl_certificate_key  /etc/nginx/cert/215095583230016.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;

   root          /root/blog_front/dist/;

   location / {
       index     index.html index.htm;
       autoindex on;
   }

   location /api/ {
       proxy_pass https://www.coffeecola.cn:8080/;
   }

   error_page 404 /404.html;
       location = /40x.html {
   }

   error_page 500 502 503 504 /50x.html;
       location = /50x.html {
   }
}
上一篇 下一篇

猜你喜欢

热点阅读