Here I will show you that how to deploy ruby on rails application with passenger and nginx on digitalocean OR amazon aws server.
Step 7.) Then again login in sachin user
Step 10.) Now we need to setup passenger with nginx
First, install a PGP key:
Change the owner and permissions for this file:
This step will overwrite our Ruby version to an older one. To resolve this, simply remove the incorrect Ruby location and create a new symlink to the correct Ruby binary file:
Open the Nginx configuration file:
You will get path for passenger_root with
If you have used ruby source code then keep as it is
If you have used rvm without gemset then it should like this:
First, We need to disable the default Nginx configuration. Open the Nginx config file:
Now, create an Nginx configuration file for our app:
If you have domain name then set it as server_name else add ip address for the server_name. If you are using more then one application with same server with different domain the don't add default_server into listen 80
Step 13.) Reload & Restart nginx
Here I have used Ubuntu as operating system.
First of all you can login with root user. For deploy application its better to create new user.
Step 1.) create new user for our application.
adduser sachin(username)Step 2.) Give that user to sudo permission so that user will able to do some administrative work
gpasswd -a sachin sudoStep 3.) Generate ssh key for root user
ssh-keygenStep 4.) Then read generated key with this and copy it somewhere else or clipboard for further use
cat ~/.ssh/id_rsa.pubStep 5.) Now you can login into created new user(sachin)
su - sachinStep 6.) Then we can add root user's key into this user's authorization key and for that we can follow this pattern:
mkdir .ssh
chmod 700 .ssh/
nano .ssh/authorized_keys
Now insert your public key (which should be in your clipboard or anywhere else you have copied earlier in step 4) by pasting it into the editor.
chmod 600 .ssh/authorized_keysWith exit you will logout from user(sachin) and now you are into root user.
exit
Step 7.) Then again login in sachin user
su - sachin (Make sure you do all later operation with this user)Step 8.) Set Up Your Domain(Optional)
In order to ensure that your site will be up and visible, you need to set up your DNS records to point your domain name towards your new server. You can find more information on setting up a hostname by following the link.Step 9.) Now you need to setup environment for ruby as well rails. We can install ruby from latest source code as well rvm.
Step 10.) Now we need to setup passenger with nginx
First, install a PGP key:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7Create an APT source file (you will need sudo privileges):
sudo nano /etc/apt/sources.list.d/passenger.listAnd insert the following line in the file:
deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty mainPress CTRL+x to exit, type y to save the file, and then press ENTER to confirm the file location.
Change the owner and permissions for this file:
sudo chown root: /etc/apt/sources.list.d/passenger.listUpdate the APT cache:
sudo chmod 600 /etc/apt/sources.list.d/passenger.list
sudo apt-get updateFinally, install Passenger with Nginx:
sudo apt-get install nginx-extras passengerNote : If you have used rvm then don't do this:
This step will overwrite our Ruby version to an older one. To resolve this, simply remove the incorrect Ruby location and create a new symlink to the correct Ruby binary file:
sudo rm /usr/bin/rubyStep 11.) Setup the web server
sudo ln -s /usr/local/bin/ruby /usr/bin/ruby
Open the Nginx configuration file:
sudo nano /etc/nginx/nginx.confFind the following lines, in the http block:
# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;Uncomment both of them. Update the path in the passenger_ruby line. They should look like this:
# passenger_ruby /usr/bin/ruby;
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;Then save file.
passenger_ruby /usr/local/bin/ruby;
You will get path for passenger_root with
passenger-config --rootYou will get path for passenger_ruby with
which rubyNote: For passenger_ruby
If you have used ruby source code then keep as it is
If you have used rvm without gemset then it should like this:
passenger_ruby /home/sachin/.rvm/gems/ruby-2.2.0/wrappers/rubyIf you have used rvm with gemset named testapp then it should be like this:
passenger_ruby /home/sachin/.rvm/gems/ruby-2.2.0@testapp/wrappers/rubyStep 12.) Now we need to configure nginx
First, We need to disable the default Nginx configuration. Open the Nginx config file:
sudo nano /etc/nginx/sites-available/defaultFind the lines:
listen 80 default_server;Comment them out, like this:
listen [::]:80 default_server ipv6only=on;
# listen 80 default_server;then Save the file.
# listen [::]:80 default_server ipv6only=on;
Now, create an Nginx configuration file for our app:
sudo nano /etc/nginx/sites-available/testappAdd the following server block. The settings are explained below.(Nginx redirect rules)
If you have domain name then set it as server_name else add ip address for the server_name. If you are using more then one application with same server with different domain the don't add default_server into listen 80
server {Then create a symlink for it:
listen 80 default_server;
server_name subdomain.domain.com;
passenger_enabled on;
passenger_app_env production;
root /home/sachin/testapp/public;
}
sudo ln -s /etc/nginx/sites-available/testapp /etc/nginx/sites-enabled/testapp
Step 13.) Reload & Restart nginx
Reload: sudo nginx -s reload
Restart: sudo service nginx restart
0 comments:
Post a Comment