11

I am using Apache 2.2 on 12.04. I have activated ssl connection with a self-signed certificate which works fine, but now I'd like to disable any non-ssl connection.

I used a2dissite default but the server is still accessible on port 80 even after restarting the server.

Please help me on this.

2 Answers 2

14

I finally have it working:

In addition to disabling the default page with: a2dissite default, I edited /etc/apache2/ports.conf and commented the following lines:

NameVirtualHost *:80  
Listen 80
1
  • I had a snap application listening on port 80. This solution stopped apache from listening on port 80 so that requests could go through to the app.
    – Edwin Chua
    Jan 21, 2021 at 13:47
12

A better idea is to keep "non-ssl connection" (http), but permanently redirected to your SSL Virtual Host (https). In this case the .conf file could look like:

<VirtualHost *:80>

        ServerName www.example.com
        ServerAdmin [email protected]

        # Redirect Requests to SSL
        Redirect permanent "/" "https://www.example.com/"
            
        ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
        CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined

</VirtualHost>


<IfModule mod_ssl.c>

        <VirtualHost _default_:443>
                
                ServerName www.example.com
                ServerAdmin [email protected]

                DocumentRoot /var/www/html/www.example.com

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

                SSLEngine on

                # other configuration directives...
        
        </VirtualHost>

</IfModule>

Related topics:

2
  • May you elaborate why is a better idea to not disable HTTP? I'm investigating pros and cons of disabling port 80. Apr 11, 2018 at 7:39
  • 5
    @MarcoMarsala, in most cases, when HTTP (port 80) is disabled and you are type in the browser http://your.domain.com (or just your.domain.com) you will receive "page not found" - unless you type https://your.domain.com ...
    – pa4080
    Apr 11, 2018 at 7:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .