@@ -25,11 +25,71 @@ cd /usr/local/nginx/conf/ssl/${vhostname}
25
25
26
26
cecho "---------------------------------------------------------------" $boldyellow
27
27
cecho "Generating self signed SSL certificate..." $boldgreen
28
- sleep 5
28
+ cecho "CSR file can also be used to be submitted for paid SSL certificates" $boldgreen
29
+ cecho "If using for paid SSL certificates be sure to keep both private key and CSR safe" $boldgreen
30
+ cecho "creating CSR File: ${vhostname}.csr" $boldgreen
31
+ cecho "creating private key: ${vhostname}.key" $boldgreen
32
+ cecho "creating self-signed SSL certificate: ${vhostname}.crt" $boldgreen
33
+ sleep 9
34
+
35
+ if [[ -z "$SELFSIGNEDSSL_O" ]]; then
36
+ SELFSIGNEDSSL_O="$vhostname "
37
+ else
38
+ SELFSIGNEDSSL_O ="$SELFSIGNEDSSL_O "
39
+ fi
40
+
41
+ if [[ -z "$SELFSIGNEDSSL_OU" ]]; then
42
+ SELFSIGNEDSSL_OU="$vhostname "
43
+ else
44
+ SELFSIGNEDSSL_OU ="$SELFSIGNEDSSL_OU "
45
+ fi
29
46
30
- openssl req -new -newkey rsa:2048 -sha256 -nodes -out ${vhostname}.csr -keyout ${vhostname}.key -subj "/C=US /ST =California /L=Los Angeles /O=${vhostname }/CN=${vhostname}"
47
+ openssl req -new -newkey rsa:2048 -sha256 -nodes -out ${vhostname}.csr -keyout ${vhostname}.key -subj "/C=${SELFSIGNEDSSL_C} /ST =${SELFSIGNEDSSL_ST} /L=${SELFSIGNEDSSL_L} /O=${SELFSIGNEDSSL_O}/OU=${SELFSIGNEDSSL_OU }/CN=${vhostname}"
31
48
openssl x509 -req -days 36500 -sha256 -in ${vhostname}.csr -signkey ${vhostname}.key -out ${vhostname}.crt
32
49
50
+ # echo
51
+ # cecho "---------------------------------------------------------------" $boldyellow
52
+ # cecho "Generating backup CSR and private key for HTTP Public Key Pinning..." $boldgreen
53
+ # cecho "creating CSR File: ${vhostname}-backup.csr" $boldgreen
54
+ # cecho "creating private key: ${vhostname}-backup.key" $boldgreen
55
+ # sleep 5
56
+
57
+ # openssl req -new -newkey rsa:2048 -sha256 -nodes -out ${vhostname}-backup.csr -keyout ${vhostname}-backup.key -subj "/C=${SELFSIGNEDSSL_C}/ST=${SELFSIGNEDSSL_ST}/L=${SELFSIGNEDSSL_L}/O=${SELFSIGNEDSSL_O}/OU=${SELFSIGNEDSSL_OU}/CN=${vhostname}"
58
+
59
+ # echo
60
+ # cecho "---------------------------------------------------------------" $boldyellow
61
+ # cecho "Extracting Base64 encoded information for primary and secondary" $boldgreen
62
+ # cecho "private key's SPKI - Subject Public Key Information" $boldgreen
63
+ # cecho "Primary private key - ${vhostname}.key" $boldgreen
64
+ # cecho "Backup private key - ${vhostname}-backup.key" $boldgreen
65
+ # cecho "For HPKP - HTTP Public Key Pinning hash generation..." $boldgreen
66
+ # sleep 5
67
+
68
+ # echo
69
+ # cecho "extracting SPKI Base64 encoded hash for primary private key = ${vhostname}.key ..." $boldgreen
70
+
71
+ # openssl rsa -in ${vhostname}.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64 | tee -a /usr/local/nginx/conf/ssl/${vhostname}/hpkp-info-primary-pin.txt
72
+
73
+ # echo
74
+ # cecho "extracting SPKI Base64 encoded hash for backup private key = ${vhostname}-backup.key ..." $boldgreen
75
+
76
+ # openssl rsa -in ${vhostname}-backup.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64 | tee -a /usr/local/nginx/conf/ssl/${vhostname}/hpkp-info-secondary-pin.txt
77
+
78
+ # echo
79
+ # cecho "HTTP Public Key Pinning Header for Nginx" $boldgreen
80
+
81
+ # echo
82
+ # cecho "for 7 days max-age including subdomains" $boldgreen
83
+ # echo
84
+ # echo "add_header Public-Key-Pins 'pin-sha256=\"$(cat /usr/local/nginx/conf/ssl/${vhostname}/hpkp-info-primary-pin.txt)\"; pin-sha256=\"$(cat /usr/local/nginx/conf/ssl/${vhostname}/hpkp-info-secondary-pin.txt)\"; max-age=604800; includeSubDomains';"
85
+
86
+ # echo
87
+ # cecho "for 7 days max-age excluding subdomains" $boldgreen
88
+ # echo
89
+ # echo "add_header Public-Key-Pins 'pin-sha256=\"$(cat /usr/local/nginx/conf/ssl/${vhostname}/hpkp-info-primary-pin.txt)\"; pin-sha256=\"$(cat /usr/local/nginx/conf/ssl/${vhostname}/hpkp-info-secondary-pin.txt)\"; max-age=604800';"
90
+
91
+
92
+ echo
33
93
cecho "---------------------------------------------------------------" $boldyellow
34
94
cecho "Generating dhparam.pem file - can take a few minutes..." $boldgreen
35
95
@@ -162,6 +222,16 @@ else
162
222
CHACHACIPHERS=""
163
223
fi
164
224
225
+ if [[ "$(nginx -V 2> &1 | grep -Eo 'with-http_v2_module')" = 'with-http_v2_module' ]]; then
226
+ HTTPTWO=y
227
+ LISTENOPT='ssl http2'
228
+ COMP_HEADER='#spdy_headers_comp 5'
229
+ else
230
+ HTTPTWO=n
231
+ LISTENOPT='ssl spdy'
232
+ COMP_HEADER='spdy_headers_comp 5'
233
+ fi
234
+
165
235
# main non-ssl vhost at yourdomain.com.conf
166
236
cat > "/usr/local/nginx/conf/conf.d/$vhostname.conf"< < ENSS
167
237
# Centmin Mod Getting Started Guide
@@ -239,7 +309,7 @@ cat > "/usr/local/nginx/conf/conf.d/${vhostname}.ssl.conf"<<ESS
239
309
# }
240
310
241
311
server {
242
- listen 443 ssl spdy ;
312
+ listen 443 $LISTENOPT ;
243
313
server_name $vhostname www.$vhostname;
244
314
245
315
ssl_dhparam /usr/local/nginx/conf/ssl/${vhostname}/dhparam.pem;
@@ -254,7 +324,7 @@ server {
254
324
#add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; ";
255
325
#add_header X-Content-Type-Options "nosniff";
256
326
#add_header X-Frame-Options DENY;
257
- spdy_headers_comp 5 ;
327
+ $COMP_HEADER ;
258
328
ssl_buffer_size 1400;
259
329
ssl_session_tickets on;
260
330
@@ -405,6 +475,8 @@ if [[ "$NGINX_VHOSTSSL" = [yY] && "$vhostssl" = [yY] ]]; then
405
475
cecho "Self-signed SSL Certificate: /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}.crt" $boldyellow
406
476
cecho "SSL Private Key: /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}.key" $boldyellow
407
477
cecho "SSL CSR File: /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}.csr" $boldyellow
478
+ # cecho "Backup SSL Private Key: /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}-backup.key" $boldyellow
479
+ # cecho "Backup SSL CSR File: /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}-backup.csr" $boldyellow
408
480
fi
409
481
echo
410
482
cecho "upload files to /home/nginx/domains/$vhostname/public" $boldwhite
435
507
cecho " rm -rf /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}.crt" $boldwhite
436
508
cecho " rm -rf /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}.key" $boldwhite
437
509
cecho " rm -rf /usr/local/nginx/conf/ssl/${vhostname}/${vhostname}.csr" $boldwhite
510
+ cecho " rm -rf /usr/local/nginx/conf/ssl/${vhostname}" $boldwhite
438
511
cecho " rm -rf /home/nginx/domains/$vhostname" $boldwhite
439
512
cecho " service nginx restart" $boldwhite
440
513
cecho "-------------------------------------------------------------" $boldyellow
0 commit comments