Fixing Errors 521 and 525! (Tutorial)

Hello,

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

Ok,

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.

Okay,

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’);

require("@utils/passport.js");

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

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

/ * Middleware Functions */;
this.express.use(cookieParser());
this.express.use(express.static(__dirname + "/../public"));
this.express.use(
  session({
    secret:
      "F577259F38FD820133AE0BE1FB5ED76ABFC26BAC899805AF7A4FA99D4B9580DF",
    resave: false,
    saveUninitialized: false,
  })
);
this.express.use(passport.initialize());
this.express.use(passport.session());

this.loadRoutes().loadErrorHandler();

}

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

  const httpsServer = https.createServer(options, this.express).listen(433)

}

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 {
    this.express.use(routePath, route);
  } catch (error) {
    console.error(`Error occured with the route "${filename}"\n\n${error}`);
  }
});

return this;

}

loadErrorHandler() {
this.express.use((req, res) => {
res.status(404);

  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.