linux安装nginx + https(tls v1.2)

linux安装nginx + https(tls v1.2)

1.准备工作

1.nginx-1.17.9.tar.gz
2.openssl-1.1.1m.tar.gz

2.安装

  • openssl安装

    1.将openssl-1.1.1m.tar.gz拷贝到linux并解压

    tar -xvf openssl-1.1.1m.tar.gz
    

    2.进入openssl-1.1.1m文件夹编译安装

    cd openssl-1.1.1m
    ./config
    make
    make install
    

    3.查看openssl版本

    openssl version
    
  • nginx安装

    1.将nginx-1.17.9.tar.gz拷贝到linux并解压

    tar -xvf nginx-1.17.9.tar.gz
    

    2.进入nginx-1.17.9文件夹编译安装

    cd nginx-1.17.9
    ./configure --prefix=/opt/nginx --with-http_ssl_module --with-openssl=/root/openssl-1.1.1m --with-http_realip_module
    make && make install
    

    参数说明:

    –prefix=/opt/nginx 指定nginx安装目录

    –with-http_ssl_module 添加nginx的ssl模块

    –with-openssl=/root/openssl-1.1.1m 指定要引用的openssl安装位置

3.配置nginx

  • ssl证书制作 nginx官方地址

    cd /usr/local/nginx/conf
    openssl genrsa -des3 -out server.key 1024
    openssl req -new -key server.key -out server.csr
    cp server.key server.key.org
    openssl rsa -in server.key.org -out server.key
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    

    命令解读:

    openssl req -``new` `-key server.key -out server.csr
    输出内容为:
    Enter pass phrase ``for` `root.key: ← 输入前面创建的密码
    Country Name (``2` `letter code) [AU]:CN ← 国家代号,中国输入CN
    State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音
    Locality Name (eg, city) []:BeiJing ← 市的全名,拼音
    Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
    Organizational Unit Name (eg, section) []: ← 可以不输入
    Common Name (eg, YOUR name) []: ← 输入域名,如:iot.conet.com
    Email Address []:admin``@mycompany``.com ← 电子邮箱,可随意填
    Please enter the following ‘extra’ attributes
    to be sent with your certificate request
    A challenge password []: ← 可以不输入
    An optional company name []: ← 可以不输入
    
  • nginx.conf修改

    server {
          
          
    	#1.15之下使用
        #listen       443;
    	#ssl on;
    	#1.15之后使用
    	listen 443 ssl;
        server_name  localhost;
        ssl_certificate /opt/nginx/conf/server.crt;
        ssl_certificate_key /opt/nginx/conf/server.key;
    	#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    	ssl_protocols TLSv1.2;
    }
    
    
  • nginx重启

    cd ../nginx
    ./nginx -s reload
    
    
  • 浏览器验证

    #访问项目地址,开发者模式中可看到:
    The connection to this site is encrypted and authenticated using TLS 1.2, ECDHE_RSA with X25519, and AES_128_GCM.
    
    

猜你喜欢

转载自blog.csdn.net/succeedcow/article/details/122439899