The discussion addresses how to prevent direct IP access to a self-hosted Discourse instance, returning an error instead of the site content. doudou asks how to configure Nginx to return a 500 error for direct IP visits, inquiring if modifying nginx/conf.d/discourse.conf within the Docker container is permanent. sam suggests using the SSL template to demonstrate how to create a Pups replacement rule that amends the Nginx configuration. doudou follows up, asking for the specific location of the template within the Docker container and noting that manually adding a return 500 rule blocks both domain and IP access. Lee_Ars questions the choice of a 500 error over a 403 Forbidden and recommends handling blocking at the firewall or via iptables to avoid interfering with Discourse’s core configuration. However, sam clarifies that iptables cannot parse the Host header required to distinguish between domain and IP requests. Lee_Ars jokingly responds to this limitation.
Why do you want to return a 500 error and not a 403 forbidden?
If you control the firewall this server is behind, dropping the offending IP address there might be easier. Or, you could use iptables on the server itself and drop the IP addresses there without having to bother with Discourse’s configuration—just add a rule onto the input chain, substituting the address or CIDR range you want to block in place of “1.2.3.4”:
iptables -A INPUT -s 1.2.3.4 -j DROP
IMO, if you’re not going to use Discourse’s built-in IP address blacklisting, it’s better to do this kind of thing outside of the Discourse docker container. You get more control and you don’t have to screw with the base DIscourse configuration in ways that might conflict with the DIscourse team’s future developments.