Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Hi I'm having major problems with a server, SSL works perfectly when connecting with https://..., I need to set up redirection from http to https.

This is my ssl.conf, CentOS-6, with one IP address. SSL cert set up with SANs. Would rather not use .htaccess.

Listen 172.21.11.48:443

NameVirtualHost 172.21.11.48:443

LoadModule ssl_module   modules/mod_ssl.so
SSLEngine on
SSLSessionCache         shmcb:/var/cache/httpd/mod_ssl/ssl_scache(512000)

<VirtualHost 172.21.11.48:443>
SSLEngine on
ServerAlias      "webmail.example.com"
DocumentRoot    "/var/www/html/roundcubemail"
SSLCertificateFile /etc/pki/tls/certs/aether.example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/aether.example.com-2048.key
SSLCACertificateFile /etc/pki/tls/certs/exampleca.crt
</VirtualHost>

<VirtualHost 172.21.11.48:443>
SSLEngine on
ServerAlias      "cloud.example.com"
DocumentRoot    "/var/www/html/owncloud"
SSLCertificateFile /etc/pki/tls/certs/aether.example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/aether.example.com-2048.key
SSLCACertificateFile /etc/pki/tls/certs/exampleca.crt
</VirtualHost>

When connecting on http://webmail.example.com it errors with:

Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port

When I add another vhost on port 80, Apache fails to start. Any help would be gratefully received.

share|improve this question
    
Did you search for how to do this? At all? Even a little bitty redirect non-SSL to SSL in apache on Google? –  voretaq7 Sep 25 '13 at 21:35
add comment

1 Answer

up vote 0 down vote accepted

You just need to edit your httpd.conf file or the file where your virtual host is specified and add these lines to redirect http to https:

  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
share|improve this answer
    
Hi Abhishek, thankyou for replying - where in httpd.conf should it go? Do I have to create another Vhost. My vhosts are in ssl.conf - can your lines of code just go in there? –  Steve Sep 25 '13 at 19:16
    
Hi Abhishek you are as star, thankyou so much for the tip - all working fine now. –  Steve Sep 26 '13 at 9:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.