Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Technical Support
  3. Cloudflare Caching

Cloudflare Caching

Scheduled Pinned Locked Moved Technical Support
9 Posts 3 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C This user is from outside of this forum
    C This user is from outside of this forum
    chartung
    wrote on last edited by
    #1

    To minimize load on our servers, I would like to set Cloudflare to cache as much of the content as possible.
    I'm assuming that any image files or anything with a css/js/json file extension is safe to cache.
    Obviously we can't cache html content for logged-in users, since there is user-specific data included in the headers.
    As far as I can tell, it should be safe to cache html content for guests as long as the TTL is short (guests cannot post on our site, if that's relevant). However, it's not clear how we can implement that. The express.sid cookie is set for guests, so we can't just cache when that cookie is absent. It should be possible to set a custom cookie on login and clear that cookie on logout, but I can't find anywhere to set that cookie. I'm using a fork of https://github.com/julianlam/nodebb-plugin-sso-oauth, and the only place I can find a res object is https://github.com/julianlam/nodebb-plugin-sso-oauth/blob/master/library.js#L124, but setting the cookie fails because res.cookie is undefined.

    Is there any way I can set a custom cookie on login, or ensure that NodeBB does not set an express.sid cookie for guests?

    julianJ Dave JensenD 4 Replies Last reply
    0
    • C chartung

      To minimize load on our servers, I would like to set Cloudflare to cache as much of the content as possible.
      I'm assuming that any image files or anything with a css/js/json file extension is safe to cache.
      Obviously we can't cache html content for logged-in users, since there is user-specific data included in the headers.
      As far as I can tell, it should be safe to cache html content for guests as long as the TTL is short (guests cannot post on our site, if that's relevant). However, it's not clear how we can implement that. The express.sid cookie is set for guests, so we can't just cache when that cookie is absent. It should be possible to set a custom cookie on login and clear that cookie on logout, but I can't find anywhere to set that cookie. I'm using a fork of https://github.com/julianlam/nodebb-plugin-sso-oauth, and the only place I can find a res object is https://github.com/julianlam/nodebb-plugin-sso-oauth/blob/master/library.js#L124, but setting the cookie fails because res.cookie is undefined.

      Is there any way I can set a custom cookie on login, or ensure that NodeBB does not set an express.sid cookie for guests?

      julianJ This user is from outside of this forum
      julianJ This user is from outside of this forum
      julian
      wrote on last edited by
      #2

      @chartung can CloudFlare just cache by respecting the cache control headers? That'd be the easiest and I'd be surprised if it could not.

      julianJ C 2 Replies Last reply
      0
      • julianJ julian

        @chartung can CloudFlare just cache by respecting the cache control headers? That'd be the easiest and I'd be surprised if it could not.

        julianJ This user is from outside of this forum
        julianJ This user is from outside of this forum
        julian
        wrote on last edited by
        #3

        @chartung you can also check out the scaling tips here:

        https://docs.nodebb.org/configuring/scaling/

        1 Reply Last reply
        0
        • julianJ julian

          @chartung can CloudFlare just cache by respecting the cache control headers? That'd be the easiest and I'd be surprised if it could not.

          C This user is from outside of this forum
          C This user is from outside of this forum
          chartung
          wrote on last edited by
          #4

          @julian No, Cloudflare can use the cache-control response header to determine how long to cache content, but not whether to cache content.
          Even if it was possible to cache based on response headers, it wouldn't be useful in this case; we want to ensure both that we're not serving user-specific content to guests (or other users) and that we're not serving guest-specific content to users, and the cache-control headers can only help with the former, not the latter.

          1 Reply Last reply
          0
          • C chartung

            To minimize load on our servers, I would like to set Cloudflare to cache as much of the content as possible.
            I'm assuming that any image files or anything with a css/js/json file extension is safe to cache.
            Obviously we can't cache html content for logged-in users, since there is user-specific data included in the headers.
            As far as I can tell, it should be safe to cache html content for guests as long as the TTL is short (guests cannot post on our site, if that's relevant). However, it's not clear how we can implement that. The express.sid cookie is set for guests, so we can't just cache when that cookie is absent. It should be possible to set a custom cookie on login and clear that cookie on logout, but I can't find anywhere to set that cookie. I'm using a fork of https://github.com/julianlam/nodebb-plugin-sso-oauth, and the only place I can find a res object is https://github.com/julianlam/nodebb-plugin-sso-oauth/blob/master/library.js#L124, but setting the cookie fails because res.cookie is undefined.

            Is there any way I can set a custom cookie on login, or ensure that NodeBB does not set an express.sid cookie for guests?

            Dave JensenD This user is from outside of this forum
            Dave JensenD This user is from outside of this forum
            Dave Jensen
            wrote on last edited by
            #5

            I had to enable Cloudflare to cut out a massive flood of Chinese bots/crawlers. I have to Pro plan so websockets should be supported but I get nothing but errors now:

            nodebb.min.js?v=qg59f2a0n14:70  POST https://www.axisandallies.org/forums/socket.io/?_csrf=556...a5a&EIO=4&transport=polling&t=PiQDHrJ&sid=AyNfwAoKNwtqarQqAP63 400 (Bad Request)
            

            I have a rule for everything under /forums to bypass the cache.

            1 Reply Last reply
            0
            • C chartung

              To minimize load on our servers, I would like to set Cloudflare to cache as much of the content as possible.
              I'm assuming that any image files or anything with a css/js/json file extension is safe to cache.
              Obviously we can't cache html content for logged-in users, since there is user-specific data included in the headers.
              As far as I can tell, it should be safe to cache html content for guests as long as the TTL is short (guests cannot post on our site, if that's relevant). However, it's not clear how we can implement that. The express.sid cookie is set for guests, so we can't just cache when that cookie is absent. It should be possible to set a custom cookie on login and clear that cookie on logout, but I can't find anywhere to set that cookie. I'm using a fork of https://github.com/julianlam/nodebb-plugin-sso-oauth, and the only place I can find a res object is https://github.com/julianlam/nodebb-plugin-sso-oauth/blob/master/library.js#L124, but setting the cookie fails because res.cookie is undefined.

              Is there any way I can set a custom cookie on login, or ensure that NodeBB does not set an express.sid cookie for guests?

              Dave JensenD This user is from outside of this forum
              Dave JensenD This user is from outside of this forum
              Dave Jensen
              wrote on last edited by
              #6

              If I turn off Cloudflare proxy, the problem stops. Also, my setup is like this:

              internet -> Cloudflare -> HAProxy —vpc-> NodeBB servers

              I'm wondering if I need to configure something between Cloudflare and the proxy?

              julianJ 1 Reply Last reply
              0
              • Dave JensenD Dave Jensen

                If I turn off Cloudflare proxy, the problem stops. Also, my setup is like this:

                internet -> Cloudflare -> HAProxy —vpc-> NodeBB servers

                I'm wondering if I need to configure something between Cloudflare and the proxy?

                julianJ This user is from outside of this forum
                julianJ This user is from outside of this forum
                julian
                wrote on last edited by
                #7

                @djensen47 what CF SSL settings are you working with? I think when CF terminates your SSL WS could go wonky... We use CF and web sockets work okay.

                1 Reply Last reply
                0
                • C chartung

                  To minimize load on our servers, I would like to set Cloudflare to cache as much of the content as possible.
                  I'm assuming that any image files or anything with a css/js/json file extension is safe to cache.
                  Obviously we can't cache html content for logged-in users, since there is user-specific data included in the headers.
                  As far as I can tell, it should be safe to cache html content for guests as long as the TTL is short (guests cannot post on our site, if that's relevant). However, it's not clear how we can implement that. The express.sid cookie is set for guests, so we can't just cache when that cookie is absent. It should be possible to set a custom cookie on login and clear that cookie on logout, but I can't find anywhere to set that cookie. I'm using a fork of https://github.com/julianlam/nodebb-plugin-sso-oauth, and the only place I can find a res object is https://github.com/julianlam/nodebb-plugin-sso-oauth/blob/master/library.js#L124, but setting the cookie fails because res.cookie is undefined.

                  Is there any way I can set a custom cookie on login, or ensure that NodeBB does not set an express.sid cookie for guests?

                  Dave JensenD This user is from outside of this forum
                  Dave JensenD This user is from outside of this forum
                  Dave Jensen
                  wrote on last edited by
                  #8

                  > @chartung said:
                  >
                  > Is there any way I can set a custom cookie on login, or ensure that NodeBB does not set an express.sid cookie for guests?

                  I'd like to get back to this question. Bots are hammering my site and CF Super Bot Fight mode isn't picking up new bots for me. I don't want to enable "Under Attack Mode" forever — it's not recommended.

                  One solution is to serve up cached items to the bots from CF but I don't want to be overly aggressive caching for users.

                  julianJ 1 Reply Last reply
                  0
                  • Dave JensenD Dave Jensen

                    > @chartung said:
                    >
                    > Is there any way I can set a custom cookie on login, or ensure that NodeBB does not set an express.sid cookie for guests?

                    I'd like to get back to this question. Bots are hammering my site and CF Super Bot Fight mode isn't picking up new bots for me. I don't want to enable "Under Attack Mode" forever — it's not recommended.

                    One solution is to serve up cached items to the bots from CF but I don't want to be overly aggressive caching for users.

                    julianJ This user is from outside of this forum
                    julianJ This user is from outside of this forum
                    julian
                    wrote on last edited by
                    #9

                    @djensen47 have you tried using Anubis? It's the only thing that worked, and has carveouts for search index crawlers.

                    1 Reply Last reply
                    0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    Powered by NodeBB Contributors
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups