Environment preparation
This build environment CS6.6, the kernel 2.6.32,nginx-1.6.3, first confirms Nginx compiles the SSL module, simultaneously installs the OpenSSL and the openssl-devel.
Upgrade OpenSSL
#openssl 1.0.1-1.0.1f is affected by a bleeding hole in the heart and needs to be upgraded [[email protected] ~]# OpenSSL Versionopenssl 1.0.1e-fips Ls/wget Http://www.openssl.org/source/openssl-1.0.1g.tar.gztar XF OPENSSL-1.0.1G.TAR.GZCD openssl-1.0.1g./config Shared Zlibmakemake installmv/usr/bin/openssl/usr/bin/openssl.oldmv/usr/include/openssl//usr/include/ Openssl.oldln-s/usr/local/ssl/bin/openssl/usr/bin/openssln-s/usr/local/ssl/include/openssl//usr/include/ openssl# Update dynamic link library data echo "/usr/local/ssl/lib/" >>/etc/ld.so.confldconfig-v[[email protected] openssl-1.0.1g]# OpenSSL VERSIONOPENSSL 1.0.1g 7 APR 2014
Generate private keys and certificates
[[email protected] cert]# OpenSSL genrsa-out cert.key 2048 Generate certificate private key [[email protected] cert]# OpenSSL Req-new-key cert . key-out CERT.CSR Generate certificate request file [[email protected] cert]# OpenSSL x509-req-in cert.csr-out cert.pem-signkey cert.key-d Ays 3650 Issue digital certificate, default format pem# can also be OpenSSL req-new-x509-key cert.key-out cert.pem-days 3650 directly generate self-signed certificate
Edit Nginx configuration file
[[email protected] nginx]# vim conf/nginx.confworker_processes 1;events { Worker_connections 1024;} HTTP {include mime.types; Default_type Application/octet-stream; Sendfile on; Keepalive_timeout 65; server {Listen 80; server_name www.peter.com; Location/{Rewrite ^ (. *) https://$server _name$1 permanent; }} server {listen 443; server_name www.peter.com; root HTML; Index index.html index.htm; SSL on; Ssl_certificate Cert.pem; Ssl_certificate_key Cert.key; Ssl_session_timeout 5m; Ssl_protocols SSLv2 SSLv3 TLSv1; Ssl_ciphers high:!anull:! MD5; Ssl_prefer_server_ciphers on; Location/{}}}[[email protected] nginx]# sbin/nginx-t[[email protected] nginx]# sbin/nginx access www.pe Ter.com
About rewrite function rewrite used for URL rewrite, can implement URL jump, pseudo-static and other functional syntax: rewrite regex replacement [flag] case: Rewrite ^/(. *)/HTTP/ Www.peter.com/$1 permanent; Description: Represents everything that matches/starts with the content in the front (), permanent means 301 permanent jump; [flag] marked with: Last match completion continues to match break match finish that terminates match redirect 302 temporary jump Permanent 301 Permanent Jump Rewirte requires pcre software support, matching with Perl-compatible regular Expressions primary note () indicates a backward reference, in which the contents of () can be obtained by $0..$9 later
Nginx Configuration HTTPS