Skip to content

Instantly share code, notes, and snippets.

@kalpesh-fulpagare
Last active December 17, 2015 19:48
Show Gist options
  • Save kalpesh-fulpagare/5662579 to your computer and use it in GitHub Desktop.
Save kalpesh-fulpagare/5662579 to your computer and use it in GitHub Desktop.
Deploying RoR app with nginx server on local machine
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#install_on_debian_ubuntu
Instruction for Ubuntu 12.X (should work on 11.x also)
a. Installing passenger gem
$ gem install passenger
b. Installing passenger-nginx module(It will compile and install Nginx with Passenger support)
IF ruby is installed without RVM
$ sudo passenger-install-nginx-module
ELSE IF RVM is used to install/manage Ruby
$ rvmsudo passenger-install-nginx-module
Q. Where do you want to install Nginx to?
Press enter, it will install nginx server in default directly i.e.
/opt/nginx
It will install nginx in opt/nginx directory, but you will not be able to start the server,
you need bash script that allow you to manage nginx
c. Installing startup script for nginx server
wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults
Now Start nginx server with command
$ sudo service nginx start
It will start nginx server on 80 port,
from browser go to http://localhost, if it displays
'Welcome to nginx!', then nginx is properly installed.
However if you already have other server(e.g. apache) running on same port i.e. 80
nginx will not start and it wil throw bind error for port 80, so in this case you need to change default port no for either that other server(e.g. apache) or for nginx server. Port no for nginx can be changed from its configuration file
Steps:
$ sudo vim /opt/nginx/conf/nginx.conf
Edit port no, change from 80 to some other port no say 90, save file and restart nginx server with command
$ sudo service nginx stop
$ sudo service nginx start
Now open browser and go to URL
http://localhost:90
It should display 'Welcome to nginx!' and that's it, you have successfully installed nginx server
Adding rails application details to nginx config file
e.g. Your ruby on rails app path is /home/kalpesh/projects/demo_app
Default nginx config file path: /opt/nginx/conf/nginx.conf
Edit server part to add your app details
$ sudo vim /opt/nginx/conf/nginx.conf
server {
listen 80;
server_name local.demoapp.com;
root /home/kalpesh/projects/demo_app/public;
passenger_enabled on;
rails_env development;
}
$ sudo vim hosts
127.0.0.1 localhost
127.0.1.1 kalpesh
127.0.0.1 local.demoapp.com
Now go to http://local.demoapp.com and you are done.
=========================================================
Useful links:
https://www.digitalocean.com/community/articles/how-to-install-rails-and-nginx-with-passenger-on-ubuntu
http://edapx.com/2012/10/28/nginx-passenger-rvm-and-multiple-virtual-hosts/
http://askubuntu.com/questions/257108/trying-to-start-nginx-on-vps-i-get-nginx-unrecognized-service
http://excid3.com/blog/setting-up-ubuntu-12-04-with-ruby-1-9-3-nginx-passenger-and-postgresql-or-mysql/#.UaxBiek-u0y
@deepti-kakade
Copy link

Thanks, it is very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment