LetsEncrypt HTTPS autoredirect not working

Having issues with your DietPi installation or found a bug? Post it here.
Post Reply
wangcow
Posts: 3
Joined: Sun May 02, 2021 12:20 am

LetsEncrypt HTTPS autoredirect not working

Post by wangcow »

I've been searching far and wide and can't seem to find the solution. When I used the xxxx.ddns.net url, all requests were automatically redirected to https without issue. Now I made a new cert with my new domain xxxx.com and all requests are being sent to http://xxxx.com. https://xxxx.com work as well. I use a LAMP stack with nextcloud running on that (xxxx.com/nextcloud) and I have a regular website I use to play around w/ css/php stuff (xxxx.com).

Any ideas why this started when changing url's? Thank you!
User avatar
Joulinar
Posts: 4536
Joined: Sat Nov 16, 2019 12:49 am

Re: LetsEncrypt HTTPS autoredirect not working

Post by Joulinar »

Hi,

Did you activate the HTTPS redirect in dietpi-letsencrypt while creating the certificate?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
wangcow
Posts: 3
Joined: Sun May 02, 2021 12:20 am

Re: LetsEncrypt HTTPS autoredirect not working

Post by wangcow »

Yup that option was checked
User avatar
MichaIng
Site Admin
Posts: 2924
Joined: Sat Nov 18, 2017 6:21 pm

Re: LetsEncrypt HTTPS autoredirect not working

Post by MichaIng »

Can you post the content of the port 80 vhost (which should contain the redirect/rewrite to HTTPS):

Code: Select all

cat /etc/apache2/sites-available/000-default.conf
Remove any identifying strings, like hostnames, if present.
wangcow
Posts: 3
Joined: Sun May 02, 2021 12:20 am

Re: LetsEncrypt HTTPS autoredirect not working

Post by wangcow »

It's working now. My 443 and 80 sections are flipped so I had a user error. This is what's working if anybody stumbles across the problem.

Code: Select all

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName xxxx.com
        DocumentRoot /var/www
        ErrorLog ${APACHE_LOG_DIR}/error.log
        #CustomLog ${APACHE_LOG_DIR}/access.log combined

Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias xxxx.com
SSLCertificateFile /etc/letsencrypt/live/xxxx.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxxx.com/privkey.pem

RewriteEngine on
RewriteCond "%{HTTP_HOST}%{REQUEST_URI}" "^xxxx\.com\/?$"
RewriteRule .* https://xxxx.com
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>

<VirtualHost *:80>
ServerName xxxx.com
        DocumentRoot /var/www
        ErrorLog ${APACHE_LOG_DIR}/error.log
        #CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
</IfModule>
User avatar
MichaIng
Site Admin
Posts: 2924
Joined: Sat Nov 18, 2017 6:21 pm

Re: LetsEncrypt HTTPS autoredirect not working

Post by MichaIng »

Okay great. Aren't 80 and 443 vhosts in different config files by default, 000-default.conf and 000-default-le-ssl.conf :)?
Post Reply