aws / opsworks-cookbooks

Chef Cookbooks for the AWS OpsWorks Service
Other
1.05k stars 1.23k forks source link

Disable web access via direct IP address (Rails nginx/unicorn) #333

Open kalpitad opened 9 years ago

kalpitad commented 9 years ago

I want my app server to only process requests to api.mydomain.com and return a 404 if any request is made using the server's IP address.

My stack is Rails on nginx/unicorn and I've implemented a custom cookbook that overrides unicorn/templates/default/nginx_unicorn_web_app.erb. I copied the template file that exists in this repository and added the following 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!