Fixing Errors 521 and 525! (Tutorial)


how do i use apache with expressJS? Apparently i need to use apache for cloudflare to work.

so yeah. Please help me. I don’t have any experince of apache2 and just downlaoaded it.

Please give full tutorial on configuratiing in plz.

You really don’t. You just need a working HTTPS website for Cloudflare to work.

Then pls help me with error 521 my things running on port 443

A 521 error happens when Cloudflare is unable to make a TCP connection to your origin server. Review the suggestions in this Community Tip for Quick Fix Ideas.

1 Like

If you have just moved to Cloudflare and you are seeing a 521 over HTTPS, it is possible that your origin server has not been configured to allow port 443 be accessed by Cloudflare IPs. In this case you should configure your server/firewall to being listening on port 443 and allow us to be able to conect. If this is not possible, you can move to using ‘Flexible’ SSL under the SSL/TLS app on the dashboard

How do I do this, I just moved to cloudfare and I’m using expressJS to host

I’m already on port 443


So now heres the problem

Error 525

A 525 error is typically caused by a configuration issue in the origin web server when its SSL certificate is not properly set up. Review the suggestions in this Community Tip for advice & insight.


installed the thing correctly now.

But the https server is not listening, so im backing on the 521 error. heres my code:

const path = require(“path”);
const express = require(“express”);
const cookieParser = require(“cookie-parser”);
const session = require(“express-session”);
const https = require(‘https’);
const fs = require(‘fs’);
const passport = require(“passport”);
let privateKey = fs.readFileSync(’/root/src/privatekey.pem’);
let certificate = fs.readFileSync(’/root/src/certificate.pem’);


const getFilesSync = require("@utils/fileWalk");

class App {
constructor(client, locals = {}) { = express();“views”, “src/dynamic”);“view engine”, “pug”);“client”, client); = locals;

/ * Middleware Functions */;; + "/../public"));
    resave: false,
    saveUninitialized: false,



listen(port) {
let options = {
cert: certificate,
key: privateKey

  const httpsServer = https.createServer(options,


loadRoutes() {
const routesPath = path.join(__dirname, “…/routes”);
const routes = getFilesSync(routesPath);

if (!routes.length) return this;

routes.forEach((filename) => {
  const route = require(path.join(routesPath, filename));

  const routePath =
    filename === "index.js" ? "/" : `/${filename.slice(0, -3)}`;

  try {, route);
  } catch (error) {
    console.error(`Error occured with the route "${filename}"\n\n${error}`);

return this;


loadErrorHandler() {, res) => {

  if (req.accepts("html")) return res.render("404");

  if (req.accepts("json"))
    return res.send({
      status: 404,
      error: "Not found",

  res.type("txt").send("404 - Not found");

return this;


module.exports = App;

Nevermind wrong port!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.