Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Host a Website Using Cloudflare and Nginx on a VPS

A practical, end-to-end guide to hosting a static site or application with Nginx on an Ubuntu VPS while Cloudflare manages DNS, proxying, and origin TLS.
Length11 min Posted Quest giverVGSources Team

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the VPS as your origin server, Nginx as the web server or application reverse proxy, and Cloudflare as the domain’s authoritative DNS provider and optional HTTP/HTTPS reverse proxy. The reliable sequence is: install Nginx, configure a server block for your hostnames, point Cloudflare DNS to the VPS, change your registrar nameservers, install a suitable origin certificate, select Full (strict), and verify both DNS and HTTPS before exposing the site.

What this setup does

A visitor requests example.com. Cloudflare answers for the domain and, when the DNS record is proxied, receives the web request at its edge. Cloudflare then opens a connection to your VPS, where Nginx serves files or forwards the request to an application. In this design, the VPS remains the origin; Cloudflare does not replace Nginx.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cloudflare’s DNS and proxy controls are separate. An A or AAAA record tells DNS which origin address belongs to a hostname. The orange-cloud proxy setting determines whether HTTP and HTTPS requests pass through Cloudflare or go directly to that address. Cloudflare describes this role as acting as the reverse proxy and DNS provider for the site.

Keep records for services that are not ordinary web traffic, such as mail, DNS-only unless the service explicitly supports Cloudflare proxying. Proxying a mail hostname can break mail delivery because the proxy is intended for supported HTTP and HTTPS traffic.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Prerequisites and planning

Prepare these items before changing DNS:

  • A registered domain and access to its registrar account.
  • A VPS with a public IPv4 address, IPv6 address, or both.
  • SSH access and an Ubuntu installation on the VPS.
  • Permission to edit the registrar’s nameservers and the domain’s Cloudflare DNS records.
  • A decision about whether Nginx will serve static files or proxy to an application process.
  • A plan for the origin certificate: a publicly trusted Let’s Encrypt certificate, or a Cloudflare Origin CA certificate used only on the Cloudflare-to-origin connection.

Write down the exact hostnames you will publish, normally the apex name and www. Certificate coverage, Nginx’s server_name, DNS records, and the URLs you test must use the same names. Cloudflare warns that missing or incorrect records can result in DNS_PROBE_FINISHED_NXDOMAIN, so do not remove the old nameservers until the replacement records are ready.

Install Nginx on Ubuntu

For an Ubuntu distribution package, connect over SSH and run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt update
sudo apt install nginx
sudo systemctl status nginx

Ubuntu identifies Nginx as a high-performance web server and reverse proxy. The status command should show the service running. If it is not active, inspect the service output before changing configuration; a syntax error in a newly enabled site can prevent a reload or restart.

Nginx also publishes signed packages. Its current package information lists Ubuntu 22.04, 24.04, and 26.04 among supported releases. If you choose that repository instead of Ubuntu’s distribution package, use the repository intended for your exact operating-system release and verify its signing keys. Do not mix package instructions for one Ubuntu version with another.

Build the Nginx site configuration

Create a directory for static files

For a simple static site, create a document root. Replace the example hostname with yours:

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html
printf '%sn' '<!doctype html><html><head><meta charset="utf-8"><title>Example site</title></head><body><h1>It works</h1></body></html>' > /var/www/example.com/html/index.html

The ownership command makes the directory manageable by the account you used for SSH. For a production deployment, copy your built files into this directory and apply the permissions policy appropriate to your deployment process.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Write a server block

Ubuntu’s sites-available convention keeps each virtual host in its own file. Create /etc/nginx/sites-available/example.com:

server {
    listen 80;
    listen [::]:80;

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

    location / {
        try_files $uri $uri/ =404;
    }
}

The server_name line is not cosmetic: Nginx uses it to select the block that handles the requested Host header. Include every hostname you intend to serve. The root directive points to the files, while try_files returns a 404 when the requested path does not exist.

Enable the file with the standard Ubuntu symlink, test the complete configuration, and only then reload:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
sudo nginx -t
sudo systemctl reload nginx

sudo nginx -t must report a successful syntax test before every reload. If it names a file or line, correct that specific problem and run the test again. A reload applies a valid configuration without unnecessarily terminating existing connections.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Proxy an application instead of serving files

If your site is an application listening locally, use a location block with proxy_pass rather than a static document root. A minimal pattern is:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

Change the address and port to the process that runs your application. Keep the application bound to the intended interface, and confirm that it is listening before blaming Nginx. The Nginx Beginner’s Guide covers the related static-content, proxy-server, and FastCGI patterns; use the appropriate one for your application stack. After editing, repeat sudo nginx -t and reload.

