Last active
June 28, 2025 04:41
-
-
Save antoniocesar16/98814941d4123e3400ef313215772c5d to your computer and use it in GitHub Desktop.
Código de ajuda para resolver o "Acesso permitido apenas por https"
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 | |
| # Criado por Antônio César | |
| # Backup the original file | |
| cp /etc/apache2/sites-enabled/000-default.conf /etc/apache2/sites-enabled/000-default.conf.backup | |
| # Create SSL certificate | |
| sudo openssl req -x509 -nodes -days 300 -newkey rsa:2048 -keyout /etc/ssl/private/apache_ssl.key -out /etc/ssl/certs/apache_ssl.crt -subj "/C=BR/ST=Estado/L=Cidade/O=Empresa/CN=$(hostname -I | awk '{print $1}')" | |
| # Replace the SSL certificate path in the config file | |
| sed -i 's|SSLCertificateFile /etc/apache2/apache.pem|SSLCertificateFile /etc/ssl/certs/apache_ssl.crt|' /etc/apache2/sites-enabled/000-default.conf | |
| # Add SSL certificate key line after the certificate file line | |
| sed -i '/SSLCertificateFile \/etc\/ssl\/certs\/apache_ssl.crt/a\ SSLCertificateKeyFile /etc/ssl/private/apache_ssl.key' /etc/apache2/sites-enabled/000-default.conf | |
| # Enable SSL module | |
| sudo a2enmod socache_shmcb | |
| sudo a2enmod ssl | |
| # Restart Apache | |
| sudo systemctl restart apache2 | |
| # try with service | |
| sudo service apache2 restart | |
| # status do Apache | |
| sudo systemctl status apache2 | |
| # status do Apache service | |
| sudo service apache2 status | |
| echo "Backup created, SSL certificate created and configured for port 443, Apache restarted" | |
| echo "Access via: https://$(hostname -I | awk '{print $1}'):443" | |
| sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ | |
| -keyout /etc/ssl/private/apache_ssl.key \ | |
| -out /etc/ssl/certs/apache_ssl.crt \ | |
| -subj "/C=BR/ST=Estado/L=Cidade/O=Empresa/CN=128.201.77.95" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment