Skip to content
Follow
Ubuntu Linux

How to Setup Cloudflare Origin Certificates with Nginx on Ubuntu Linux

Richard
Written by
Richard
May 27, 2019 Updated Jul 14, 2026 5 min read
How to Install Nextcloud AIO on Ubuntu Linux
How to Install Nextcloud AIO on Ubuntu Linux

Cloudflare Origin Certificates secure your web server by encrypting traffic directly between Cloudflare and your server.

⚡ Quick Answer

Generate a Cloudflare Origin Certificate by navigating to the Crypto tab, scrolling to Origin Certificates, and clicking “Create Certificate”. Copy the provided private key and certificate content to text files on your Ubuntu server.

These free certificates, signed by Cloudflare, add an extra layer of security to your website when using Cloudflare’s Full SSL mode.

This tutorial guides you through setting up these certificates with Nginx on Ubuntu Linux. This ensures that only traffic coming through Cloudflare reaches your server, preventing attacks.

How to sign up for Cloudflare

The first step in this tutorial is to sign up for a Cloudflare account. This post assumes that you already have registered a domain name. If you don’t, then go and get one before continuing further.

If you already have a Cloudflare account, then skip the registration below.

https://dash.cloudflare.com/sign-up

Type in your email address and click Create Account.

Cloudflare WordPress setup
cloudflare wordpress setup

Once the account is created and you’ve verified your email address and logged back into the Cloudflare account, click the button or link (Add a Site) to add a site to your account.

Cloudflare WordPress setup
cloudflare wordpress setup 1

Next, type in the domain name you have registered. Again, Cloudflare service will help speed up and protect the site you add.

Cloudflare WordPress setup
cloudflare wordpress setup 2

Next, Cloudflare will query your domain DNS provider for the records in the DNS table. Cloudflare should find the domain and import the records into its DNS systems if it is online.

Cloudflare WordPress setup
cloudflare wordpress setup 3

After that, select the plan you want to use for the site. For this tutorial, we will be using the Cloudflare free plan.

Cloudflare WordPress setup
cloudflare wordpress setup 4

You should see two nameservers provided to you by Cloudflare when you’re done. You need to log on to your domain provider’s portal. Then, when you have your domain, replace the nameservers with the ones Cloudflare gives you.

Cloudflare setup showing name servers for domain configuration.
cloudflare setup name servers

For example, our example.com site is hosted with Google Domains. Log on to your Google Domains account and select use custom nameservers.

You’ll have the option to enter the nameservers provided by Cloudflare. Save your changes when you’re done.

Cloudflare WordPress Setup
cloudflare wordpress setup 16

Once you’ve saved your custom nameserver changes, return to your Cloudflare account and wait for Cloudflare to see the changes. Depending on your domain provider, it takes up to an hour for the DNS changes to be visible on Cloudflare.

Cloudflare overview page indicating an active SSL/TLS setup.
cloudflare overview active

Once all is ready, you’ll see your site status as Active.

Your Cloudflare account displays DNS entries after setup is complete. Your DNS records may contain more entries than the two shown in the example.

These two entries are the most important for running your website.

Cloudflare WordPress Setup
cloudflare wordpress setup 6

After that, click on the Crypto tab and choose to enable Full (strict) SSL. This should turn on SSL for the site.

Cloudflare WordPress Setup
cloudflare wordpress setup 17

While still on the Crypto tab, scroll down to Origin Certificates. Then click the button to create the Certificate.

Cloudflare Origin Certificates are free TLS certificates that you install on your origin server. These Origin Certificates encrypt traffic only between Cloudflare and your origin server.

Cloudflare WordPress setup step: entering domain name.
cloudflare wordpress setup 8

Next, let Cloudflare generate a private key and a CSR for the domain. Click Next.

WordPress Cloudflare
cloudflare wordpress setup 9

Then, copy and paste these into a text file onto your server.

Run the commands below on Ubuntu to create the Private key, Certificate, and Origin pull files (3 files). Then, copy and paste each content into the respective file. And save.

