Linux installation nginx + https (tls v1.2)
1. Preparations
1.nginx-1.17.9.tar.gz
2.openssl-1.1.1m.tar.gz
2. Install
-
openssl install
1. Copy openssl-1.1.1m.tar.gz to linux and decompress
tar -xvf openssl-1.1.1m.tar.gz
2. Enter the openssl-1.1.1m folder to compile and install
cd openssl-1.1.1m ./config make make install
3. Check the openssl version
openssl version
-
nginx installation
1. Copy nginx-1.17.9.tar.gz to linux and decompress it
tar -xvf nginx-1.17.9.tar.gz
2. Enter the nginx-1.17.9 folder to compile and install
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
Parameter Description:
–prefix=/opt/nginx specifies the nginx installation directory
–with-http_ssl_module Add nginx ssl module
–with-openssl=/root/openssl-1.1.1m specifies the openssl installation location to be referenced
3. Configure nginx
-
ssl certificate production nginx official address
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
Command interpretation:
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 modification
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 restart
cd ../nginx ./nginx -s reload
-
browser verification
#访问项目地址,开发者模式中可看到: The connection to this site is encrypted and authenticated using TLS 1.2, ECDHE_RSA with X25519, and AES_128_GCM.