apacheubuntusslredirect-loop

How to Configure Apache 2.2.14 on Ubuntu 10.04 to use SSL only (Redirect loop)


Good morning,

I'm new to managing Apache servers. We have one internal server in particular that we would like to listen ONLY on port 443. There is only one 'site' or singular configuration on this server called 'interweb'. I attempted to make the following change in our sites-available folder as shown below, but it results in a redirect loop:

<VirtualHost *:80>
        RewriteEngine on
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/htdocs (...)  

Any assistance you can offer would be greatly appreciated!


Solution

  • You need to get rid of your first virtual host because this looks like it is your httpd.conf file, not .htaccess, then change * to your server's IP address and finally put

    Listen 443
    

    at the top of the file.

    Finally restart Apache in a terminal:

    sudo /etc/init.d/apache2 restart