Nginx redirects to default site after using certbot

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g., so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is:

I ran this command:
sudo certbot --nginx -d

My web server is (include version):
nginx version: nginx/1.14.0 (Ubuntu)

The operating system my web server runs on is (include version):
Ubuntu 18.04.3 LTS

I can login to a root shell on my machine (yes or no, or I don’t know):

I’m using a control panel to manage my site (no, or provide the name and version of the control panel):

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot):
certbot 0.31.0

Hello, I wanted to move a WordPress site to a different domain, I set the new domian in WordPress and have verified that the domain is set correctly in the WordPress settings, then I added the new domain in my nginx conf file for the site and ran certbot on the new domain, but now whenver I try to access the new domain nginx just redirects me to the default site instead of the actual site I want to open. I’ve attached my nginx conf file, I’ve tried to make many, many changes to it to fix this problem so it may contain some weird things.

I tried writing the part from line 56-61 myself again and manually set the correct HTTPS certs, but this did not fix the problem.

output from ls of myt /etc/letsencrypt/live/oslopeace19 folder
cert.pem chain.pem fullchain.pem privkey.pem README

the letsencrypt folder contains three certificates for this site, one for the development domain, and two that have come from my trying to run certbot

# ls|  grep oslopeace

Any ideas on what could be causing this issue?

edit: results from curl says the site is moved permanently

301 Moved Permanently

301 Moved Permanently

nginx/1.14.0 (Ubuntu)


I see that you have correctly setup your Nginx plain http host, but your HTTPS host does not contain a server directive.
Please try to add your domain / host on that config and reload Nginx.

Thank you

by server directive do you mean ‘server_name’? I thought I could only have one of those per file, when I tried to add another nginx complained when I ran “sudo nginx -t”

Could you be a more specific on where I should add the second " server_name;" line?

You could only have one server_name directive per virtual host.
(The one that starts with server{ and ends with })

So since you have two servers in the config file, you should be able to add server_name in the first virtual host config.

See the below Pastebin for your reference:

The only difference is that the first server directive does not have a server name, which is why it doesn’t work. (Since Nginx can’t find the website you are trying to visit)

Thank you

Thank you for your clearifaction and example config file, but I still have the same issue. When running your exact config file Nginx gives out the following warnings when running “sudo nginx -t”

nginx: [warn] conflicting server name "" on [::]:443, ignored
nginx: [warn] conflicting server name "" on, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Using curl I still get the same “301 moved permanently” error


Two more points:

  1. The 301 error is not an error, it’s a redirection that should redirect you to the “secure” https version of the site. You could use curl -L to follow redirects.
  2. The warning message stated is that you’ve already specified your https virtual host on another file.

Could you please try to dump your whole Nginx virtual hosts and share it to another text links?
use nginx -T to dump all your running configs…

Thank you

Full dump here


Just update you here.
I’m still sorting the Nginx configuration file you provided… and still need some time.

No problem, I found some duplication error, so please use this file instead

Still have the same issue though, tried to remove HTTPS certs in my latest config.

Not quite sure what I did, but I re-wrote the conf file for the tenth time today. Now the site is working as intended, I don’t like to read forum posts where OP just says “it works now”

But it does, and I have no idea why. Thank you for your help stevenzhu!

Glad it works :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.