How To Redirect in Nginx all Domain Name Versions to https://www

| Servers & Config | 25 seen

As you might already know search engines (Google) sees www.domain.com and domain.com as two separate domain names. If you are not using 301 redirects (www to non-www or vice verse)you might get penalized for duplicate content. 

In Ngnix, there is a simple solution how to make such redirect happen, see: Ngnix Redirect To WWW

Now, things get a bit complicated when https versions are involved. See: Linode: How To Secure Nginx with Let's Encrypt on Ubuntu 12.04

Once your website has https enabled, technically speaking you might be dealing with for different domain names:

  1. domain.com
  2. www.domain.com
  3. https://domain.com
  4. https://www.domain.com

What we are looking is to redirect all versions to one, I prefer the version with https://www, here is how to achieve that with Nginx server blocks.

Assuming you have already configured server blocks pointing your domain name to https://www open your server config:

sudo nano /opt/etc/nginx/sites-available/reinisfischer.com

And at the end of the code add:

server{
  listen 80;
  server_name www.reinisfischer.com reinisfischer.com;
  return 301 https://$server_name$request_uri;
}
server{
  listen 443;
  server_name reinisfischer.com;
  return 301 https://www.$server_name$request_uri;
}

Now, restart Nginx

sudo /etc/init.d/nginx restart

Hope it helps!

 

Latest articles

Embedded thumbnail for Spring in Georgia: Morel Hunting, Gori Food Stop & Stunning Gorijvari Views

Spring in Georgia: Morel Hunting, Gori Food Stop & Stunning Gorijvari Views

Shot at the end of April 2026, on a calm and lovely Sunday morning, this video started with a simple plan: go out and hunt for morels -  murķeļi. Spring, fresh air, perfect timing… everything looked right.But plans shifted quickly.After the first attempts turned up nothing, we didn’t push too hard — instead, we adapted. Rather than chasing…

Living in Georgia |

LEGOLAND Berlin Review: A Fun Family Activity in the German Capital

When planning a family trip to Berlin with children, most travelers immediately think about the Berlin Zoo — and rightly so. But if you are spending a few days in the German capital with younger kids, another solid half-day activity is the LEGOLAND Discovery Centre BerlinWe visited it in April 2026 together with our 7-year-old daughter during our…

Germany |