How to Config SSL on Aapche2 of Ubuntu
#install openssl
sudo apt-get install openssl
#create key
openssl genrsa -des3 -out server.key 2048
openssl req -new -days 365 -key server.key -out server.csr
cp server.key server.key.org openssl rsa -in server.key.org -out server.key
#activate ssl
sudo a2enmod ssl
sudo service apache2 restart
#locate keys
sudo mkdir /etc/apache2/ssl
/etc/apache2/ssl/server.crt
/etc/apache2/ssl/server.csr
/etc/apache2/ssl/server.key
#set permissions
sudo chown -R root:root /etc/apache2/ssl
sudo chmod 600 /etc/apache2/ssl/*.*
sudo chmod 700 /etc/apache2/ssl
#config your site with key location
sudo cp /etc/apache2/sites-available/default-ssl /etc/apache2/sites-available/example.com
sudo vi /etc/apache2/sites-available/example.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
sudo a2ensite example.com
sudo service apache2 restart
#redirection http to httpsNameVirtualHost *:80, add below at the end of the example.com file
ServerName example.com
DocumentRoot /var/www/html
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(/(.*))?$ https://%{SERVER_NAME}/%$1 [R,L]
# Or Redirect permanent ^/$ https://example.com/
SSLEngine on
SSLCertificateFile /etc/httpd/conf/server.crt
SSLCertificateKeyFile /etc/httpd/conf/server.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog logs/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
DocumentRoot /var/www/html
Comments
Post a Comment