Just throw it on CloudFlare hosting

Started by jesusbond, Oct 12, 2022, 07:38 AM

Previous topic - Next topic

jesusbondTopic starter

I have several websites with articles. There is traffic and even some money I earn from them. Just the case when "just throwing on web hosting" is no longer enough, and hiring a whole team of intelligent programmers is still expensive.
I write about traveling. Summer is the season. The sun is hot, people are going to the sea. And at the same time, data centers are warming up from the heat. I'm tired of "falling" for several hours every season.

And now I will explain what I did and why I needed it.
About me and my sites

There are no universal instructions that are suitable for absolutely everyone. What is good for a rarely changing website with articles is not suitable for an online store or SaaS. We need to throw a little context:

    I have pretty ordinary websites with articles on WordPress. No shopping cart, products, user profiles, forums, etc. Almost static.

    I only write about places that I know well myself. I flew to Georgia several times and climbed this country up and down. No copywriters.

    I wrote the theme myself from scratch so that my resources would be convenient, beautiful and fast. If it would be interesting to read about it, please let me know in the comments and I will try to write a separate detailed article.

    This is no longer just a hobby, but rather something in between business and self-employment.

    The total audience is about 250,000 views per month. This is about 500-t articles. As for the current times and the situation with tourism, it is quite decent. It used to be several times more.

    I'm not really a programmer, and certainly not a system administrator. But a little turned on the speed and stability of work. It's physically unpleasant when sites slow down or don't open at all.

It takes 2-3 hours a day to support and develop websites. Once it started more as a hobby, but now I'm trying to monetize. Otherwise, there is not enough motivation.

I earn money with the help of partner programs like TravelPayouts or Myrentacar. They allow you to get a percentage of the clients I have brought. The price for readers does not change. At first glance, it smacks of MMM or network marketing, but in fact everything is quite honest and mutually beneficial.

I recommend only personally verified companies in which I am confident. For example, now my parents are in Montenegro and I have booked tickets, accommodation, transfers and excursions for them on exactly the same sites that I recommend in my blog. Similarly, I sent my mother-in-law to Georgia. The main thing here is not to lie, because people immediately see the falsity.

In general, everything is very ambiguous with affiliate programs. In fact, thanks to them, prices for tourist services are falling, and more expert articles appear on the Internet instead of a stupid rewrite of $1 per 1000 characters from people who have never traveled. I'm serious.
Such is the paradox. If you are interested in how it all works from the inside, I can tell you in a separate article sometime. I'm not exactly an expert expert, but I've been stewing in this for a long time.
How did I build the infrastructure by trial and error?

Let's deal with my Frankenstein and why did it turn out that way?

If you just throw the site on hosting, the fall of hosting = complete unavailability of sites. Everyone falls. For a year, a few hours runs up at any hosting provider. It's good if it's just maintenance in winter and even in the middle of the night. It can be neglected. But half an hour-an hour of downtime in the summer at the height of the working day - is already very unpleasant. And from a financial point of view, and then the people complain.

But this is just the tip of the iceberg. Sometimes, for various reasons, quite decent web hosting services fall for several days. A couple of stories:

    I almost "got" with ihor, from whom I once foolishly rented a VPS. They had their own data center, backup communication channels, etc. But the owners quarreled and someone just pulled the switch. I "dumped" literally a week before all these events. How I felt.

    The valiant police simply seized a server from a well-known German provider on H, where one of my projects was stored, among other things. If I remember correctly, it only took a few weeks for the correspondence "what is it, where did everything go".

    At the data center of one good provider, the homeless decided to warm up. Isn't it a cool idea to set fire to a fiber optic cable in a barrel?

    Not so long ago, the OVH data center was on fire. It's bad weather in Germany now.

    Recently there was something with the power supply in Selectel. The sites were falling, then rising. Here the total downtime turned out to be about an hour or two, but problems were observed for three days.

