简体   繁体   中英

Redirecting http to https in vps

I have a vps set up on the domain "mysite.co.uk" and I also installed an SSL certificate. But it is shown only when using " https://mysite.co.uk ".

How can I set it up so that mysite.co.uk would redirect to the one with "https"?

I tried adding a " Redirect " in the hosting service and I have the following too in my etc/apache2/sites-enabled/mysite.conf :

<VirtualHost *:80>
        ServerAdmin ewewew@gmail.com
        ServerName mysite.co.uk
        ServerAlias www.mysite.co.uk
        Redirect / https://mysite.co.uk
</VirtualHost>

Please try with following steps :

Enable modules

sudo a2enmod rewrite
sudo a2enmod ssl

Edit configurations

Edit file : /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile    <path to your crt file>
    SSLCertificateKeyFile   <path to your private key file>
</VirtualHost>

Restart apache2

sudo service apache2 restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM