Created
February 3, 2020 12:29
-
-
Save daorte/50bc9da6d28c812b87a3e5c42dd1c936 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Required | |
domain=$(uname -n) | |
echo "Generating SSL for $domain" | |
commonname=$domain | |
country=IN | |
state=KA | |
locality=BANGALORE | |
organization=Intuit | |
organizationalunit=EBS-RARE | |
[email protected] | |
#Optional | |
password=dummypassword | |
echo "Generating key request for $domain" | |
mkdir -p /etc/ssl/private | |
chmod 700 /etc/ssl/private | |
cd /etc/ssl/private | |
#Generate a key | |
openssl genrsa -des3 -passout pass:$password -out $domain.key 2048 -noout | |
#Remove passphrase from the key. Comment the line out to keep the passphrase | |
echo "Removing passphrase from key" | |
openssl rsa -in $domain.key -passin pass:$password -out $domain.key | |
#Create the request | |
echo "Creating CSR" | |
openssl req -new -key $domain.key -out $domain.csr -passin pass:$password \ | |
-subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email" | |
mkdir -p /etc/ssl/certs | |
cd /etc/ssl/certs | |
openssl x509 -req -days 365 -in $domain.csr -signkey $domain.key -out $domain.crt | |
echo "---------------------------" | |
echo "-----Below is your Certificate-----" | |
echo "---------------------------" | |
echo | |
cat $domain.crt | |
echo | |
echo "---------------------------" | |
echo "-----Below is your Key-----" | |
echo "---------------------------" | |
echo | |
cat $domain.key | |
#openssl dhparam -out /etc/ssl/certs/dhparam.pem 2049 | |
mkdir -p /tmp/rpms | |
cd /tmp/rpms | |
wget https://nginx.org/packages/rhel/7/x86_64/RPMS/nginx-1.8.0-1.el7.ngx.x86_64.rpm | |
yum -y localinstall nginx-1.8.0-1.el7.ngx.x86_64.rpm | |
cat <<EOF > /etc/nginx/conf.d/ssl.conf | |
server { | |
listen 443 ssl; | |
listen [::]:443 ssl; | |
server_name $domain; | |
ssl_certificate /etc/ssl/certs/$domain.crt; | |
ssl_certificate_key /etc/ssl/private/$domain.key; | |
#ssl_dhparam /etc/ssl/certs/dhparam.pem; | |
######################################################################## | |
# from https://cipherli.st/ # | |
# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html # | |
######################################################################## | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; | |
ssl_ecdh_curve secp384r1; | |
ssl_session_cache shared:SSL:10m; | |
ssl_session_tickets off; | |
ssl_stapling on; | |
ssl_stapling_verify on; | |
resolver 8.8.8.8 8.8.4.4 valid=300s; | |
resolver_timeout 5s; | |
# Disable preloading HSTS for now. You can use the commented out header line that includes | |
# the "preload" directive if you understand the implications. | |
#add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; | |
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains"; | |
add_header X-Frame-Options DENY; | |
add_header X-Content-Type-Options nosniff; | |
################################## | |
# END https://cipherli.st/ BLOCK # | |
################################## | |
root /usr/share/nginx/html; | |
location / { | |
} | |
error_page 404 /404.html; | |
location = /404.html { | |
} | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
} | |
} | |
EOF | |
systemctl start nginx | |
systemctl status nginx | |
systemctl enable nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment