After relocating all my web apps on DigitalOcean, I’ve discovered the performances of Nginx joined with Passenger standalone.
Nginx is a very fast and slim web server that could serve a lot of requests with agility. It is possible to use Nginx with a stand alone Passenger using a reverse proxy.
We know that:
- Phusion Passenger Standalone also supports listening on a Unix domain socket instead of a TCP socket. Unix domain sockets are significantly faster than TCP sockets.
- Nginx supports reverse proxying to Unix domain sockets;
So with this nginx configuration, we could join together Nginx and Passenger through socket:
upstream olm_upstream { server unix:/tmp/openlastminute.it.socket; } server { listen 80; root /var/www/vhosts/olm.it/current; server_name olm.it; location / { proxy_pass http://olm_upstream; proxy_set_header Host $host; } }
However, I’m using capistrano and start/stop socketed Passenger doen’t work by simply touch tmp/restart.txt.
So I’ve produced a capistrano recipe that perform a Passenger restart by stopping the old process and by starting a new one.
Here is the recipe:
Capistrano::Configuration.instance.load do after "deploy:update", "passenger:stop", "passenger:start" namespace :passenger do task :start, :roles => :app, :except => { :no_release => true } do run "cd #{current_path} && bundle exec passenger start --socket /tmp/#{application}.socket --daemonize --environment production --nginx-version 1.1.19" end task :stop, :roles => :app, :except => { :no_release => true } do run "cd #{current_path} && bundle exec passenger stop --pid-file #{current_path}/tmp/pids/passenger.pid" end end end
You’ve to customize your nginx version included in the recipe. Have a good deploy!