Using certbot behind nginx to get certificates

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. crt.sh | example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is: psychphransisco.com

I ran this command: $ sudo certbot --nginx

It produced this output:
psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$ sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
/etc/letsencrypt/options-ssl-nginx.conf has been manually modified; updated file saved to /snap/certbot/3834/lib/python3.8/site-packages/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf. We recommend updating /etc/letsencrypt/options-ssl-nginx.conf for security purposes.

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.


1: psychphransisco.com
2: api.psychphransisco.com
3: www.psychphransisco.com


Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
Requesting a certificate for psychphransisco.com and 2 more domains

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/psychphransisco.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/psychphransisco.com/privkey.pem
This certificate expires on 2024-09-23.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for psychphransisco.com to /etc/nginx/sites-enabled/default
Successfully deployed certificate for api.psychphransisco.com to /etc/nginx/sites-enabled/default
Successfully deployed certificate for www.psychphransisco.com to /etc/nginx/sites-enabled/default
We were unable to install your certificate, however, we successfully restored your server to its prior configuration.

NEXT STEPS:

  • The certificate was saved, but could not be installed (installer: nginx). After fixing the error shown below, try installing it again by running:
    certbot install --cert-name psychphransisco.com

nginx restart failed:
nginx: [emerg] "ssl_dhparam" directive is duplicate in /etc/nginx/sites-enabled/default:19

My web server is (include version): nginx -v

The operating system my web server runs on is (include version):
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
psychphransiscobounce@p

My hosting provider, if applicable, is:
psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$ curl "http://metadata.google.internal/computeMetadata/v1/instance/id" -H "Metadata-Flavor: Google"
7945750991747948125

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

I'm using a control panel to manage my site (no, or provide the name and version of the control panel):
psychph+ 55767 0.0 0.2 8176 2564 pts/0 S+ 14:14 0:00 grep --color=auto -E cpanel|plesk|webmin|ispconfig

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

*The problem they are saying is that ssL-dhparam are duplicated but in all of my files I do not even have those parameters in my code yet so i can't get past this

Welcome @Ajar67

That must be somewhere. Possibly related to the error:

In any case, if you show the output of this we can sort out what is happening

sudo nginx -T

An uppercase T is essential. It shows the entire active nginx config. The output is long. That's fine. Or pipe that to a .txt file and upload it.

sudo nginx -T >config.txt
3 Likes

psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$ sudo nginx -T
nginx: [warn] conflicting server name "psychphransisco.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.psychphransisco.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "api.psychphransisco.com" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_names_hash_bucket_size 128;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
# 
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

# configuration file /etc/nginx/mime.types:

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

# configuration file /etc/nginx/sites-enabled/default:
server {
  listen 80;

  server_name psychphransisco.com www.psychphransisco.com api.psychphransisco.com;

  location / {
    proxy_pass http://localhost:3003;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

# configuration file /etc/nginx/sites-enabled/default_backup:
server {
  listen 80;

  server_name psychphransisco.com www.psychphransisco.com api.psychphransisco.com;

  location / {
    proxy_pass http://localhost:3003;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$

Thank you for helping!

1 Like

The first (main) problem is you have a file named default_backup in your sites-enabled folder. You include all files from there so have duplication. You need to move that file out of that folder so only the default file remains in sites-enabled.

I think that will also fix the error about ssl_dhparam being duplicated but we'll see.

I am also bothered about the error saying the below file was modified. Would you please show contents of:

/etc/letsencrypt/options-ssl-nginx.conf
1 Like

psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$
cat /etc/letsencrypt/options-ssl-nginx.conf

ssl_session_cache shared:le_nginx_SSL:1m;
ssl_session_timeout 1440m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;

ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';

ssl_ecdh_curve secp384r1;
ssl_dhparam /etc/nginx/dhparam.pem;

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
1 Like

Okay, that is quite a bit different than the one provided by Certbot. So, I assume you intentionally modified it for your preferences.

But, that is the cause of the duplicate dh_param message and should be resolved once you remove the default_backup

After that is gone follow the instructions to install. Let us know what happens

1 Like

I didn't touch that file though ... and just installed it from certbot

psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$ sudo certbot install --cert-name psychphransisco.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Deploying certificate
Successfully deployed certificate for psychphransisco.com to /etc/nginx/sites-enabled/default
Successfully deployed certificate for api.psychphransisco.com to /etc/nginx/sites-enabled/default
Successfully deployed certificate for www.psychphransisco.com to /etc/nginx/sites-enabled/default
We were unable to install your certificate, however, we successfully restored your server to its prior configuration.
nginx restart failed:
nginx: [emerg] "ssl_dhparam" directive is duplicate in /etc/nginx/sites-enabled/default:19

Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.
psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$

Well, someone did, as it definitely isn't a file that came from Certbot directly. You can see all the configuration files here, old and new: certbot/certbot-nginx/certbot_nginx/_internal/tls_configs at master · certbot/certbot · GitHub. And the one you've got isn't there. Also, the Certbot files all start with a header explaining the file.

Weird, I don't see that directive, but I'm guessing Certbot puts the include directive to the options-ssl-nginx.conf file in every server {} block and nginx doesn't like that.

You should move the ssl_dhparam directive to a file which is only included just once.

1 Like

Alrighty ... would you recommend that i switch to the config file it should be... the one from Certbot directly?

That's probably a good idea, although you're of course allowed to configure nginx to your own pleasing.

In any case, the ssl_dhparam needs to be in a separate configuration file which is only included just once and not in options-ssl-nginx.conf which is included multiple times when Certbot installs certs.

which file should that be? And would I have to update the server block?

does it matter which options config file I use?

I think /snap/certbot/3834/lib/python3.8/site-packages/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf is the most recent and you can simply copy that one.

Note that Certbot has a --hsts option if you want to keep using HSTS. And the other add_header directives, if you want to use them, should be moved into a different configuration file, just like the other directives not included in the options-ssl-nginx.conf provided by Certbot.

1 Like

In theory yes but in this case all 3 domain names are in the same port 80 server block. So, there would only be one port 443 server block with that included. Right?

The problem they had originally was duplicated port 80 server block so definitely would get duplicated then.

1 Like

I don't know what Certbot is up to when installing the cert :person_shrugging:t2: The duplicate error needed to come from somewhere..

Yes, I wonder if the duplicate port 80 server block was properly removed prior to the latest install attempt

@Ajar67 What does this show now?

sudo nginx -t

lowercase t okay for this one

1 Like

Hey I am so sorry had to step away from computer ... I created a different file for the ssl_dhparam and then ran .... sudo openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048 .... and then included it in the nginx.conf file in the http{} block and ran 'sudo nginx -t' and got tests successfull .... psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
psychphransiscobounce@psychphransisco:~/stocks_with_joe_backend$

1 Like

I also fixed options-ssl-nginx.conf file with the one y'all sent me ... thank you!

1 Like

Good progress. Looks like HTTPS is working now. Is it for you?

2 Likes