Tony Pitale

Merb and Subdomains with Nginx

I encountered two issues and learned two quick lessons when deploying a Merb application I have been working on. Aside from the fact that you can use request.subdomains to get an array of subdomains, you must do two little things to get this to play nice when your application is deployed upstream on Nginx (and likely apache, too) as well as handling the same situation in local development.

First, in your Nginx configuration file be sure to set the proper header for host, otherwise the host that Merb will see is the name you give to the upstream section of your configuration. To pass this information on correctly, do this: proxy_set_header Host $host; inside the "location" block for your application's root.

Second, in order to get the right subdomains, Merb expects you are using a TLD or top-level-domain, such as If you, like me, are using a local hostname, such as localhost, you aren't going to get anything when you ask for subdomains. So, in /etc/hosts I simply set up a domain pointing to for a place I know I'll never go.

I hope these two little tips will help you to avoid some of the trouble I had to deal with, even if it was only 5 minutes of my time, or yours.

Read More Recent Posts