Certbot nginx plugin could not open file


I have a simple personal website that I want to make HTTPS.

I setup my Nginx server block following this tutorial:

And I followed this tutorial to install Let’s Encrypt on my server block:

Everything worked like a charm, up to Step 4 where the following command:

sudo certbot --nginx -d -d

return this:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Could not open file: /etc/nginx/sites-enabled/
Plugins selected: Authenticator nginx, Installer nginx
Starting new HTTPS connection (1):
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for
tls-sni-01 challenge for
Cleaning up challenges
Could not open file: /etc/nginx/sites-enabled/
Cannot find a VirtualHost matching domain In order for Certbot to correctly perform the challenge please add a corresponding server_name directive to your nginx configuration:

I checked the permissions on my server block file in /etc/nginx/ but it all look good:

├── [drwxr-xr-x]  conf.d
├── [drwxr-xr-x]  sites-available
│   ├── [-rw-r--r--]  default
│   └── [-rw-r--r--]
├── [drwxr-xr-x]  sites-enabled
│   └── [lrwxrwxrwx] -> sites-available/

I tried to access the log on /var/log/letsencrypt, but it wasn’t helpful:

2017-11-29 21:03:32,206:DEBUG:certbot.error_handler:Calling registered functions
2017-11-29 21:03:32,206:INFO:certbot.auth_handler:Cleaning up challenges
2017-11-29 21:03:32,478:WARNING:certbot_nginx.parser:Could not open file: /etc/nginx/sites-enabled/
2017-11-29 21:03:33,529:DEBUG:certbot.log:Exiting abnormally:
Traceback (most recent call last):
  File "/usr/bin/certbot", line 11, in <module>
    load_entry_point('certbot==0.19.0', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/dist-packages/certbot/", line 861, in main
    return config.func(config, plugins)
  File "/usr/lib/python2.7/dist-packages/certbot/", line 698, in run
    certname, lineage)
  File "/usr/lib/python2.7/dist-packages/certbot/", line 85, in _get_and_save_cert
    lineage = le_client.obtain_and_enroll_certificate(domains, certname)
  File "/usr/lib/python2.7/dist-packages/certbot/", line 357, in obtain_and_enroll_certificate
    certr, chain, key, _ = self.obtain_certificate(domains)
  File "/usr/lib/python2.7/dist-packages/certbot/", line 318, in obtain_certificate
  File "/usr/lib/python2.7/dist-packages/certbot/", line 74, in get_authorizations
    resp = self._solve_challenges()
  File "/usr/lib/python2.7/dist-packages/certbot/", line 115, in _solve_challenges
    resp = self.auth.perform(self.achalls)
  File "/usr/lib/python2.7/dist-packages/certbot_nginx/", line 767, in perform
    sni_response = chall_doer.perform()
  File "/usr/lib/python2.7/dist-packages/certbot_nginx/", line 55, in perform
    vhost = self.configurator.choose_vhost(achall.domain)
  File "/usr/lib/python2.7/dist-packages/certbot_nginx/", line 242, in choose_vhost
    "") % (target_name))
MisconfigurationError: Cannot find a VirtualHost matching domain In order for Certbot to correctly perform the challenge please add a corresponding server_name directive to your nginx configuration:

I changed my server block file permissions to 777, but to no effect!

Where can I found a solution to this issue?

Thank you for your help. Yohann Paris

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hey all,

I also had this problem but this ended up working for me:

It has to do with broken symlinks in /sites-enabled. A symlink may break for different reasons, in this case, nginx can still follow the link, but certbot cannot. Why? I don’t know tbh.

To fix, I simply removed the symlink and created a new one.

If you list the directory you can typically spot a broken symlink with red text and a black background, and a working symlink with blue text:

naderabbara@server:/etc/nginx/sites-enabled$ ls
brokensymlink    workingsymlink

I removed the broken symlink and created a new one:

sudo rm <broken symlink>
sudo ln -s path/to/nginx/conf nginx-conf

Hope it’s this simple for you.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel