xxxxxxxxxx
# Set the text we want to insert into each record
INSERT='\ # Enable HSTS (added manually)\n add_header Strict-Transport-Security "max-age=31536000" always;\n'
# For every site in sites-available without the phrase "HSTS" in it...
for I in `grep -L 'HSTS' /etc/nginx/sites-available/*`; do
echo ""
echo $I
echo "Missing HSTS, checking if it is secured..."
# If this site is SSL-encrypted...
if grep -q 'ssl_certificate /' "$I"; then
echo "***Secured, adding HSTS***"
# Add the HSTS configuration
sed -i "/SAMEORIGIN.*/i$INSERT" $I
fi
done
service nginx reload
echo ""
echo "Reloaded nginx. Script complete!"
echo ""
Design © 2025. ForgeRecipes loves you.
Site maintained by Vince Mitchell.
Inspired by original by David Hemphill, Tanner Hearne, & Matt Stauffer.