EDIT There is an updated version available which does not setup nginx as a system service. Instead HAProxy is used to allow a proper WebSocket setup. If you like to follow along just setup named properly.
Pow is a nice Rack server. You can’t work with it while offline but that didn’t bother me much. Then it started randomly crashing on me & using 99% of my CPU. That’s when I started testing alternative setups to get rid of pow.
A basic, alternative setup should
- closely resemble my production setup
- better serve the needs of a web-app with multiple dependencies, e.g. resque, faye
- gracefully handle errors
- work well with co-workers still using pow
Since I don’t like to change my /etc/hosts
file I need some sort of dynamic DNS resolution.
Also using unicorn & nginx seemed like a good choice because I’m always using them in production.
Here’s the basic setup I’m using right now:
- use
bind
for DNS resolution nginx
as reverse proxyforeman
to startup all necessary services
Instead of bind
, dnsmasq
should work as well.
To setup bind
& nginx
I followed this guide, with some small changes.
You should read it now, since I’m not going to repeat the steps listed in the guide. I’m only going to show changes in configuration.
Also note that all I did was install nginx
& bind
. Nothing more.
changes to bind
configuration
I like .dev
as my development TLD, so I changed the configuration to use it instead of ld
.
# /etc/named.conf
zone "dev" IN {
type master;
file "dev.zone";
};
# /var/named/dev.zone
dev. 7200 IN SOA dev. root.dev. (
2008031801 ; Serial
15 ; Refresh every 15 minutes
3600 ; Retry every hour
3000000 ; Expire after a month+
86400 ) ; Minimum ttl of 1 day
IN NS dev.
IN MX 10 dev.
IN A 127.0.0.1
*.dev. IN A 127.0.0.1
# /etc/resolver/dev
nameserver 127.0.0.1
changes to nginx
homebrew configuration
After removing plenty of stuff, this is my nginx.conf
:
# /usr/local/etc/nginx/nginx.conf
worker_processes 1;
error_log /usr/local/Cellar/nginx/logs/error.log debug;
#pid logs/nginx.pid;
events {
worker_connections 128;
}
http {
include mime.types;
access_log /usr/local/Cellar/nginx/logs/access.log combined;
sendfile on;
keepalive_timeout 65;
include /usr/local/etc/nginx/sites-enabled/*;
}
Now whenever I deploy a new site for local development I place my nginx
configuration at
/usr/local/etc/nginx/sites-enabled
changes to my workflow
Before coding on a project I cd
into the application directory and run foreman start
to get my application and all of it’s dependencies up and running.
Only after I’ve done that I can start working. As soon as I’m done I stop foreman. That’s it.
This setup requires more work than I had running pow, but moving from development to production is much easier now since most of the configuration is already done on my local machine. To me this seems to be a good replacement for pow. At least for now.