Setting up Cloudflare for your server can significantly enhance its security, performance, and reliability. This guide will walk you through creating a Cloudflare account, setting up your domain records, and using Cloudflare Zero Trust applications to establish a tunnel and subdomains for your server. This comprehensive, step-by-step guide is perfect for new users.
Step 1: Create a Cloudflare Account
1.1 Sign Up for Cloudflare
- Go to Cloudflare’s website.
- Click on the Sign Up button in the top-right corner.
- Enter your email address and create a password.
- Click Create Account.
1.2 Add Your Site
- After signing up, you’ll be prompted to add a site. Enter your domain name (e.g.,
example.com
) and click Add Site. - Cloudflare will scan your existing DNS records. Review and confirm these records to ensure they are correct.
1.3 Select a Plan
- Choose a plan that suits your needs. The free plan is sufficient for most users.
- Click Continue.
1.4 Update Your Nameservers
- Cloudflare will provide you with two nameservers. You need to update your domain registrar’s settings to use these Cloudflare nameservers.
- Log in to your domain registrar’s website.
- Find the DNS settings for your domain.
- Replace the existing nameservers with the ones provided by Cloudflare.
- Save the changes.
It may take up to 48 hours for these changes to propagate.
Step 2: Configure DNS Records
2.1 Access the DNS Settings
- Log in to your Cloudflare account.
- Select your domain from the dashboard.
- Navigate to the DNS tab.
2.2 Add DNS Records
- To add an A record:
- Click Add Record.
- Select A from the Type drop-down menu.
- Enter the subdomain you want to use (e.g.,
www
) in the Name field. - Enter your server’s IP address in the IPv4 address field.
- Ensure the Proxy status is set to Proxied.
- Click Save.
- Repeat the process for any other records you need to add (e.g., MX, CNAME, TXT).
Step 3: Set Up Cloudflare Zero Trust and Tunnels
3.1 Access Zero Trust Dashboard
- Navigate to the Cloudflare Zero Trust dashboard.
- Log in with your Cloudflare account.
3.2 Create a Tunnel
- In the Zero Trust dashboard, go to Access > Tunnels.
- Click Create a Tunnel.
- Enter a name for your tunnel (e.g.,
MyServerTunnel
). - Click Save.
3.3 Install Cloudflare Tunnel on Your Server
- Follow the instructions provided to download and install the Cloudflare Tunnel client (
cloudflared
) on your server. - Authenticate
cloudflared
with your Cloudflare account:cloudflared login
- Start the tunnel
cloudflared tunnel --config /etc/cloudflared/config.yml run MyServerTunnel
3.4 Configure Tunnel Routes
- In the Zero Trust dashboard, go to Access > Tunnels.
- Select your tunnel and click Configure.
- Add a new route:
- Enter the hostname (e.g.,
myapp.example.com
). - Select the service type (e.g., HTTP).
- Enter your server’s local address and port (e.g.,
http://localhost:8080
).
- Enter the hostname (e.g.,
- Click Save.
3.5 Configure Zero Trust Policies
- In the Zero Trust dashboard, go to Access > Applications.
- Click Add an Application.
- Choose the application type (e.g., Self-Hosted).
- Enter the application details:
- Name: The name of your application.
- Domain: The subdomain you configured (e.g.,
myapp.example.com
).
- Click Next.
- Configure access policies:
- Specify who can access the application (e.g., only specific email domains, users, or groups).
- Click Save.
Step 4: Verify and Test
- Ensure your server is running and accessible through the configured tunnel.
- Visit the subdomain you set up (e.g.,
myapp.example.com
) to verify that it works. - Test the access policies to ensure only authorized users can access the application.
Conclusion
By following these steps, you have successfully set up a Cloudflare account, configured your domain records, and established a Cloudflare Tunnel using Zero Trust applications. This setup provides enhanced security and performance for your server while allowing you to manage access control efficiently.
Feel free to reach out for any further assistance or clarifications! Happy hosting!