Cloudflare Load Balancing with Laravel Forge SFTP File Only Servers
Bryan
2 min read
Assumptions
- Using Laravel Forge to setup servers
- Syncing folder(s) between Server 1 and Server 2
- 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
- Setup 2 servers
- Do not delete the
default
site, deleting it did not work with load balancing for some reason
- Do not delete the
- SSH into server #2
- Create SSH key in server #2 and choose to save the key into
/home/forge/.ssh/
- Copy the contents of the newly generated key with
cat/home/forge/.ssh/<key_name_from_step_2>.pub
- Add the key to server #1 in Laravel Forge SSH Keys
- Create the main folder in server #1 and #2 that you want to be synced between them
- Add a test file to server #1 folder for test syncing
- 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
- Add cronjob to server #2 to have it sync, use crontab.guru 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>
- DO NOT add job in Scheduler in Laravel Forge, you will be required to input a password for
Setting up Load balancing with Cloudflare
- Select the domain in Websites section in Cloudflare
- On the left go to Traffic -> Load Balancing
- Select Manage Pools to create a new pool
- Creating new Pool
- Create origins (get ips from both servers created from forge)
- Create Load Balancer
- Choose subdomain (it will create a loadbalancer subdomain in DNS)
- Select pool
- Attach pool monitor
- Traffic steering OFF
- No custom rules
- On the left go to SSL/TSL -> Origin Server
- Create certificate
- RSA (2048)
- hostname, put the subdomain used for the loadbalancer
- 15 years is fine
- Copy the private key and certificate (Both servers will use them)
- Go back to Laravel Forge and install (Existing) SSL for both servers using private key and certificate created in step 7-8
0
Subscribe to my newsletter
Read articles from Bryan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by