how to install let's encrypt certificate with express and node.js ?

how to install let’s encrypt certificate with express and node.js ?

Submit an answer
Answer a question...

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.

Site Moderator
Site Moderator badge
January 23, 2023

Hi @4f4cefbb8aa1434c9446051567aea7,

I would assume you are using Nginx as a reverse proxy, am I right? If yes then using Certbot to auto-install certificates should do the trick for you. Just auto-deploy:

Alternatively, you can run the following :

  1. # Create the SSL certificate
  2. certbot certonly --standalone

This will generate a certificate for you for your domain. Once you have it, you can add the following to your Nginx reverse proxy configuration:

# HTTPS — proxy all requests to the Node app
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;

    # Include the SSL configuration from
    include snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:8000/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;

Where proxy_pass http://localhost:8000/ will have the port of your application.