Carlo wants to restrict access to their Discourse forum to only be accessible via the domain name (e.g., forum.example.com) and not through the IP address (e.g., 123.123.123.123). They are looking for a way to achieve this using Nginx, similar to how they would use .htaccess with Apache.
Carlo provided an example of the code they would use, but is unsure how to implement it in Discourse. Mittineague clarified the question, and Carlo confirmed that they want to redirect visitors who access the forum via the IP address to the domain name. pfaffman suggested enabling HTTPS and running discourse-setup again to resolve the issue.
Hi everyone. So I have setup Discourse and configure Cloudflare and SSL connection.
So far so good. Now I see my website is accessible via the domain name and the default ip, which I do not want.
When I use a CMS such as Wordpress or Modx ( on apache ), I normally configure the ht.access to do the trick. But Discourse is not on Apache…
Is there a way to do that with Nginx ? I am not even sure that Discourse uses it.
Anyway that is the code I would be using:
# Tells the browser to always force SSL.
# Do not use this line if there is a chance you will turn off SSL
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
if ($scheme != "https") {
rewrite ^ https://discourse.mydomain.com$request_uri permanent;
}
if ($host != "discourse.mydomain.com") {
rewrite ^ https://discourse.mydomain.com$request_uri permanent;
}
host:port at 123.123.123.123:8080
domain example.com maps to host:port
you don’t want requests for host:port to work, but only requests for the domain that are mapped to the host:port
But that doesn’t make sense to me and the code example you posted isn’t about that so I am confused.
What instructions did you follow for your install and is this a domain name, host IP, or port problem?