Put the domain on Cloudflare

Add the zone and review imported records

  1. Sign in to Cloudflare and add the apex domain, such as example.com.
  2. Review the records Cloudflare imports. Remove stale web records and correct any record that points at an old server.
  3. Create an A record for the VPS IPv4 address and an AAAA record when you intend to serve IPv6. Use the apex name for the root record and create the www record as required by your naming plan.
  4. Set the web records to Proxied when browser traffic should traverse Cloudflare. Leave mail and other unsupported service records DNS-only.

An A or AAAA record identifies the origin; it does not by itself turn on Cloudflare’s reverse proxy. Conversely, a proxied record cannot repair an incorrect address. Verify both the value and the proxy status in the DNS dashboard.

Change the registrar nameservers

  1. Cloudflare supplies two authoritative nameservers for the zone.
  2. At the registrar, replace the existing nameservers with exactly those two assigned nameservers.
  3. Save the change and wait for delegation to update. Until delegation changes, public resolvers may continue using the previous DNS provider.

Do not assume that adding a zone in Cloudflare automatically changes delegation. The registrar step is what makes Cloudflare authoritative. During the transition, test from more than one network and allow for resolver caching.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose and install the origin TLS certificate

HTTPS has two relevant legs: the visitor-to-Cloudflare connection and, when proxying is enabled, the Cloudflare-to-origin connection. Your certificate choice determines whether the origin can be validated when Cloudflare connects to Nginx and whether browsers can connect directly if proxying is later disabled.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
Criterion Let’s Encrypt with Certbot Cloudflare Origin CA
Browser trust when the origin is reached directly Designed to provide a publicly trusted certificate. Designed for Cloudflare-to-origin encryption; browsers may show a certificate-authority error if they connect directly.
Dependence on Cloudflare proxying Can be used with or without Cloudflare proxying. Intended for proxied traffic and should not be exposed directly when proxying is disabled.
Issuance workflow Certbot uses the Let’s Encrypt ACME service and can install the result through its Nginx plugin. Create an Origin CA certificate in Cloudflare, then install the supplied certificate and private key on Nginx.
Hostname coverage Request the exact names you serve, such as the apex and www. Issue the certificate for the hostnames Cloudflare will use to reach the origin.
Operational monitoring Track renewal and confirm that the installed certificate remains current. Track expiration yourself; Cloudflare states that it does not send expiration notifications for Origin CA certificates.

Option A: Let’s Encrypt through Certbot

Ubuntu recommends Certbot as an ACME client, and its Nginx plugin can obtain a certificate for the configured domains, edit the matching server block, and reload Nginx. With the server block already naming both hosts, run:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Follow Certbot’s prompts and read the proposed Nginx changes before accepting them. The certificate must cover every hostname that browsers will request. After completion, run sudo nginx -t and request both HTTP and HTTPS URLs. Keep a record of the certificate locations and verify your renewal process rather than assuming an unattended renewal is working.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Option B: Cloudflare Origin CA

  1. In Cloudflare’s SSL/TLS area, create an Origin CA certificate covering the hostnames that Cloudflare will send to the VPS.
  2. Copy the PEM certificate and private key to protected files on the VPS. Restrict access to the key according to your operating-system policy.
  3. Update the Nginx server block to listen on port 443 and reference the certificate and key files. Keep the port-80 block available for the HTTP behavior you choose, commonly a redirect after HTTPS is confirmed.
  4. Run sudo nginx -t, reload Nginx, and confirm that the origin accepts HTTPS.
  5. In Cloudflare, select Full (strict) once the valid origin certificate is installed.

Cloudflare Origin CA certificates encrypt the Cloudflare-to-origin leg and are compatible with Strict SSL mode. They are not general-purpose public certificates. If you pause or disable Cloudflare proxying, a visitor connecting directly to the VPS can receive a certificate-authority error because the browser does not trust the Origin CA chain. Use a publicly trusted certificate when direct browser access must remain valid.

Full versus Full (strict)

Full (strict) is the appropriate end state when Nginx presents a valid certificate for the requested hostname. It lets Cloudflare encrypt the origin connection and validate the certificate. If the origin certificate is missing, expired, does not match the hostname, or is otherwise not accepted, strict mode will fail the connection. A non-strict Full setting can be used only as a temporary compatibility step while you install a proper origin certificate; it does not replace that certificate or remove the need to maintain one.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Open the required network paths

The origin must be reachable on the ports required by your selected validation and HTTPS design. At minimum, your plan must account for SSH administration and the HTTP and HTTPS listeners that Nginx uses. Check the VPS firewall and any provider-level network firewall before testing through Cloudflare. A correct DNS record cannot compensate for a blocked origin port.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

When using Certbot, make sure the validation method you selected can reach the hostname and that Nginx serves the challenge on the expected listener. When using Origin CA, make sure port 443 is enabled and the certificate files are readable by Nginx while the private key remains protected.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify the finished deployment

Perform these checks in order so that a failure points to the right layer:

  1. Delegation: confirm that the registrar now lists the two Cloudflare-assigned nameservers.
  2. DNS records: resolve the apex and www names and confirm that the A or AAAA values correspond to the VPS. A proxied response may show Cloudflare addresses rather than the VPS address; that is expected when proxying is enabled.
  3. Proxy status: confirm that the web records have the intended Proxied or DNS-only state. Do not infer status from the returned IP alone.
  4. Nginx configuration: run sudo nginx -t and check that the active server block contains the expected server_name, root or proxy target, and HTTPS certificate paths.
  5. Origin listeners: verify that Nginx is listening on the ports required by the design and that the application process is listening on its local port when applicable.
  6. HTTP: request the apex and www URLs and confirm that the expected site, redirect, or application response appears.
  7. HTTPS: request both names over HTTPS. Confirm that the certificate names match the hostname and that the connection remains successful through the selected Cloudflare SSL mode.
  8. Direct-origin behavior: if you use an Origin CA certificate, do not treat a direct browser certificate warning as a Cloudflare failure; it is the expected limitation when proxying is bypassed.

Troubleshoot common failures

DNS_PROBE_FINISHED_NXDOMAIN

Check that the registrar delegation points to Cloudflare, that the zone is active there, and that an A or AAAA record exists for the exact hostname. Also check for a typo in the hostname and whether you are testing a name that has no record. Changing Nginx cannot fix an NXDOMAIN response because the request has not reached the VPS.

The domain resolves but the site does not load

First check proxy status and the VPS firewall. Confirm that Nginx is running, that the relevant port is open, and that the request’s hostname appears in server_name. For a static site, verify the file exists beneath the configured root. For an application, verify the local process and the proxy_pass destination.

Nginx will not reload

Run sudo nginx -t and fix the first reported error. Typical causes are a missing semicolon, an incorrect certificate path, a duplicate or malformed server block, or a symlink to a file that was moved. Do not repeatedly restart the service without reading the test output; a restart can interrupt otherwise healthy sites.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

HTTPS fails after enabling strict mode

Check that port 443 is reachable, the certificate and private key files are present, and the certificate covers the hostname Cloudflare requested. Ensure the Nginx HTTPS block is enabled and that the certificate has not expired. Full (strict) requires a valid origin certificate, including a correctly installed Cloudflare Origin CA certificate.

A browser warns about the certificate after proxying is paused

This is expected for a Cloudflare Origin CA certificate when visitors connect directly to the VPS. Restore Cloudflare proxying, or replace the origin certificate with one issued by a publicly trusted authority if direct access is a requirement.

Maintenance after launch

  • Keep Ubuntu, Nginx, and the application packages maintained. Apply updates appropriate to the installed Ubuntu release and package source.
  • Run sudo nginx -t before every reload, including reloads performed by deployment tooling.
  • Maintain an inventory of certificate names, file locations, issuer, and expiration date.
  • Test certificate renewal before the current certificate approaches expiration. Certbot and an Origin CA certificate have different issuance and monitoring workflows.
  • Recheck both apex and www after DNS, Nginx, certificate, or proxy-status changes.
  • Document which records are proxied and which are DNS-only so a future operator does not proxy mail or another unsupported service accidentally.
  • Review the origin firewall whenever you change the validation method, enable IPv6, or add an HTTPS listener.

A practical decision framework

Choose the Nginx role

  • Use a static root and try_files block for files generated by a site build.
  • Use proxy_pass when a separate application server renders responses or provides an API.
  • Use FastCGI configuration when your application runtime requires it rather than treating every backend as an HTTP proxy.

Choose the certificate

  • Choose Let’s Encrypt with Certbot when the VPS may be visited directly, when Cloudflare proxying might be paused, or when you want a browser-trusted origin certificate.
  • Choose Cloudflare Origin CA when the origin is deliberately private behind Cloudflare and you will keep the web records proxied. Track expiration yourself because Cloudflare does not provide Origin CA expiration notifications.
  • Whichever path you choose, select Full (strict) only after the origin certificate is installed, matches the hostnames, and Nginx serves it on port 443.

The durable arrangement is therefore straightforward: DNS identifies the VPS, proxy status controls whether Cloudflare sits in front of it, Nginx selects the correct site by hostname, and a maintained origin certificate allows strict TLS between Cloudflare and the VPS.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.