First of all, install nginx from Slackbuild.
Be sure to turn off Apache’s startup script if you have it installed:
chmod -x /etc/rc.d/rc.httpd
This is to ensure no conflict since both of them by default will use port 80.
unicorn in your Gemfile and run
I’m putting my Rails app in
/opt/neuro, so, adjust it accordingly.
/etc/nginx/nginx.conf with this content:
sites-enabled directory in
/etc/nginx and create a softlink to the
nginx.conf in our app:
$ mkdir /etc/nginx/sites-enabled $ ln -s /opt/neuro/config/nginx.conf neuro.conf
Create a directory for the pid
$ mkdir /opt/neuro/tmp/pids
Before starting it for the first time, let us monitor important logs (open it using different terminals) :
$ tail -f /var/log/nginx/error.log $ tail -f /opt/neuro/log/unicorn.log
Make sure you’ve precompiled your assets:
$ rake assets:clean $ rake assets:precompile
$ cd /opt/neuro $ unicorn -c config/unicorn.rb -E production -D
Congratulation! Make sure there’s no error in your logs. If there’re, you can use these commands to
unicorn to start everything back:
$ nginx -s stop $ killall unicorn
Let’s test the gzip compression using
$ curl -LI --compressed http://neuro.husmnet/
You’ll get something like this (notice the gzip info):
HTTP/1.1 200 OK Server: nginx/1.2.2 Date: Sat, 05 Jan 2013 21:00:26 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Status: 200 OK X-UA-Compatible: IE=Edge,chrome=1 ETag: "a66ac1d43d8f07ecc0737e64dd8a3366" Cache-Control: max-age=0, private, must-revalidate Set-Cookie: _neuro_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTQ2YTU2NjE3MDY0Y2RkNzk0Yzk3ODhhNDJlYmQ3ODA3BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMVNvOXVTS2I2RXJIcTljbS9WeGRDODZyTUpVZENXL2NPVnJhTGR0V2xydGM9BjsARg%3D%3D--173e9d56a5cc434eb675b6626d90aced1cc17cd6; path=/; HttpOnly X-Request-Id: 760e233de4980dc75169f2c68a53dc31 X-Runtime: 0.017885 X-Rack-Cache: miss Content-Encoding: gzip
I admit, this is a very simple config, but it’s good enough for a beginner like me to get started. So, good luck!
Written by Amree Zaid