So I’m just lazy, I know there is better way to serve Ruby on Rails with unicorn or uWSGI, but I will try later.
This time I just want a have a quick look how’s the RoR running on the browser only with nginx, just a quick guide, no bullshit. so currently I have rails installed on my ubuntu machine 14.04 with mysql database configured and nginx. So make sure you have those things installed properly to follow this guide.
I usually create my local domain first to navigate it easier:
$ sudo echo -e "127.0.0.1\tmyapp.local" >> /etc/hosts
Create the nginx config for your web app :
$ sudo vim /etc/nginx/conf.d/myapp.conf
very simple myapp.conf looks like:
server { listen 80; server_name www.myapp.local myapp.local; charset utf-8; access_log /var/log/nginx/myapp.access.log; error_log /var/log/nginx/myapp.error.log; location / { proxy_pass http://127.0.0.1:3000; } }
Check nginx config and restart
$ sudo nginx -t $ sudo service nginx restart
Run the rails (I told you, I’m just lazy) :
$ cd /myapp $ rails server &
And now, Rails is running with port 3000 which nginx already addressed to myapp.local domain. Open up the browser and navigate to http://myapp.local