I want the sites to continue to work more or less normally even when hosting is down. And so that this pleasure does not cost like an airplane wing. I'm telling you how I got out.

It's strange to start a conversation about web hosting and infrastructure with a domain. It would seem - well, what does he have to do with it? And here it is not!

It is advisable to buy domains for valuable sites from registrars. I never buy a domain in the same place where I host sites. It's cheaper this way, but if something happens with hosting, there will be huge problems. I will tell you on the example of ihor. I was just helping a colleague restore a project that she kept with them:

    Huge simple. She had backups. But what is the point of them if there is no access to the DNS records of the domain? The mirror can be deployed in half an hour, but it is not possible to direct traffic to it.

    Find out the registrar. The hosting site did not work, but the registrar can be found through Whois. Most web hosting companies are just engaged in reselling.

    Correspondence with the registrar. We wrote to a foreign registrar, explained the situation and proved for a long time that the domain is really ours and we really want to transfer it to any other company for maintenance. The most difficult thing was to explain to the Europeans that we could not "go to the place where we registered the domain."

    DNS replacement. As soon as we managed to win back the domain, we immediately changed the DNS addresses to the current ones. But the sites didn't work. It was necessary to wait a few more days until all providers updated the cache.

    Results. A simple 9 and a half days. Traffic was restored only after a year and a half. And then at the cost of incredible efforts. And there should have been growth.

In my version, if something happens to web hosting, it's enough just to change the DNS in CloudFlare and the sites will work after 15-20 seconds. Well, if CloudFlare itself falls, then a good third of the Internet will lie with them. Who will need my blazhiki at such a moment?

I have several sites and it would be inconvenient to switch everything by hand. Especially when you are sitting in a café and have only a smartphone at hand. Therefore, I made for myself a primitive utility that connects to them via the API and simply switches all DNS to backup with one button.

Their API is pretty clear. I've never worked with such things before, but I figured it out in about an hour. It was necessary to create tokens in the interface, and then everything is done with simple GET and PUT requests.

For example, using such a GET request, I find out which IP is currently registered in their DNS section:


It actually gives a lot of information, so you need to use json_decode and look for the desired value in the resulting array. Something like that:


And with such a PUT request, I set the IP I need:

$data_array =  '{"type":"A","name":"georgia.in-facts.info","content":"","proxied":true}';
$update_plan = callAPI ('PUT', 'https://api.cloudflare.com/client/v4/zones/a32543f1f18dc3ye8a4faa0c04c20eb95s/dns_records/ecfa543133b5655beb2abb8as2140a008d', $data_array);

In the examples above:

a365f1f18dc3ye8a4faa0c04c20eb95s is a Zone ID that can be obtained in the Cloudflare personal account. ecfa543133b3490beb2abb8as2140a008d is the identifier of a specific DNS record. It is obtained by the same GET request as the IP.

* Here and further, I replaced all passwords, logins, etc. with random ones.

I sketched out a very simple interface in a couple of minutes. Now I just need to open a special website, enter a password and click one button. Then the IP change automatically changes for all the sites I need.

It goes without saying that such a site should not be "hosted" on the main web server. Otherwise, in case of a fall, it will not open either.

Monitoring signals me about the fall of the main hosting. There are a lot of paid and free solutions for this now. I do not undertake to recommend what I have chosen for myself by the "poke method".

Why do I need CloudFlare?

It would seem that the benefits of CDN are obvious - sites will work faster. But in fact, if your main audience is from the CIS, then with good hosting in the  Netherlands, the time to load pages will be almost lower than when proxying through CloudFlare. At least, this is often observed in my particular case.

However, the service helped me out a lot when one of the sites started DDoS. I don't think it was a deliberate and planned attack. Most likely, I just became a random target of some botnet. But in the case of hosting, I would not be able to fight back in any way. I would just be turned off and that's it. And with the help of CloudFlare, it turned out to at least quickly block traffic from all non-target countries. This bought me time to find a more adequate solution.
Automatic Platform Optimization for WordPress

