Configuring SSL in Apache 2.4 under Ubuntu 14.04


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


2. Increase the dependency of

$ vim apache2.conf

Add in the last line

LoadModule ssl_module /usr/lib/apache2/modules/

Save, exit

3. HTTP access configuration


$ vim sites-enabled/000-default.conf

The amendment is as follows:

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

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

4. HTTPS access configuration

Open ports.conf

$ vim ports.conf

Original content:

Listen 80

<IfModule ssl_module>
        Listen 443

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/"
            #Path of key file (you need to apply for it by yourself or ask for it colleagues)
            SSLCertificateKeyFile "./SSL_Cert/"

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:


Will be redirected to

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

[tutorial] restful API using JWT authentication in laravel

This article is forwarded from the professional laravel developer community, original link:… In this article, we’ll learn how to use JWT authentication to build restful APIs in larevel. JWT stands for JSON web tokens. We will also use the API to create full-featured crud applications for user products. When using cross platform applications, the […]