美文网首页
nginx/1.18.0进行SSL证书配置

nginx/1.18.0进行SSL证书配置

作者: 素时年锦 | 来源:发表于2020-08-08 03:07 被阅读0次

服务器:腾讯云服务器
nginx版本:nginx/1.18.0 nginx下载地址
CentOS: CentOS Linux release 7.6.1810 (Core)

查看安装了哪些模块,nginx -V 显示的很乱,看起来不是很方便,如下:

没排版的样式

可以输入下面的命令,就可以很清晰查看安装了哪些模块了

nginx -V 2>&1 | sed "s/\s\+--/\n --/g"
排版后的样式

进入正题,开始配置SSL证书

  • 这里我用的是腾讯云服务器,点击下载证书


    下载位置
  • 下载后有个这个文件夹


    下载后文件夹
  • 打开文件夹,找到nginx文件


    图示
  • 打开nginx文件里面两个文件复制一下


    图示
  • 这个时候连接到云服务器
    把刚刚nginx文件里面复制的两个文件,放在/etc/nginx/conf文件中
    图示
  • 通过vim /etc/nginx/conf.d/default.conf进行编辑配置,将下面的www.yubo365.cn换成你的域名
server {
    listen       80;
    #server_name  localhost;
    server_name www.yubo365.cn;
    return       301 https://$server_name$request_uri;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    #location / {
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
    #}

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #error_page   500 502 503 504  /50x.html;
    #location = /50x.html {
        #root   /usr/share/nginx/html;
    #}

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
server {
    listen       443 ssl;  # nginx1.15之后用这个语法,老的语法是ssl on;
    server_name  service.yuming.com;
    ssl_certificate   /etc/nginx/conf/1_www.yubo365.cn_bundle.crt;
    ssl_certificate_key  /etc/nginx/conf/2_www.yubo365.cn.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 / {
       root   /usr/share/nginx/html;
       index  index.html index.htm;
    }
    #location / {
       #proxy_set_header Host $http_host;
       #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       #proxy_set_header X-Real-Ip $remote_addr;
       #proxy_set_header X-NginX-Proxy true;
       #proxy_pass http://localhost:8081;
       #proxy_redirect off;
    #}
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

注意:服务器安全组要开启80/443端口

  • 配置好以后,重启下服务器
//关闭
nginx -s quit

//开启nginx
nginx

相关文章

网友评论

      本文标题:nginx/1.18.0进行SSL证书配置

      本文链接:https://www.haomeiwen.com/subject/bzqfdktx.html