For the Private key file. Run this, copy and paste the private key given to you into the file, and save.

🐧Bash / Shell
sudo nano /etc/ssl/private/cloudflare_key_example.com.pem

For the certificate file, run this copy, paste the certificate content into the file, and save.

🐧Bash / Shell
sudo nano /etc/ssl/certs/cloudflare_example.com.pem

You’ll also want to download the Cloudflare Origin Pull certificate. You can download that from the link below:

Zone-Level — Cloudflare certificate

Under Zone-level certificate, expand the certificate button and copy its content.

Next, run the commands below to create an origin-pull-ca.pem file, paste the certificate content into the file below, and save.

🐧Bash / Shell
sudo nano /etc/ssl/certs/origin-pull-ca.pem

Once done, you should have three files. The cloudflare_key_example.com.pem, cloudflare_example.com.pem and origin-pull-ca.pem.

We will use these files in the Nginx config below.

Cloudflare WordPress setup: selecting a plan for the website.
cloudflare wordpress setup 10

Pull the certificate files after saving the key, Certificate, and Origin. Continue below.

Still, on the Crypto page in your Cloudflare account, enable Always use HTTPS, and you may also change settings for HSTS but not necessary.

Cloudflare WordPress setup: confirming domain name and plan.
cloudflare wordpress setup 11

Next, turn on Authenticated Origin Pulls and Opportunistic Encryption, and continue.

Cloudflare WordPress setup: scanning DNS records for the domain.
cloudflare wordpress setup 12

Then, turn on Automatic HTTPS Rewrites and continue.

Cloudflare WordPress setup: reviewing DNS records before activation.
cloudflare wordpress setup 13

Next, move to the Page Rules tab. Then, create a new rule for the site. Then, type the URL and choose Always Use HTTPS.

HTTP://* example.com/*

Always Use HTTPS

Cloudflare WordPress setup: successful activation confirmation page.
cloudflare wordpress setup 15

Save your settings, and you’re done with setting up Cloudflare.

How to configure Nginx with Cloudflare

Finally, configure the Nginx site configuration file for your website. This file will control how users access your website content. Run the commands below to create a new configuration file called example.com

🐧Bash / Shell
sudo nano /etc/nginx/sites-available/example.com

Then copy and paste the content below into the file and save it. Replace the highlighted line with your domain name and directory root location.

Also, reference the certificate files created above during Cloudflare setup.

🐘PHP
server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name  example.com www.example.com;
    root   /var/www/html/example.com;
    index  index.php;

    ssl_certificate /etc/ssl/certs/cloudflare_example.com.pem;
    ssl_certificate_key /etc/ssl/private/cloudflare_key_example.com.pem;
    ssl_client_certificate /etc/ssl/certs/origin-pull-ca.pem;
    ssl_verify_client on;

    client_max_body_size 100M;
  
    autoindex off;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }
}

Save the file and exit.

How to enable server block with Nginx

After configuring the server block above, please enable it by running the commands below.

🐧Bash / Shell
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Then open your browser and browse to the server domain name.

That should do it!

Conclusion:

This post showed you how to enable a Cloudflare origin certificate to enhance and secure the connection between Cloudflare’s server and your servers. If you find any error above, please use the comment form below to report.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to use Cloudflare Origin Certificates with Apache on Ubuntu Linux
Ubuntu Linux How to use Cloudflare Origin Certificates with Apache on Ubuntu Linux
How to Setup Let's Encrypt with Nginx on Ubuntu Linux
Ubuntu Linux How to Setup Let's Encrypt with Nginx on Ubuntu Linux
How to Install Nginx on Ubuntu Linux
Ubuntu Linux How to Install Nginx on Ubuntu Linux
How to Install PHP on Ubuntu Linux
Ubuntu Linux How to Install PHP on Ubuntu Linux

0 Comments

  • Atoro Desu

    Just a heads up, in Step 2: Configure NGINX, the command line example there has apache2 instead of NGINX

    Reply
  • @CNSKnight

    this article is DATED, and has hella cramatical issues.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *