Back

Setting Up Cloudflare SSL with NGINX on Ubuntu 22.04 Server

Securing your website with SSL (Secure Sockets Layer) is a crucial step in ensuring data integrity and building trust with your visitors. Cloudflare, a content delivery and security service, offers SSL certificates that provide a secure connection between your website and its visitors. Combined with NGINX, a high-performance web server, you can create a robust and encrypted web experience. In this guide, we’ll walk you through the process of setting up Cloudflare SSL with NGINX on an Ubuntu 22.04 server.

Prerequisites

  • An Ubuntu server (such as Ubuntu 22.04 or later)
  • A registered domain name
  • Access to your Cloudflare account
  • Basic knowledge of the Linux command line

Step 1: Install NGINX

sudo apt update
sudo apt install nginx

Step 2: Configure NGINX

After installing NGINX, you’ll need to create a server block configuration for your website. This configuration will redirect HTTP traffic to HTTPS. Create a new configuration file:

sudo nano /etc/nginx/sites-available/your-site-name

Replace your-site-name with a suitable name for your site. Inside the file, set up a basic server block configuration:

server {
   listen 80;
   server_name your-domain.com www.your-domain.com;
   return 301 https://$host$request_uri;
}

Save the file and exit the text editor.

Step 3: Enable the Configuration

Create a symbolic link to your configuration file in the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/your-site-name /etc/nginx/sites-enabled/

Step 4: Test NGINX Configuration

Before proceeding, validate your NGINX configuration for syntax errors:

sudo nginx -t

If the test passes, reload NGINX to apply the changes:

sudo systemctl reload nginx

Step 5: Set Up Cloudflare SSL

Log in to your Cloudflare account and select your domain. Follow these steps:

a. Go to the “SSL/TLS” section.
b. Choose “Full” or “Full (strict)” for the SSL mode.
c. Cloudflare will provide you with SSL certificates. Keep this page open for reference.

Setting Up Cloudflare SSL with NGINX on Ubuntu 22.04 Server
Set Up Cloudflare SSL Origin Server

Step 6: Configure NGINX for SSL

Edit your NGINX configuration file again:

sudo nano /etc/nginx/sites-available/your-site-name

Update the server block to include SSL settings:

sudo nano /etc/nginx/sites-available/your-site-name
server {
   listen 443 ssl;
   server_name your-domain.com www.your-domain.com;

   ssl_certificate /path/to/cloudflare/certificate.crt;
   ssl_certificate_key /path/to/cloudflare/private-key.pem;
   ssl_client_certificate /path/to/cloudflare/cloudflare.crt;
   ssl_verify_client on;

   # Other SSL settings like SSL protocols and ciphers

   location / {
       # Your usual location block settings
   }
}
sudo nano /path/to/cloudflare/cloudflare.crt
-----BEGIN CERTIFICATE-----
MIIGCjCCA/KgAwIBAgIIV5G6lVbCLmEwDQYJKoZIhvcNAQENBQAwgZAxCzAJBgNV
BAYTAlVTMRkwFwYDVQQKExBDbG91ZEZsYXJlLCBJbmMuMRQwEgYDVQQLEwtPcmln
aW4gUHVsbDEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzETMBEGA1UECBMKQ2FsaWZv
cm5pYTEjMCEGA1UEAxMab3JpZ2luLXB1bGwuY2xvdWRmbGFyZS5uZXQwHhcNMTkx
MDEwMTg0NTAwWhcNMjkxMTAxMTcwMDAwWjCBkDELMAkGA1UEBhMCVVMxGTAXBgNV
BAoTEENsb3VkRmxhcmUsIEluYy4xFDASBgNVBAsTC09yaWdpbiBQdWxsMRYwFAYD
VQQHEw1TYW4gRnJhbmNpc2NvMRMwEQYDVQQIEwpDYWxpZm9ybmlhMSMwIQYDVQQD
ExpvcmlnaW4tcHVsbC5jbG91ZGZsYXJlLm5ldDCCAiIwDQYJKoZIhvcNAQEBBQAD
ggIPADCCAgoCggIBAN2y2zojYfl0bKfhp0AJBFeV+jQqbCw3sHmvEPwLmqDLqynI
42tZXR5y914ZB9ZrwbL/K5O46exd/LujJnV2b3dzcx5rtiQzso0xzljqbnbQT20e
ihx/WrF4OkZKydZzsdaJsWAPuplDH5P7J82q3re88jQdgE5hqjqFZ3clCG7lxoBw
hLaazm3NJJlUfzdk97ouRvnFGAuXd5cQVx8jYOOeU60sWqmMe4QHdOvpqB91bJoY
QSKVFjUgHeTpN8tNpKJfb9LIn3pun3bC9NKNHtRKMNX3Kl/sAPq7q/AlndvA2Kw3
Dkum2mHQUGdzVHqcOgea9BGjLK2h7SuX93zTWL02u799dr6Xkrad/WShHchfjjRn
aL35niJUDr02YJtPgxWObsrfOU63B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CXERVxajn/FLcOhglVAKo5H0ac+AitlQ0ip55D2/mf8o72tM
fVQ6VpyjEXdiIXWUq/o=
-----END CERTIFICATE-----

Replace /path/to/cloudflare/certificate.pem and /path/to/cloudflare/private-key.pem with the actual paths to the SSL certificate and private key provided by Cloudflare.

Step 7: Test and Reload NGINX

Test the configuration and reload NGINX:

sudo nginx -t
sudo systemctl reload nginx

Your NGINX server is now set up to serve your website securely over HTTPS through Cloudflare’s SSL.

In conclusion, securing your website with Cloudflare SSL and NGINX on Ubuntu involves several steps, from installing and configuring NGINX to setting up SSL certificates with Cloudflare. By following these steps, you’ll be providing your visitors with a secure and trustworthy browsing experience while also boosting your website’s performance.

Remember that this guide provides a general overview, and there might be variations based on specific configurations or updates that have occurred after the publication date. Always refer to official documentation and resources for the latest information and instructions.

admin
admin
https://nsreem.com

We use cookies to give you the best experience. Cookie Policy