zoukankan      html  css  js  c++  java
  • 详细nginx配置SSL

    1.nginx的ssl

    让nginx实现用https来访问网站,http是80端口,https是443端口。

    https其实就是一种加密的http

    2.为什么要加密

    例子:在网上银行汇款,在你汇款的过程当中,你会输入银行卡的密码,如果不加密,这些数据传输的过程中就有可能被人截获,破解。

    如果你使用了https,数据在传输的过程中是会加密的。即使抓到了数据包,但是无法破解出来。

    知识:

    http(1.1版本)  http 2(https)

    3.0 怎么配置ssl?

    首先得看你是yum安装的nginx还是编译安装的nginx

    3.1yum安装nginx已经有参数--with-http_ssl_module

    nginx -V ##查看参数
    

    3.2 编译安装查看是否有--with-http_ssl_module (我选择的是编码编译安装的nginx)

    /usr/local/nginx/sbin/nginx -V
    

    3.3如果没有重新编译。进入nginx解压的目录

    # cd /usr/local/src/nginx-1.17.0/
    

    3.4 重新配置新的编译参数

    # ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    

    3.5 运行上面命令即可,等待配置,运行命令

    # make
    

    注:不用make install安装,不然会覆盖安装

    3.6 停止nginx

    # /etc/init.d/nginx stop
    

    3.7 把刚刚编译好的nginx覆盖原有的nginx

    # cp ./objs/nginx /usr/local/nginx/sbin/
    

    3.8 查看编译的参数是否生效

    # /usr/local/nginx/sbin/nginx -V 
    

      

    4.0 如何获取ssl证书?

    申请证书:

    网站:(沃通)

    免费的:freessl.cn

    这里拿的是免费的证书

    进入freessl.cn首先注册  然后输入域名申请开通,这个过程需要去添加TXT记录来证明网站是你的。

    会给你一个TXT的记录

    然后在你的域名解析中添加

    回到freessl.cn点击验证会给你CA证书,证书,秘钥

    这时候回到linux 创建ssl的目录

    # mkdir /usr/local/nginx/conf/ssl/
    

    进入ssl目录

    vim CA
    添加浏览器生成的CA证书
    

    编辑证书文件

    # vim bbs.crt
    复制粘贴证
    

    编辑私钥文件

    # vim bbs.key
    复制粘贴私钥
    

    配置conf配置文件

    server
        {
            listen 443 ssl;
            index index.html index.htm index.php;
            root /data/wwwroot/bbs.centos.com;
            server_name bbs.centos.com;
            ssl_certificate /usr/local/nginx/conf/ssl/bbs.crt;
            ssl_certificate_key /usr/local/nginx/conf/ssl/bbs.key;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    

    检测语法重载配置

    # /usr/local/nginx/sbin/nginx -t
    # /usr/local/nginx/sbin/nginx -s reload
    

    另外也可以配置成

    server
        {
            listen 443;
            index index.html index.htm index.php;
            root /data/wwwroot/bbs.centos.com;
            server_name bbs.centos.com;
            ssl on;
            ssl_certificate /usr/local/nginx/conf/ssl/bbs.crt;
            ssl_certificate_key /usr/local/nginx/conf/ssl/bbs.key;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    

    重启nginx

    # /etc/init.d/nginx restart
    

    查看监听端口

    # netstat -lntp
    

    5.0 配置好了可以访问但是centos有防火墙还需要开放443端口

    # firewall-cmd --add-port=443/tcp --permanent ##永久放行443端口
    # firewall-cmd -reload #重载
    

    现在访问域名上效果图

  • 相关阅读:
    Spring Boot 自定义属性 以及 乱码问题
    IDEA 修改文件编码
    Gojs简单例子
    无法转换json问题 Error: Model.nodeDataArray value is not an instance of Array or NodeList or HTMLCollection
    java json转换
    git设置HTTP代理
    thymeleaf中的日期格式化
    thymeleaf:字符串Strings常见的使用方法
    thymeleaf+bootstrap,onclick传参实现模态框中遇到的错误
    Thymeleaf教程 (十二) 标签内,js中使用表达式
  • 原文地址:https://www.cnblogs.com/yantou/p/11669881.html
Copyright © 2011-2022 走看看