I have no valid SSL certificate for my "example.com".

I can't issue/renew a certificate for "example.com" at the moment.

However, I have a valid one for "www.example.com"

I want all the requests, including https ones, to "example.com" to be redirected to "www.example.com"

I've set up everything in nginx but when I go to "example.com", I see "invalid certificate" and don't get redirected to the https: //www....

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

  server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name localhost example.com;
    return 301 https://www.example.com$request_uri;

  server {
      listen 443 ssl default_server;
      listen [::]:443 ssl default_server;

      server_name www.example.com;

      ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;

      # .................

Is there a way to fix that?

That is, redirect everything to https://www.example.com without a certificate error at https://example.com .

  • 1
    Do not use existing domains you don't own as examples. example.com is specifically reserved for this purpose. – Sven Jun 23 '18 at 18:11

This is not possible. If you don't have a valid cert for example.com, you can't connect to it without an error message, including redirects to a site with a valid cert. If this would be possible, this would subvert a large portion of the security TLS provides.

What stops you from getting a free Let's Encrypt cert? 10 minutes, and the problem is fixed.

  • dns redirect to "www" or anything like that? – Jimku Jun 23 '18 at 16:07
  • 2
    There is no such thing as a DNS redirect. – Sven Jun 23 '18 at 16:08
  • What stops you from getting a free Let's Encrypt cert? ---> 'too many requests, wait for 1 week" – Jimku Jun 23 '18 at 16:17
  • To prevent the "too many requests", Let's Encrypt has a staging endpoint to test and verify before requesting a real certificate. – John Hanley Jul 14 '18 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.