添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Report this

What is the reason for this report?

How To Host a Website Using Cloudflare and Nginx on Ubuntu 20.04

Updated on January 12, 2022
anondon Matt Abrams
English
How To Host a Website Using Cloudflare and Nginx on Ubuntu 20.04

The author selected the Electronic Frontier Foundation to receive a donation as part of the Write for DOnations program.

Introduction

Cloudflare is a service that sits between the visitor and the website owner’s server, acting as a reverse proxy for websites. Cloudflare provides a Content Delivery Network (CDN), as well as DDoS mitigation and distributed domain name server services.

Nginx is a popular web server responsible for hosting some of the largest and highest-traffic sites on the internet. It’s common for organizations to serve websites with Nginx and use Cloudflare as a CDN and DNS provider.

In this tutorial, you will secure your website served by Nginx with an Origin CA certificate from Cloudflare ) and then configure Nginx to use authenticated pull requests. The advantages of using this setup are that you benefit from Cloudflare’s CDN and fast DNS resolution while ensuring that all connections pass through Cloudflare. This prevents any malicious requests from reaching your server.

Prerequisites

  • the Ubuntu 20.04 initial server setup guide , including a sudo non-root user and a firewall.
  • Nginx installed on your server. You can follow our guide on how to install Nginx on Ubuntu 20.04 .
  • A Cloudflare account.
  • A registered domain added to your Cloudflare account that points to your Nginx server. Our guide on how to mitigate DDoS attacks against your website with Cloudflare can help you set this up. Our introduction to DNS terminology, components, and concepts can also provide assistance.
  • An Nginx Server Block configured for your domain, which you can do by following Step 5 of How To Install Nginx on Ubuntu 20.04 .
  • Step 1 — Generating an Origin CA TLS Certificate

      1. Step 2 — Installing the Origin CA Certificate in Nginx

                    1. Step 3 — Setting Up Authenticated Origin Pulls

                      Cloudflare’s documentation.

                      Copy this certificate.

                      Then create the file /etc/ssl/cloudflare.crt file to hold Cloudflare’s certificate:

                            1. Conclusion

    Matt Abrams
    Matt Abrams
    Editor
    See author profile

    Supporting the open-source community one tutorial at a time. Former Technical Editor at DigitalOcean. Expertise in topics including Ubuntu 22.04, Ubuntu 20.04, CentOS, and more.

    Still looking for an answer?

    Was this helpful?
    

    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!

    Hi, i did what you said but i am having an issue where www.domain.com has an SSL but domain.com doesn’t. You can check it out yourself, plutus.gq does have an SSL but www.plutus.gq does. Can you please help me ?

    I have followed these steps and encounter the following error when trying to load my page :

    ERR_SSL_VERSION_OR_CIPHER_MISMATCH

    Any suggestions?

    this is a great article, it’s work, but lose one step:

    after edit /etc/nginx/sites-available/your_domain then should link file to sites-enable or nginx will not start correctly

    ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enable/your_domain
    

    This is a dangerous article, it should enfatize that turning on ufw without setting up ssh might make you lose connection with your server at all ¬¬

    You should always run this before enabling ufw if you are on remote server:

    sudo ufw allow ssh
    

    https://stackoverflow.com/questions/55022757/unable-to-reach-ec2-instance-after-setting-up-nginx

    great tutorial as usual.

    You might want to consider adding another step and only allow Cloudflare IP addresses to enforce the Origin Server, as recommended by Cloudflare.

    This way any attempt to access the website through the ip address (instead that through the domain name) will be handled (and rejected) by the firewall instead of by NGINX. All the scam requests will be cleared from NGINX logs.

    Using UFW will require something like this:

    $ sudo ufw allow proto tcp from <ip address range> to any port 443
    

    instead of

    $ sudo ufw allow 'Nginx HTTPS'