I can’t find a resource for this anywhere online, all I see is references for nginx.
I need help with this quickly as my server is live with users accessing it and somehow google indexed my ip address and users are accessing my site through my ip.
I plan to migrate servers tonight and am aware of why my ip was indexed, but in the meantime need a method to prevent direct access via my ip.
This obviously isn’t working, and don’t have much room to test, unless I stop the server and kick all of my users off for an extended period of time:
app.get('myiphere', function(req, res){
res.redirect('domain.com');
});
3
Answers
Prevent indexing by creating a
robots.txt
at your server root directory. See https://stackoverflow.com/a/390379/11191351You can implement an application-level middleware which checks that a request host-name isn’t anything else but your domain. That way an access to your with an IP address wouldn’t cause a processing (on application level).
To prevent direct access to your site from IP you can set the loopback IP this way: