nginx (2) ssl 관련 설정

5892 단어 httpsnginx 설정
선언:
안전 이 최 우선 인 오늘날, 전역 https 의 구호 가 나날이 높 아 지고 있다.
**ngx_http_ssl_module 모듈 관련 설정 * *
ssl_certificate file;인증서 경로 지정
ssl_certificate_key file;인증서 에 대응 하 는 비밀 키 파일;
ssl_ciphers ciphers;nginx 가 사용 하 는 암호 화 알고리즘 을 가리 키 며 OpenSSL 라 이브 러 리 에서 지원 하 는 각종 암호 화 세트 일 수 있 습 니 다.
ssl_protocols [SSLv2][SSLv3][TLSv1.1][TLSv1.2];사용 한 SSL 프로 토 콜 버 전 가리 키 기;기본 값 은 세 개 입 니 다.
ssl_session_cahce off|none|[builtin[:size]][shared:name:size];ssl 세 션 캐 시 메커니즘 가리 키 기;
  • builtin: openssl 에 내 장 된 ssl 세 션 캐 시 를 사용 합 니 다.각 worker 개인;
  • shared: 각 worker 사이 에 공 유 된 캐 시 를 사용 합 니 다.

  •        name: 고유 이름;    
          크기: 캐 시 공간 크기      
    ssl_session_timeout time;ssl 세 션 시간 초과;즉, ssl session cache 의 캐 시 유효 시간;
    * * 개인 CA 만 들 기 * *
    [root@node3 ~]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
    Generating RSA private key, 2048 bit long modulus
    ................+++
    ..................................+++
    [root@node3 newcerts]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365
    You are about to be asked to enter information that will be incorporated
    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) [XX]:CN
    State or Province Name (full name) []:beijing
    Locality Name (eg, city) [Default City]:beijing
    Organization Name (eg, company) [Default Company Ltd]:tz.company
    Organizational Unit Name (eg, section) []:ops
    Common Name (eg, your name or your server's hostname) []:tzca.com    
    Email Address []:
    
    [root@node3 CA]# touch {serial,index.txt}
    [root@node3 CA]# echo 01 > serial

    * * nginx 서버 생 성 인증서 요청 * *
    [root@node4 nginx]# mkdir ssl
    [root@node4 nginx]# cd ssl/
    [root@node4 ssl]# (umask 077; openssl genrsa -out nginx.key 1024)
    Generating RSA private key, 1024 bit long modulus
    .................................++++++
    ........................++++++
    e is 65537 (0x10001)
    [root@node4 ssl]# openssl req -new -key nginx.key -out nginx.csr
    You are about to be asked to enter information that will be incorporated
    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) [XX]:CN
    State or Province Name (full name) []:beijing
    Locality Name (eg, city) [Default City]:beijing
    Organization Name (eg, company) [Default Company Ltd]:tz.company
    Organizational Unit Name (eg, section) []:ops
    Common Name (eg, your name or your server's hostname) []:www.tz.com
    Email Address []:[email protected]
    
    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:
    An optional company name []:
    [root@node4 ssl]# scp nginx.csr [email protected]:/tmp
    [email protected]'s password: 
    nginx.csr                                             100%  696     0.7KB/s   00:00

    * * 인증서 서명 요청 * *
    [root@node3 CA]# openssl ca -in /tmp/nginx.csr -out certs/nginx.crt
    Using configuration from /etc/pki/tls/openssl.cnf
    Check that the request matches the signature
    Signature ok
    Certificate Details:
            Serial Number: 1 (0x1)
            Validity
                Not Before: Feb 29 13:11:28 2016 GMT
                Not After : Feb 28 13:11:28 2017 GMT
            Subject:
                countryName               = CN
                stateOrProvinceName       = beijing
                organizationName          = tz.company
                organizationalUnitName    = ops
                commonName                = www.tz.com
                emailAddress              = [email protected]
            X509v3 extensions:
                X509v3 Basic Constraints: 
                    CA:FALSE
                Netscape Comment: 
                    OpenSSL Generated Certificate
                X509v3 Subject Key Identifier: 
                    E5:01:2E:03:DE:39:5E:71:3B:9C:E3:D9:60:00:97:16:95:42:16:EB
                X509v3 Authority Key Identifier: 
                    keyid:12:C5:01:DB:D3:6C:F6:67:3D:3B:60:99:D8:AD:7E:21:90:46:22:62
    
    Certificate is to be certified until Feb 28 13:11:28 2017 GMT (365 days)
    Sign the certificate? [y/n]:y
    
    
    1 out of 1 certificate requests certified, commit? [y/n]y
    Write out database with 1 new entries
    Data Base Updated
    
    [root@node3 certs]# scp nginx.crt [email protected]:/etc/nginx/ssl
    The authenticity of host '172.16.61.4 (172.16.61.4)' can't be established.
    ECDSA key fingerprint is 88:93:ff:8b:6e:ac:a0:c1:10:1f:4b:7d:ac:44:85:f0.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '172.16.61.4' (ECDSA) to the list of known hosts.
    [email protected]'s password: 
    nginx.crt                                                    100% 3774     3.7KB/s   00:0

    * * nginx 를 https 로 설정 * *
    server {
                    listen 443 ssl;
                    listen 172.16.61.4:80;
                    server_name www.tz.com;
                    root /data/www/vhost1;
                    ssl_certificate /etc/nginx/ssl/nginx.crt;
                    ssl_certificate_key /etc/nginx/ssl/nginx.key;
                    ssl_session_cache shared:SSL:1m;
                    ssl_session_timeout 5m;
                    ssl_ciphers HIGH:!aNULL:!MD5;
                    ssl_prefer_server_ciphers on;
    
                    if ($scheme = http) {             #   http      https
                            return 301 https://$server_name$request_uri;
                    }
            }

    주: 생산 환경 에서 자신 이 생 성 한 비밀 키 파일 과 인증서 요청 파일 을 CA 기구 에 복사 하고 CA 기구 에서 인증서 의 서명 을 한 후에 이 인증 서 를 사용 할 수 있 습 니 다.

    좋은 웹페이지 즐겨찾기