How to make the entire Moodle website over https?

How to make the entire Moodle website over https?

by Davi DePaula -
Number of replies: 6

I have successfully installed a certificate and turned on the https loging option. My next step is to make the entire website run over https.

I have changed my config file  $CFG->wwwroot   = 'https://www.mysite.com'; to point to the https but I don't think this is all I need to do.

Do I have to change any configuration on my Apache server?

I run moodle on a LAMP system. 


Thank you for your help.


Average of ratings: -
In reply to Davi DePaula

Re: How to make the entire Moodle website over https?

by Davi DePaula -

I found out that if you add the following lines into the "default" file in apache2 that holds the "VirtualHost *:80" configuration, all http requests get redirected to https.

        ServerName www.sitename.com

        Redirect / https://www.sitename.com/

Now, all of the website seems to be going over ssl. Is this the correct way to do it? 

Also, I'm having a problem now with the Theme. The https redirect seems to have broken the Theme. It looks like the css file or maybe the Java Scripts don't get loaded now. What I'm I missing here? 

BTW, I'm running Moodle 2.4 and using the Anomaly Theme.  

Thank you for your help. 
In reply to Davi DePaula

Re: How to make the entire Moodle website over https?

by john saylor -
there are many ways to do this. probably the easiest is to just not run anything but the SSL site. that is, there is no unencrypted data being served at all. this means changing the apache configuration and requires understanding how that configuration file operates. it's probably better, though, to do a redirect at the webserver level. so that anyone coming in to your site on the plain text port will be redirected to the encrypted one. i think you are using the apache server, so here is some documentation with a few examples: https://httpd.apache.org/docs/2.4/rewrite/remapping.html you may not be running a 2.4 server, but you can probably find the 2.2 documentation which is on the same site. yes, it's somewhat complicated. so you may have to learn something yourself or get some help with it. good luck!
In reply to john saylor

Re: How to make the entire Moodle website over https?

by Davi DePaula -

Thank you john for your help. I ended up using the following rewrite code in the /var/apache2/sites-avaiable/default file and now it is working well. That has also resolved the Theme issue I was having.


<VirtualHost*:80>ServerName www.mysite.comRedirect/ https://www.mysite.com/</VirtualHost><VirtualHost*:80>ServerName www.example.com
</VirtualHost>
Thanks. 
In reply to Davi DePaula

Re: How to make the entire Moodle website over https?

by Davi DePaula -

One more problem that I ran into when making Moodle completely over ssl is that the embedded objects in the website that have a http connection will not display. 

For example, A Youtube embedded video code that looks like this:

<iframe width="640" height="360" src="http://www.youtube.com/embed/9GDX-IyZ_C8?feature=player_detailpage" frameborder="0" allowfullscreen=""></iframe>


will not display because in the page because of the http request. 

But if you change the http directive to https like so:

<iframe width="640" height="360" src="https://www.youtube.com/embed/9GDX-IyZ_C8?feature=player_detailpage" frameborder="0" allowfullscreen=""></iframe>

It works just fine. 

Of course you'll have to make sure if the servers you are pulling the embedded objects from allow a https connection. 

In reply to Davi DePaula

Re: How to make the entire Moodle website over https?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There is one other thing you should do, the "Change your Moodle URL" step from http://docs.moodle.org/27/en/Moodle_migration#Migrating_a_complete_Moodle_site_-_method_1

In reply to Tim Hunt

Re: How to make the entire Moodle website over https?

by Davi DePaula -

Good point. 

Thank you for your help Tim.