DEV Community


Posted on • Originally published at


Cloudflare Load Balancing with Laravel Forge SFTP File Only Servers

Table Of Contents


  1. Using Laravel Forge to setup servers
  2. Syncing folder(s) between Server 1 and Server 2
  3. Using Load balancing with Cloudflare

Setting up servers with Laravel Forge

rsync is required to sync between servers, using Laravel Forge to setup the servers will automatically install rsync

  1. Setup 2 servers
    • Do not delete the default site, deleting it did not work with load balancing for some reason
  2. SSH into server #2
  3. Create SSH key in server #2 and choose to save the key into /home/forge/.ssh/
  4. Copy the contents of the newly generated key with cat/home/forge/.ssh/<key_name_from_step_2>.pub
  5. Add the key to server #1 in Laravel Forge SSH Keys
  6. Create the main folder in server #1 and #2 that you want to be synced between them
  7. Add a test file to server #1 folder for test syncing
  8. In server #2 run: sudo rsync -avzhe "ssh -i /home/forge/.ssh/<key_name_from_step_2>" forge@<server_1_ip_address>:<directory_from_server_1_to_sync> <server_2_directory_to_sync_into>
    • If successful, terminal will show the files that got synced
  9. Add cronjob to server #2 to have it sync, use to figure out time
    • DO NOT add job in Scheduler in Laravel Forge, you will be required to input a password for sudo
    • Run sudo crontab -e
    • Add to the end of crontab * * * * * sudo rsync -avzhe "ssh -i /home/forge/.ssh/<key_name_from_step_2>" forge@<server_1_ip_address>:<directory_from_server_1_to_sync> <server_2_directory_to_sync_into>

Setting up Load balancing with Cloudflare

  1. Select the domain in Websites section in Cloudflare
  2. On the left go to Traffic -> Load Balancing
  3. Select Manage Pools to create a new pool
  4. Creating new Pool
    • Create origins (get ips from both servers created from forge)
  5. Create Load Balancer
    • Choose subdomain (it will create a loadbalancer subdomain in DNS)
    • Select pool
    • Attach pool monitor
    • Traffic steering OFF
    • No custom rules
  6. On the left go to SSL/TSL -> Origin Server
  7. Create certificate
    • RSA (2048)
    • hostname, put the subdomain used for the loadbalancer
    • 15 years is fine
  8. Copy the private key and certificate (Both servers will use them)
  9. Go back to Laravel Forge and install (Existing) SSL for both servers using private key and certificate created in step 7-8

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesnโ€™t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.