A user is struggling to configure Discourse behind an AWS Load Balancer with SSL, where the main domain (capitool.com.br) redirects to www.capitool.com.br but fails to enforce HTTPS. The user attempts to modify the nginx configuration using web.ssl.template.yml and X-Forwarded-Proto headers, but encounters redirect loops and a ‘Welcome to Nginx’ page. Other users discuss the issue, noting that Discourse does not natively support X-Forwarded-Proto for HTTPS redirection, and that the problem lies in the nginx configuration and proxy setup. sam confirms that HTTPS can be handled solely by the load balancer, with Discourse running on HTTP, but the redirection must be correctly configured in the Discourse container’s nginx config. Anil_Gupta and others explore solutions, including using if ($http_x_forwarded_proto != "https") in the nginx config, but the correct placement and method remain unclear. The discussion also touches on the complexity of scaling Discourse on AWS and whether a single Digital Ocean droplet suffices for most use cases. Tango expresses interest in a high-availability setup without hosted solutions, while codinghorror suggests that for most users, a single droplet is sufficient and avoids unnecessary complexity.
I am using a AWS Load Balancer with an Amazon Issued Certificate, I cannot download it on my ec2 instance. When i access my forum by https://www.capitool.com.br it works fine, but when accessing by capitool.com.br , as the default is http, not working.
On Route 53 i have an ALIAS from capitool.com.br to www.capitool.com.br. So when you try to access capitool.com.br Route 53 point to www.capitol.com.br.
So i create a copy of web.ssl.template.yml and replace all content by:
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /server.+{/
to: |
server {
listen 80;
return 301 https://$$ENV_DISCOURSE_HOSTNAME$request_uri;
}
server {
But i received a Too Many Request error. I tried also:
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /server.+{/
to: |
server {
listen 80;
server_name forum.com.br www.forum.com.br;
rewrite ^/(.*) https://$$ENV_DISCOURSE_HOSTNAME$request_uri permanent;
}
server {
Does meta.discourse run on http behind the AWS ELB (using https)?
Or both Amazon ELB and discourse server are having HTTPS?
The question is to have https config ONLY at Load balance server level. The discourse install should be only using HTTP and still should be able to REWRITE/REDIRECT to https version.
Ya.. but, how does the redirection work at the discourse server level then?
There has to be some redirection rule at discourse set up. In my case, google load balance server does not handle the redirection.
Google recommends that this rule should be added to the discourse’s web server:
server {
listen 80;
server_name www.example.org;
if ($http_x_forwarded_proto != "https") {
rewrite ^(.*)$ https://$server_name$REQUEST_URI permanent;
}
}
The question is where should we add this rule?
I have tried adding it in app.yml (inside after_web_config hook) but, it does not work.
It starts showing the ‘Welcome to Nginx’ screen after adding the above rule.
Do you have any suggestions as to how this rule can be configured in Discourse set up?
enter container, mess with nginx config file inside container, run sv restart nginx to have it take effect. Continue messing with nginx conf until you have something that works.
Only after that would you add it to the bootstrap process.
A complete guide on this would be fantastic. There seems to be bits & pieces (plenty of interest) around this topic of deploying on AWS in a HA environment with ELB.
I acknowledge that such a document would compete against hosted options.
Very extremely unlikely we are going to publish any guidelines on “this is how you build a super mega enterprise Discourse setup” for a book full of reasons.
If the community want to share knowledge be our guests
Unless you are doing at least 20 million pageviews per month – and please do correct me if you are – you can trivially achieve “not going to wake me up” and “scales” just fine on a single Digital Ocean droplet.
Otherwise you have decided to opt yourself into pain. Which is entirely your perogative, if that’s what you want.