Last active
July 24, 2024 19:10
-
-
Save jeffbrl/2e608d82105bcb1a764e00a49ce7fc3f to your computer and use it in GitHub Desktop.
User-data for Amazon Linux 2 or 2023 Apache with Self-Signed Cert
This file contains 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 -xe | |
# Use with Amazon Linux 2 | |
# Amazon Linux 2023 doesn't seem to have make-dummy-cert script | |
yum update -y | |
yum install -y httpd mod_ssl | |
systemctl start httpd | |
systemctl enable httpd | |
usermod -a -G apache ec2-user | |
chown -R ec2-user:apache /var/www | |
chmod 2775 /var/www | |
find /var/www -type d -exec chmod 2775 {} \; | |
find /var/www -type f -exec chmod 0664 {} \; | |
echo `hostname` > /var/www/html/index.html | |
echo '<br><br>' >> /var/www/html/index.html | |
# create ~ 12K of random text | |
base64 /dev/urandom | head -c 1000 >> /var/www/html/index.html | |
cd /etc/pki/tls/certs | |
# AL2 use next two lines | |
#./make-dummy-cert localhost.crt | |
#sed -i 's/^SSLCertificateKeyFile.*$//' /etc/httpd/conf.d/ssl.conf | |
# AL2023 use next line | |
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/apache-selfsigned.key -out /etc/pki/tls/certs/apache-selfsigned.crt | |
systemctl restart httpd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment