Skip to content

Instantly share code, notes, and snippets.

@rhysemmas
Last active November 2, 2020 17:24
Show Gist options
  • Save rhysemmas/95d0cd6d352641a5dd0de321339cf5bf to your computer and use it in GitHub Desktop.
Save rhysemmas/95d0cd6d352641a5dd0de321339cf5bf to your computer and use it in GitHub Desktop.
#!/bin/bash
domain=$(uname -n)
echo "Generating SSL for $domain"
commonname=$domain
country=UK
state=EGG
locality=EGG
organization=Urmum
organizationalunit=Urmum-1
email=egg@egg.com
#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 1 -in /etc/ssl/private/$domain.csr -signkey /etc/ssl/private/$domain.key -out $domain.crt
#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