requested domain name does not match the server’s certificate

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: I)

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

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

III) certificates are generated in the following location /etc/letsencrypt/live/ cert.pem fullchain.pem chain.pem privkey.pem


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/

VII) 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

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.