This is a new paid option in CloudFlare. They cache images and scripts for free. For $5 a month, you can adequately cache html, too. There are options for how to get the same result for free at all. But they are all a bit crutchy and do not work as stably as we would like.

I see two advantages of APO for myself:

Speed. Sites are starting to open much faster. Especially from countries "remote" from web hosting. I have translations of some articles into English. That is, traffic is also coming from overseas. After connecting, it became a little, but faster:

I would not pay attention to specific figures. Google Analytics quite strangely considers the loading speed of sites. I tested them even on a very slow mobile Internet in the mountains and everything opened adequately. But in analytics,  where hosting is located, the average value is about 4 seconds.

Stability. Since all data is downloaded directly from CloudFlare web  servers, then purely in theory, in the event of a hosting crash, users should not notice anything at all. In practice, everything will depend on the location of the user, his device and the requested page.

Relatively speaking:

    I have a lot of users in  Ukraine and Belarus. Therefore, almost all pages, pictures and scripts are in the cache. Sites are more or less loaded, but sometimes there are errors with pictures when a user requests a "rare" size on a not particularly popular page.

    In Europe, something is loaded, and something is not. Corny cache is "rotten" and CloudFlare has nothing to give.

    Nothing loads in Africa, since I have almost no users from there.

If you look closely at the diagram at the beginning of the article, you can see that 91% of the requested pages are immediately given from the cache and do not depend on web hosting performance in any way. The remaining 9% is the admin panel, which is not cached, comments, site search, recently updated articles and queries from "exotic" countries for me.
html caching

The lion's share of the time that passes from the user's request to web server's response is the work of php scripts. I have WordPress with a manually written, very fast theme. But I still use caching. I've tried a lot of plugins. Including the fashionable paid WP Rocket. But I stopped at the free WP Super Cache, since in expert mode it is able to give the cache using the rules in .htaccess and does not use php at all. It's faster.

The cache accounts for 8% of requests. Basically, it works out when a user from conditional Germany-Austria (I have few readers there) first requests a not particularly popular page and it simply does not exist on the CloudFlare server closest to him.

At one time, I decently "jumped" on different hosting and VPS. And I came to a very simple conclusion: from the point of view of an ordinary user, they are all the same.

The speed and stability of my projects specifically will depend more on the specific machine they will get on, the neighbors on it and the overselling than on the name of web hosting. Everyone uses the same approaches and equipment, plus or minus.
If you just need hosting

I would recommend Running for beginners. I have been using their services for more than 6 years. The support is adequate, the sites work more or less quickly. Pay 40% referral. Everything is standard, in general.

Of the unique advantages, I would note a really convenient control panel and the isolation of sites on the same account from each other. Few people have such a thing.

There are also disadvantages: my sites fall by about 2 hours a year. The other day I couldn't log in to the panel all day, because some work was being done. Prices are rising.

Links: Simple | Referral
Need a good hosting

I keep the most valuable projects on Lite.host. This is the brainchild of one person. I learned about it just And one in the field is a warrior. We then talked in the comments, the owner seemed adequate and I promised to place a small new website with him. And in the end, I transferred just the old and especially valuable ones. Let me tell you why:

High-class support. In most reviews, people measure the quality of support by the speed of response in the middle of the night. But it is important only for typical questions that I can usually solve myself. I appreciate more the quality of these very answers and the willingness of the sysadmin to really deal with the problem.

Empirically, it was possible to establish that this sometimes happens if the page was loaded using php. The error was not regular and occurred only with me. For a few hours everything is fine, then 2-3 pages with an error, then everything is fine again. Refreshing the page in the browser helped. If there are cool sysadmins here, please write in the comments how you would solve such a problem.

Most web hosting companies with such a problem would simply "send me", stating that the problem is on the side of CloudFlare or traffic routing. Evgeny and I have been periodically looking for the reason for more than a month. I clicked the checkboxes in the CloudFlare settings and tried to edit the scripts. He dug right down to the code of the servers.

