Discourse use double nginx error : Could not find module `handlebars` imported from `discourse-common/lib/raw-handlebars`

AI-generated summary

LeBlanc is running Discourse v2.9 with a custom double-nginx setup proxying two web_only containers on separate machines to avoid crashes from high connection loads. However, they intermittently encounter a client-side error: “Could not find module handlebars imported from discourse-common/lib/raw-handlebars”, resulting in blank pages — but only when traffic is load-balanced across both containers. The error disappears when routing all traffic to a single container, even though both run the same image. pfaffman finds this behavior perplexing and suggests the setup adds unnecessary complexity unless for zero-downtime upgrades. They also help resolve an issue with incorrect client IP logging by recommending set_real_ip_from and real_ip_header directives in web_only.yml LeBlanc confirms this fix works. pfaffman advises upgrading Discourse, as v2.9 is outdated and likely contains unresolved bugs and security issues. LeBlanc reports the error persists in safe mode and plans to test upgrading Discourse to resolve it.

Hi!
My website uses version 2.9 of discourse. For some reason, I had to use double nginx for discourse. I deployed two discourse web_only container nodes and used an nginx to proxy in front of them. My system architecture diagram:

I was confused when my custom nginx proxy two web_only container nodes and randomly distributed requests to any web_only node, my discourse website sometimes reported errors: Could not find module ‘handlebars’ imported from’ discurse-common /lib/raw-handlebars’, this time the browser visits the site blank screen. But when I used custom nginx to forward all requests to only one of the web_only nodes, this error does not occur. I searched for this problem, there were some commits before to solve this same error, I confirmed that my version contains those commit code.

Could not find module 'handlebars' imported from 'discourse-common/lib/raw-handlebars'

Broken instance after updating to 2.9.0.beta2 - #11 by david

Does anyone know why that is? Thanks very much

By the way, share a problem where using double nginx causes can’t get the real user IP address.
This is because my custom nginx enables X-Forwarded-For header field to get client IP address, but does not disenable X-Forwarded-For of discourse’s nginx. Causes the custom nginx X-Forwarded-For configuration to be overwritten by discourse’s nginx

And it doesn’t matter which one you use? And they are running the same image? That is perplexing.

The only advantage I can see to running two containers like that on the same host is to make it possible to do zero-downtime upgrades. Since you’re not upgrading very often, it seems that you’ve got unnecessary complexity.

You need sometihng like this in your web_only.yml:

after_bundle_exec:
  - replace:
    filename: /etc/nginx/conf.d/discourse.conf
    from: "types {"
    to: |
      set_real_ip_from 172.16.0.0/12;
      set_real_ip_from 10.0.0.0/8;
      real_ip_recursive on;
      real_ip_header X-Forwarded-For;
      types {

Thank you very much for your reply.

Yes, it doesn’t matter which one use. They are running the same web_only image. I will continue to look for problems using safe-mode and if there are any conclusions I will report back here.

Sorry for the misunderstanding in my system architecture diagram, I used a different machine to deploy web_only.The reason why I use double web_only is that my web_only container once crashed due to too many connections, but I did not find out the reason at that time. So I tried to use double web_only to avoid the same problem again.

Thanks,this helped me solve the problem of getting the real user ip

That makes sense.

There is a setting to increase the number of connections.

I would upgrade. There should be some issue on that version and I’m pretty sure that several security issues have been fixed since then.

Thanks. At present, I still get the same error when I try to debug in safe mode. I’ll be ready to try upgrading my discourse to see if it works.