The easiest way to make MediaWiki require HTTPS on all pages?

I need a MediaWiki installation to require the use of https (and reject regular http). I spent 2 hours. Installation $wgServerdoes not work, and closing port 80 in httpd.confdoes not work either.

My wiki installation is done on an Apache server.

+5
source share
2 answers

My answer assumes that you already have Apache that listens for https traffic on port 443. If this is not the case, you need to install this first. The procedure will vary depending on the operating system you are running on.


You want to do this in Apache. On my Ubuntu system, there is a file /etc/apache2/ports.confthat contains the following line:

Listen 80

, . Apache.


, Apache, HTTP- , .htaccess MediaWiki. :

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
+5

Ubuntu 14 ( , !),

$wgServer = "//myhostname.com/mediawiki";

" " , HTTP HTTPS. , https://... .

apache2 HTTP- HTTPS:

SSL (, ):

sudo vim /etc/apache2/sites-available/default-ssl.conf

- :

# Redirect HTTP to HTTPS
<VirtualHost *:80>
     ServerAdmin admin@example.com
     ServerName example.com

     Redirect permanent / https://example.com/
</VirtualHost>

# Normal HTTPS config for default site
<VirtualHost *:443>
     SSLEngine On
     SSLCertificateFile /etc/apache2/ssl/apache.pem
     SSLCertificateKeyFile /etc/apache2/ssl/apache.key

     ServerAdmin admin@example.com
     ServerName example.com
     DocumentRoot /var/www/html/
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

SSL , ( , )

sudo a2ensite default-ssl

, SSL ( ), /etc/apache2/ssl/apache.pem /etc/apache2/ssl/apache.key, .

, apache :

sudo service apache2 restart

( reload )

+6

All Articles