It was only solved when I purely accidentally came up with how to increase the frequency of this problem from 1-2 per hour to loading every 4-5 pages. And here's the solution:

I'm not a particularly technically literate user. So I asked Evgeny to tell me about the decision. 522 the error occurred only with HTTP/2.0 requests from cloudflare.com if you make direct requests (without cloudflare.com , then there was no such error).
 When activating support for this version of the protocol from the DirectAdmin control panel, it configures it for both Nginx (fronted) and Apache (backend). Disabling HTTP/2.0 from Apache completely solved the problem. Where is the true problem (in cloudflare.com , Nginx or Apache) is still unclear, but the main thing is that a solution has been found.

I have not seen such a level of support anywhere else. Right before the Lighthost, I rented a VPS from AdminVPS. I took it just because people wrote about cool support in the reviews. In fact, their guys and I somehow didn't get along. The server often crashed. Half of the cases are my fault, half are theirs. But I left precisely because of the engineers' answers. Like: you can read the full restrictions in VPS on our website.
And look further for yourself where it is written and whether it is written at all. I haven't found this secret page in half an hour.

Transparency. There is such a thing: status.lite.host, where information about all failures, malfunctions and problems is published. If hosting or VPS crashes, you no longer need to guess: something has fallen off on my side, or it's still their jamb. You can immediately see what happened and when it will be fixed.

Favorable rates. I will not say that this is a cheap web hosting. But I switched to Eugene with a VPS. I tested and compared for a long time. It turned out that hosting cost 3 times cheaper, and the speed was about the same level.

Very fast hosting. Although Zhenya says that everyone uses similar equipment, I don't believe him. My sites open objectively faster. When I generated WebP images, the process was 3-4 times faster than on the Run.

A beautiful story. Who knows, but I really like to support small entrepreneurs who are trying to make cool products. This is psychologically more pleasant to me than paying a large corporation, in which ordinary people are no longer visible behind the regulations and scripts.

To be completely honest, one of the reasons why I decided to write this article was the desire to arrange a small "advertisement" for my Wife.

The cons follow from the pros. Since only one person is engaged in hosting, then bus factor = 1. Be sure to make backups and have a "hot" web reserve. Support is not always prompt. Since even Superman sometimes needs to sleep. Well, referral only 15%.

Links: Simple | Referral
Backup server

I have a minimal VPS on Digital Ocean in Amsterdam. I rent it primarily for VPN. But since I'm crying, I wanted to keep a mirror of my sites there. I used to set this up manually in about 3-4 days. And it even worked!

This time I decided to just pay Eugene something about $ 20 for a turnkey job. I am proud of myself: I have learned to delegate at least something.

Every night, files and the database of the most valuable sites are synchronized to a backup server using rsync. The database is automatically imported, so in fact a fully functional copy of my projects is spinning there. To switch to it, simply change the DNS in CloudFlare using the utility that I mentioned above.

Synchronization is performed by a simple bash script that runs every day early in the morning (during the period of minimal load).

Ideally, of course, it would be better to buy some kind of Load Balancer, and it's really good to set up master-master database replication as well, in order to constantly have an up-to-date copy. But, unfortunately, all this is not paying off for me yet.

A budget Load Balancer will cost at least $5 per month. This would pay off only if web hosting dropped by at least half an hour once a month. But we still need to look for such a low-quality service.

There is another problem with synchronization. I'm not sure I can set it up so that it will work stably for years without maintenance by a good administrator. Most likely, crashes due to configuration errors will occur almost more often than due to hosting failures.

