linux contenos下nginx配置ssl证书实现https访问

原文地址:https://www.cnblogs.com/tianhei/p/7726505.html

本文主要是记录一下nginx配置ssl的方式

linux contenos下nginx配置ssl证书实现https访问一,环境说明

服务器系统:ubuntu16.04LTS

服务器IP地址:47.89.12.99

域名:bjubi.com

二,域名解析到服务器

在阿里云控制台-产品与服务-云解析DNS-找到需要解析的域名点“解析”,进入解析页面后选择【添加解析】按钮会弹出如下页面:

主机记录这里选择@,记录值就是服务器ip地址,确认。

linux contenos下nginx配置ssl证书实现https访问

三,申请ca证书

在阿里云控制台-产品与服务-安全(云盾)-CA证书服务(数据安全),点击购买证书,

linux contenos下nginx配置ssl证书实现https访问

选择“免费版DV SSL”,点击立即购买:

linux contenos下nginx配置ssl证书实现https访问

然后点去支付:

linux contenos下nginx配置ssl证书实现https访问

最后确认支付:

linux contenos下nginx配置ssl证书实现https访问

就会回到管理界面:

linux contenos下nginx配置ssl证书实现https访问

点击“补全”,输入要解析的域名,点下一步:

说明:因为我们这里申请的是开发版免费证书,所以一个证书仅支持一个域名认证,不支持通配符。

linux contenos下nginx配置ssl证书实现https访问

等待几分钟,证书状态变为“已签发”后,证书就申请成功了。

四,下载证书

列表中找到已签发的证书,下载:

linux contenos下nginx配置ssl证书实现https访问

进入下载页面,找到ngin页签中nginx配置信息,并“下载证书 for Nginx”:

linux contenos下nginx配置ssl证书实现https访问

记录以下内容,为了一会儿配置nginx用:

linux contenos下nginx配置ssl证书实现https访问

下载的文件有两个:

1,214292799730473.pem

2,214292799730473.key

Nginx配置安装参考地址:

https://blog.csdn.net/liqi_q/article/details/72965128

特别注意的地方:./configure --prefix=/root/software/nginx_soft/nginx  --with-http_ssl_module

在nginx安装一文中有此处

server {

     listen 443;
    server_name nas-crazy.top localhost;
    ssl on;
    #listen 80;
    #server_name _;
    charset utf-8;
    #rewrite ^(.*)$ https://$host$1 permanent;

    ssl_certificate  cert/1816984_nas-crazy.top.pem;
    ssl_certificate_key cert/1816984_nas-crazy.top.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.html index.htm;
    proxy_pass http://cloud_server;
    proxy_redirect off;
    proxy_redirect     http://host http://host:8080;
    # 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
}
location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
#    expires 7d;
    proxy_pass http://cloud_server;
}
location ^~ /statics/ {
            root   html/DTS;
        }