jeudi 24 septembre 2015

Disable web access via direct IP address on AWS OpsWorks Nginx/Unicorn server

I have a Rails app running on an AWS OpsWorks Nginx/Unicorn Rails Layer. I want my app to only process requests to api.mydomain.com and have my web server directly return a 404 if any request is made using the server's IP address.

I've implemented a custom cookbook that overrides unicorn/templates/default/nginx_unicorn_web_app.erb (from the opsworks-cookbooks repo: http://ift.tt/1gbQgcB). I copied the template file that exists in this repository and added a new server block at the top of the template:

server { listen 80; server_name <%= @instance[:ip] %>; return 404; }

I stopped and started my server to ensure that the customized template file gets used, but when I issue a request using the server's IP address it still gets routed to my Rails app.

Is this <%= @instance[:ip] %> not correct? Is there a way to log from within this template file so that I can more easily debug what is going wrong? I tried using Chef::Log.info, but my message didn't seem to get logged.

Thanks!




Aucun commentaire:

Enregistrer un commentaire