Cannot find a VirtualHost matching domain mydomain.cz

Hi,

I’m getting error Cannot find a VirtualHost matching domain mydomain.cz when trying to generate certificate with certbot:

pooik@server:~$ sudo certbot --nginx certonly
Saving debug log to /var/log/letsencrypt/letsencrypt.log
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): mydomain.cz mydomain2.cz
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for mydomain.cz
tls-sni-01 challenge for mydomain2.cz
Cleaning up challenges
nginx: [error] invalid PID number "" in "/run/nginx.pid"
Encountered exception during recovery
nginx restart failed:

Traceback (most recent call last):
 File "/usr/lib/python2.7/dist-packages/certbot/error_handler.py", line 99, in _call_registered
  self.funcs[-1]()
 File "/usr/lib/python2.7/dist-packages/certbot/auth_handler.py", line 284, in _cleanup_challenges
  self.auth.cleanup(achalls)
 File "/usr/lib/python2.7/dist-packages/certbot_nginx/configurator.py", line 824, in cleanup
  self.restart()
 File "/usr/lib/python2.7/dist-packages/certbot_nginx/configurator.py", line 590, in restart
  nginx_restart(self.conf('ctl'), self.nginx_conf)
 File "/usr/lib/python2.7/dist-packages/certbot_nginx/configurator.py", line 853, in nginx_restart
 "nginx restart failed:\n%s\n%s" % (out.read(), err.read()))
 MisconfigurationError: nginx restart failed:

 Cannot find a VirtualHost matching domain mydomain.cz.

My nginx.conf looks like this:

#user  nobody;
worker_processes  1;
#pid        logs/nginx.pid;
events {
  worker_connections  1024;
}

http {
  passenger_root /home/spravce/.rvm/gems/ruby-2.4.1/gems/passenger-5.1.6;
  passenger_ruby /home/spravce/.rvm/gems/ruby-2.4.1/wrappers/ruby;

  include       mime.types;
  default_type  application/octet-stream;

  sendfile        on;
  keepalive_timeout  65;

  server {
    listen  80;
    listen 443 ssl;
    server_name mydomain.cz www.mydomain.cz;

    ssl_certificate      nginx-selfsigned.crt;
    ssl_certificate_key  nginx-selfsigned.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    root /www/mydomain.cz;
    index index.html;
    location / {
      try_files $uri $uri/ =404;
    }
  }

  server {
    listen  80;
    listen 443 ssl;
    server_name mydomain2.cz www.mydomain2.cz;

    ssl_certificate      nginx-selfsigned.crt;
    ssl_certificate_key  nginx-selfsigned.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    root /www/mydomain2.cz;
    index index.html;
    location / {
      try_files $uri $uri/ =404;
    }
  }
}

Any ideas?

Thanks

Hi @Pooik,

Can you tell us what version of Certbot you’re running? Certbot’s nginx support has improved a lot over time, and so it’s possible that this failure is associated with using an older version.

@erica, have you seen this kind of error with “nginx restart failed” before, by any chance?

I’m definitely interested in seeing what version of Certbot this is, because if there’s a problem with the config files (which leads to the “failed to restart” error), it shouldn’t be getting to “please enter in your domain names” (which it shouldn’t be doing anyway, since there are domain names in there).

Hi,

I’m running version 0.17.0. I was installing it yesterday, using this: https://certbot.eff.org/#ubuntuxenial-nginx

Thanks

Hi,

any new thoughts?

Thanks

Isn’t the problem that I’m not using sites-available? I’m having all in nginx.config?

Hi @Poolk,

I think your guess is plausible.

You might not be able to get a reply from @erica about this right away because this is a holiday weekend in the United States, and so she won’t be back at work until September 5.

No, sites-available-based configs should be treated the same as including it all in a single config file.

Is nginx.conf located in /etc/nginx/? If not, you can use the --nginx-server-root flag to set it to the directory containing nginx.conf.

Ok, my nginx intallation seemed to be completely uncommon, so I reinstalled whole VPS according to this tutorial https://gorails.com/deploy/ubuntu/16.04 and now the certification ran correctly.

So thank you

Glad you got it working!

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