Overview
Each traditional SSL certificate is issued, and each certificate requires an independent IP address. If you enable tls sni (server name identification) support when compiling OpenSSL and nginx, you can install multiple SSL certificates, bind different domain names to share the same IP address.
Nginx supports SNI extension of the TLS Protocol (server name indication, simply put, this extension allows different domains of Serv with different certificates on the same IP address)
Earlier, the only way was to sign a wildcard certificate, that is, a certificate like * .delphij.net in the cname, that is, the certificate is bound in the form of a wildcard domain name.
However, a certificate that is not a wildcard domain name cannot bind multiple certificates to one IP address. The tls sni technology mentioned below can bind multiple certificates to one IP address.
Purpose
Use the same IP address with https://ssl.15099.net and https://selfssl.15099.net to configure https, test environment: US VPs + centos
Compiling OpenSSL supports TLS SNI
CD/usr/src/
Wget http://www.openssl.org/source/openssl-0.9.8l.tar.gz
Tar zxvf./openssl-0.9.8l.tar.gz
CD./openssl-0.9.8l
./Config enable-tlsext
Make
Make install
CD ..
Compiling nginx supports TLS SNI
CD/usr/src/
Wget http://nginx.org/download/nginx-0.7.67.tar.gz
Tar zxvf nginx-0.7.67.tar.gz
CD nginx-0.7.67
./Configure \
-- Prefix =/usr \
-- Sbin-Path =/usr/sbin/nginx \
-- Conf-Path =/etc/nginx. conf \
-- Error-log-Path =/var/log/nginx/error. log \
-- Http-log-Path =/var/log/nginx/access. log \
-- PID-Path =/var/run/nginx. PID \
-- Lock-Path =/var/lock/nginx. Lock \
-- User = Nobody \
-- Group = Nobody \
With-http_stub_status_module \
With-http_ssl_module \
With-http_flv_module \
With-http_gzip_static_module \
-- Http-client-body-temp-Path =/var/tmp/nginx/client_temp /\
-- Http-proxy-temp-Path =/var/tmp/nginx/proxy_temp /\
-- Http-FastCGI-temp-Path =/var/tmp/nginx/fcgi_temp /\
-- With-OpenSSL = ../openssl-0.9.8l/
Make
Make install
Check whether nginx supports tls sni.
[Root @ WWW ~] # Nginx-V
Nginx version: nginx/0.7.67
Built by GCC 4.1.2 20080704 (Red Hat 4.1.2-48)
Tls sni support enabled
Configure arguments: -- prefix =/usr -- sbin-Path =/usr/sbin/nginx -- conf-Path =/etc/nginx. conf -- error-log-Path =/var/log/nginx/error. log -- http-log-Path =/var/log/nginx/access. log -- PID-Path =/var/run/nginx. PID -- lock-Path =/var/lock/nginx. lock -- user = nobody
-- Group = nobody -- with-http_stub_status_module -- with-http_ssl_module -- with-http_flv_module -- with-http_gzip_static_module -- http-client-body-temp-Path =/var/tmp/nginx/client_temp/-- http-proxy-temp-Path =/var/tmp/nginx/proxy_temp/-- http-FastCGI-temp-Path =/var/tmp/nginx/fcgi_temp/
-- With-OpenSSL = ../openssl-0.9.8l/
[Root @ WWW ~] #
Generate self-issued certificate
Ssl.15099.net certificate issued
Four steps are required to generate a certificate:
Ssl.15099.net. CRT self-Signed CA certificate
Ssl.15099.net. CSR Certificate Signature request file
Ssl.15099.net. Key Private Key File
Ssl.15099.net _ nopass. Key Private Key File Without Password
CD/etc/nginx/
1. OpenSSL genrsa-des3-out ssl.15099.net. Key 1024.
2. OpenSSL req-New-key ssl.15099.net. Key-out ssl.15099.net. CSR
3. OpenSSL RSA-In ssl.15099.net. Key-out ssl.15099.net _ nopass. Key
4. OpenSSL X509-req-days 365-In ssl.15099.net. CSR-signkey ssl.15099.net. Key-out ssl.15099.net. CRT
Generate
Mkdir-P/usr/share/nginx/15099.net/ssl.15099.net
Echo "selfssl Test 1">/usr/share/nginx/15099.net/ssl.15099.net/index.html
The detailed output of the preceding command is as follows:
[Root @ WWW nginx] # cd/etc/nginx/
[Root @ WWW nginx] # OpenSSL genrsa-des3-out ssl.15099.net. Key 1024 # create a private key file
Generating RSA private key, 1024 bit long Modulus
....................................... ++
...
E is 65537 (0x10001)
Enter pass phrase for ssl.15099.net. Key: # enter the password
Verifying-enter pass phrase for ssl.15099.net. Key: # repeat the password
[Root @ WWW nginx] # OpenSSL req-New-key ssl.15099.net. Key-out ssl.15099.net. CSR # create a Certificate Signature request file
Enter pass phrase for ssl.15099.net. Key: # enter the password you just set
You are about to be asked to enter information that will be ininitialized
Into your certificate request.
What you are about to enter is what is called a distinguished name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country name (2 letter code) [GB]: CN # country
State or province name (full name) [Berkshire]: Guangdong # Province
Locality name (eg, city) [Newbury]: Guangzhou # City
Organization Name (eg, company) [My Company Ltd]: 15099.nat # Name of the organization or organization
Organizational unit name (eg, section) []: 15099.net # Department
Common name (eg, your name or your server's hostname) []: ssl.15099.net # domain name, you need to bind the SSL Domain Name
Email Address []: admin@youdomain.com # mailbox, how to apply for authentication certificate, This mailbox is very important. I am writing an error here to prevent spam
Please enter the following 'extra 'attributes
To be sent with your certificate request
A challenge password []: # Press ENTER
An optional company name []: # Press ENTER
[Root @ WWW nginx] # OpenSSL RSA-In ssl.15099.net. Key-out ssl.15099.net _ nopass. Key # generate a private key file without a password
Enter pass phrase for ssl.15099.net. Key: # enter the password you just set
Writing RSA key
[Root @ WWW nginx] # OpenSSL X509-req-days 365-In ssl.15099.net. CSR-signkey ssl.15099.net. Key-out ssl.15099.net. CRT # generate self-Signed CA certificate
Signature OK
Subject =/C = Cn/ST = Guangdong/L = guangzhou/o = 15099.nat/ ou = 15099.net/ Cn = ssl.15099.net/emailaddress=admin@15099.net
Getting Private Key
Enter pass phrase for ssl.15099.net. Key:
[Root @ WWW nginx] #
Related remarks:
When you generate a CSR, the common name must be filled in. The common name is your host name + domain name, for example: ssl.15099.net us VPs server certificate is issued to a host, not a domain. Your common name must be the same as the full name of the host where you want to use the server certificate, because www.domain.com and domain.com are different.
Selfssl.15099.net certificate issued
CD/etc/nginx/
OpenSSL genrsa-des3-out selfssl.15099.net. Key 1024
OpenSSL req-New-key selfssl.15099.net. Key-out selfssl.15099.net. CSR
OpenSSL RSA-In selfssl.15099.net. Key-out selfssl.15099.net _ nopass. Key
OpenSSL X509-req-days 365-In selfssl.15099.net. CSR-signkey selfssl.15099.net. Key-out selfssl.15099.net. CRT
Mkdir-P/usr/share/nginx/15099.net/selfssl.15099.net
Echo "selfssl Test 2">/usr/share/nginx/15099.net/selfssl.15099.net/index.html
Add nginx Virtual Host Configuration File
VI/etc/nginx/CONF. d/15099.net. conf
The content is as follows:
Server {
SERVER_NAME ssl.15099.net;
Listen 443;
Index index.html index.htm index. php;
Root/usr/share/nginx/15099.net/ssl.15099.net;
SSL on;
Ssl_certificate ssl.15099.net. CRT ;(
Ssl_certificate_key ssl.15099.net _ nopass. Key;
}
Server {
SERVER_NAME selfssl.15099.net;
Listen 443;
Index index.html index.htm index. php;
Root/usr/share/nginx/15099.net/selfssl.15099.net;
SSL on;
Ssl_certificate selfssl.15099.net. CRT;
Ssl_certificate_key selfssl.15099.net _ nopass. Key;
}
Restart nginx and you can access it using https://ssl.15099.net and https://selfssl.15099.net.
Http://www.15099.net/search/label/nginx Source