Did I mention that my hosting has bus factor = 1? But in general, any company is not immune from problems. My data may be lost due to human error, equipment failure, fire or natural disaster. So that such a loss is not critical, I make backups in four places:

    Backups from web  hosting. Almost everyone offers them now. They are created automatically, they work. I tested them for "ghostliness".

    A "hot" backup on a remote web  server. The same thing I've already told you about.

    Backup on a laptop. Just about once a month I manually copy all the files and databases to my work laptop. My sites rarely change, so if anything, the losses will not be very critical. If I make a lot of edits, then I make a backup earlier.

    Backup on the hard disk. I also copy everything to an external HDD.

How to check if there is an effect?

I did not measure the stability of my sites in any way. So I can't say exactly how much such "crutches" have improved it. Subjectively, I avoided a couple of hours of downtime this summer. But there was just bad luck with force majeure in the Selectel data center. Usually hosting services do not fall for such a long time.

But the "speed of operation" of the sites would be interesting to compare. But there are difficulties here too. It is easy to measure the effect if, before the start of work, the site wildly slowed down and opened for 5-10 seconds. Then the banal connection of caching will easily give an acceleration of 1000%. Here it is - the main secret of many beautiful advertising articles.

It is much more difficult to make measurements if the site was working fast enough before the "acceleration". Even deploying two copies on different infrastructure and comparing them will not work, since the sites will be without load.

That's what I came up with:

    There are two sites that are "written" plus or minus the same. This is my georgia.in-facts.info and the site of colleagues montenegro-travel.info , where I helped to do only the design.

    The first site uses the infrastructure described above. The second one was simply "thrown" on the Run. The number of visitors is comparable.

    For the tests, I chose two pages without third-party scripts: no Google Maps inserts, advertising widgets, etc. Only pictures and text. This is done because any advertising widget "weighs" and affects the page loading speed more than everything else combined.

    Tested using gtmetrix.com , since I consider this service one of the best. Chrome browser is selected as the most popular among my visitors.

    I tested it in the afternoon, in prime time. Took the average of five runs.

The conclusion is simple. Yes, the crutches I've made really noticeably accelerate the speed of the sites. The effect will be more noticeable the longer the route from web hosting to the user.

I want to clarify that the spread of values turned out to be quite large. I don't know what this is related to. I specifically specified the site addresses so that you can test everything yourself.

It is curious that when trying to test the loading speed of a "rare" page from an unpopular location among my users, the first test georgia.in-facts.info it showed a result of 900-1600 milliseconds, and the second one was 3-4 times lower. It looks like APO really works.

If you know a more objective way to quickly compare the speed of two pages, tell me about it in the comments. Just please keep in mind that paid tools in this case will be a little superfluous.
And how should I have done it?

Remember, I said that I'm not really a programmer and certainly not a system administrator?
There is a feeling that the infrastructure I have built is far from optimal. Well, for some reason they don't write about how to set everything up correctly for projects like mine. Or "just upload to hosting" or clouds with Docker containers and a couple of engineers to support this whole zoo.



Everything was written correctly about dns, but the phrase "if cloudflare falls, then half the Internet will fall and no one will need my blocky" is fundamentally wrong from the point of view of a perfectionist.
Use Primary/Secondary dns for duplication! Normal dns hosting services providing this service are fully automated - the entire zone with all records is transferred from Primary to Secondary instantly and automatically.


For such a large load, I would suggest generating static pages from Wordpress, there was already an article about such generators somewhere. And put third-party comments.
Counters/ratings may well work in JavaScript and without a backend, I think.
Giving away a static html page quickly is unlikely to require large hosting resources.

About DNS, I can recommend trying the Zilore service https://zilore.com/dns (there is a free tariff), which monitors the site itself and, in case of unavailability, switches DNS to backup (see Failover IP, minimum TTL 600 like). I use it myself, as for me, it is quite conveniently done.


CloudFlare is "ahead of the whole planet" in such an important indicator of the quality of work as the percentage of errors when sending a file.
They have it at 7.2%, whereas all traditional CDNs have less than 1%. How can you comment on this?
www.cedexis.com/country-reports / (see the last graph). Isn't this the reason for the discontent of most commentators?