Many modern applications combine two powerful tools:
- a VPS to run the application
- Cloudflare to handle security, DNS, and performance
This architecture allows developers to maintain full control over their infrastructure while benefiting from Cloudflare’s global network.
In this guide, we’ll walk through how to host your application on a VPS and connect it to Cloudflare.
Why Use a VPS with Cloudflare?
Cloudflare is excellent at handling traffic, caching content, and protecting applications from attacks.
However, Cloudflare does not replace the need for a server where your application actually runs.
A VPS provides:
- Full control over your server environment
- Ability to install any software stack
- Support for backend services and databases
- Flexibility to scale resources
When you combine a VPS with Cloudflare, you get both control and performance.
Architecture Overview
A typical setup looks like this:
User ↓ Cloudflare (DNS + CDN + Security) ↓ Your VPS ↓ Application Server
Cloudflare manages incoming traffic and security while your VPS runs the actual application.
Step 1: Launch a VPS
First, create a virtual machine.
Choose:
- an operating system (Ubuntu is commonly used)
- CPU and RAM depending on your application
- a region close to your users
Cloud platforms like Raff Cloud allow developers to launch a virtual machine in minutes.
Once your server is ready, connect via SSH.
ssh root@your_server_ip
Step 2: Install Your Application Environment
Depending on your project, install the required tools.
Common stacks include:
- Node.js
- Python
- Docker
- Nginx
- PostgreSQL or MySQL
Example installation for Node.js:
sudo apt update sudo apt install nodejs npm
After installing your runtime, deploy your application to the server.
Step 3: Configure a Reverse Proxy (Nginx)
Most production setups use Nginx as a reverse proxy.
Nginx handles incoming HTTP requests and forwards them to your application.
Basic flow:
Internet ↓ Nginx ↓ Application
Install Nginx:
sudo apt install nginx
Then configure a server block pointing to your application port.
Step 4: Add Your Domain to Cloudflare
Now connect your domain to Cloudflare.
Steps:
- Create a Cloudflare account
- Add your domain
- Update your domain’s nameservers to Cloudflare
Once this is done, Cloudflare will start managing your DNS.
Step 5: Point Your Domain to Your VPS
In the Cloudflare DNS dashboard, create an A record.
Example:
Type: A Name: @ IPv4 Address: your_server_ip Proxy Status: Enabled
When proxying is enabled, Cloudflare sits between users and your VPS.
This improves security and performance.
Step 6: Enable HTTPS and Security
Cloudflare simplifies SSL configuration.
You can enable:
- HTTPS encryption
- automatic SSL certificates
- DDoS protection
- caching rules
- firewall protection
This ensures traffic reaching your VPS is secure.
Final Architecture
After configuration, your infrastructure looks like this:
User ↓ Cloudflare ↓ Your VPS ↓ Application
Cloudflare improves performance and security while your VPS handles application logic.
Final Thoughts
Using Cloudflare with a VPS is one of the most common and practical architectures for modern web applications.
Cloudflare improves security and global performance, while a VPS provides the flexibility developers need to run their applications.
If you want to deploy your own server quickly, you can launch a virtual machine on Raff Cloud and start hosting your application in minutes.
