Configuring SSL in Apache 2.4 under Ubuntu 14.04

Time:2019-10-21

Because of business requirements, SSL encryption needs to be configured for domain names. After obtaining. Cert and. Key files from it department, configuration starts.

1. Find the SSL module of Apache

Under Ubuntu, the default module directory of Apache is/usr/lib/apache2/modules/

$ cd /usr/lib/apache2/modules/
$ ls

After confirming that there is a “mod_ssl. So” module, we go to the Apache configuration directory. The default is/etc/apache2

$ cd /etc/apache2
$ ls

findapache2.conf

2. Increase the dependency of mod_ssl.so

$ vim apache2.conf

Add in the last line

LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

Save, exit

3. HTTP access configuration

opensites-enabled/000-default.conf

$ vim sites-enabled/000-default.conf

The amendment is as follows:

<VirtualHost *:80>
    Servername: safe.example.com (domain name to be bound)
    Options FollowSymLinks
    #Automatically redirect port 80 access to HTTPS domain name
    Redirect permanent / https://safe.example.com
    
    #You can also use if-else conditional selection to disable IP access:
    # <If "%{HTTP_HOST} == 'safe.example.com'">
    #     Redirect permanent / https://safe.example.com/
    # </If>
    # <Else>
    #     Order allow,deny
    #     Deny from all
    # </Else>
    #For details, see: https://httpd.apache.org/docs/2.4/expr.html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

4. HTTPS access configuration

Open ports.conf

$ vim ports.conf

Original content:

Listen 80

<IfModule ssl_module>
        Listen 443
</IfModule>

The amendment is as follows:

<IfModule ssl_module>
        Listen 443
        <VirtualHost _default_:443>
            #Site root here
            DocumentRoot /var/www/html

            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined

            SSLEngine On
            #Path to the certificate file (you need to apply for it yourself or ask for it colleagues)
            SSLCertificateFile "./SSL_Cert/safe.example.com.cert"
            #Path of key file (you need to apply for it by yourself or ask for it colleagues)
            SSLCertificateKeyFile "./SSL_Cert/safe.example.com.key"
        </VirtualHost>
</IfModule>

5. Enable service

$apachectl configtest ා check whether the Apache configuration is correct
$sudo service apache2 reload - after checking that the configuration is correct, reload the configuration
$sudo a2enmod SSL enable SSL service
$sudo service apache2 restart

Disable SSL service yes

$ sudo a2dismod ssl

6. finish

If configured correctly, access:

  1. http://safe.example.com
  2. https://safe.example.com
  3. safe.example.com

Will be redirected to https://safe.example.com

7. References

  1. Expressions in Apache HTTP Server – Apache HTTP Server Version 2.4
  2. Access Control – Apache HTTP Server Version 2.4
  3. Apache forbids IP direct access, only domain name access
  4. Apache configures HTTPS access

Recommended Today

Single and multiple buttons are styled with pictures

I’ve always seen people asking how to style and enlarge the buttons of radio buttons and multi buttons? Let’s share an example I did. 1. First make the button into a picture  2.html page Copy code The code is as follows: <!DOCTYPE HTML> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <script type=”text/javascript” src=”jquery-1.10.2.min.js”></script> <script type=”text/javascript”> […]