Non-www to https www redirection

Thanks for this great app! I have question about redirection:

Do we have the setting to redirect all non-www domain to secured https www? I tried to create non-www domain and redirects, but it didn’t work.

Hi @fin -

The redirects is more from 1 page to another sort of thing and isn’t really meant for redirecting traffic from non-www to www.

We actually have sites setup to operate in the reverse (move from www to non-www). Though, can I ask why you prefer this way over the other? If it makes sense, maybe we’ll consider adding the ability to move from non-www to www.

Hi @amiedema

Thanks for your reply.

I originally set up the site with the domain www.mydomain.com and apply the ssl. All worked so far.

However, when I tried to visit mydomain.com (without www), the page is generating non secured ssl error, plus this error message in the page:

File does not exist, or is not accessible: /usr/share/netdata/web//index.html

Ah! I see.

Probably the quickest way would be to reset up the site without ‘www’ and apply SSL, and then re-deploy.

It is possible to manually change around the logic to redirect to www. But, I’m not sure if the trouble is worth it.

@fin - were you able to get your site working?

Hi @amiedema, thanks for asking. Unfortunately, after I reset up the site, I got SSL error. The SSL, for some reason, can’t be generated and just shown Error in the dashboard. I will retry back again later with my other server to play more.

Do you have any suggestion for manual change for that redirection? Some of my domains have been using www for long and redirects the non www to www.

Let’s Encrypt does have some limits - such as, if you try to enable SSL too many times in a short period of time for a domain, it may reach a limit and start to fail. I’m not sure if that’s what happened to you, but is something to be aware of. You can always apply SSL after you create a site.

For the redirect, let me see what might be the best way to do that and I’ll get back to you with more info.

Here is a way to redirect from non-www to www

Step 1 -
Create a new site and use www in the domain; such as www.example.com

Enable SSL for the domain

Step 2 -
SSH into your server, and go to
/etc/nginx/cleaver-conf/www.example.com/header/ and edit redirect.conf file to look like the below (pay close attention to where www is and is not.

# Redirect all http traffic to https

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    return 301 https://www.$host$request_uri;
}

# Redirect www https traffic to primary domain https
server {
    include /etc/nginx/cleaver-conf/www.example.com/server.conf;
    server_name example.com;
    return 301 $scheme://www.example.com$request_uri;
}

That should work to redirect traffic to www while maintaining SSL for www. Let me know if it works or not for you! I’d recommend testing it out with an unused domain first if you can just to make sure it works the way you want it to.

Hell @amiedema You rock! Thanks so much :smiley:
Just need to restart the nginx after I edit that file and it works.

2 Likes

Hi @amiedema It seems like my domain that get SSL error last time still being blocked by your system. I tried to add it without SSL, then after the site is created, I generated the SSL Let’s Encrypt, but I got the red text Error status without further information. Could you please help to unblock that domain? (Sorry, I sent you private message here of my domain name because it’s still not ready for public)