requested domain name does not match the server’s certificate

Posted February 28, 2018 20.2k views
UbuntuApacheDigitalOceanLet's EncryptUbuntu 16.04

Hi all,

my requirement is i need to redirect from to

The url ( is the web application using flask

The error am getting while running from the browser is ** your connection is not secure uses an invalid security certificate. The certificate is only valid for the following names:,**

The following are the installation/configuration steps carried out:

My domain is registered in Godaddy
in Godaddy, the forwarding section we had added the URL
Forward Type: Permanent(301)
SETTINGS: Forward Only

sudo add-apt-repository ppa:certbot/certbot
sudo apt-get install python-certbot-apache
sudo certbot –apache -d -d

certificates are generated in the following location


In the following location /etc/nginx/sites-available/default

The following is the change

    server {
    listen 80;
    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;


    location /.well-known {
            allow all;
            default_type "text/plain";
            autoindex    on;
            location / {
            return 301$request_uri;


  server {

   listen [::]:443 ssl ipv6only=on; # managed by Certbot

    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

        location / {
          proxy_pass "";


In the following location /etc/nginx/sites-enabled/000-default.conf

The following is the change

    <VirtualHost *:443>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    Redirect permanent /
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


VI) In the following location /etc/apache2/sites-available/default

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    Redirect permanent /

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
     SSLEngine on
     SSLCertificateFile /etc/letsencrypt/live/
     SSLCertificateKeyFile /etc/letsencrypt/live/

In flask web application the following is the change

    if __name__ == '__main__':,ssl_context=('/etc/letsencrypt/live/','

Please suggest how can i resolve the error

Please suggest what best can be done to redirect to the https URL seamlessly

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.

Submit an Answer
1 answer

You cannot acquire a LetsEncrypt certificate for an IP address currently. You could either use a paid CA to issue a certificate for the IP address, reconfigure your control panel to use the domain name instead of the IP address or set up a reverse_proxy configuration in nginx to route the control panel access through it instead of redirecting it.