Forcing access to Discourse via domain name only

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 ^$request_uri permanent;
if ($host != "") {
	rewrite ^$request_uri permanent;

Any suggestions ?


Still haven’t find a simple way to do it.

If anyone has a solution I’d be grateful :slightly_smiling_face:

It sounds like your question is something like:

host:port at
domain 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?

Really sorry I didn’t make myself clear.

Let say my website is hosted on the ip:
And this is my domain name:

Right now, visitors can browse the forum by accessing the ip

What I want is:

When someone goes to the ip, it will be redirect to

The issue is that I am not able to locate ngnix default file.

Enable https. Run disourse-setup again and give your email address for the let’s encrypt question.