Install Nginx Passenger Ubuntu 16.04


Install Nginx Passenger Ubuntu 16.04

Installing Nginx On Ubuntu 16.04

Nginx is an open source web server that can be used to create web and application servers. It is a powerful and stable web server that is commonly used on Linux based operating systems. The Nginx web server is an alternative to the popular Apache web server. This guide will show you how to install Nginx on Ubuntu 16.04.

To begin, log in to your Ubuntu 16.04 server instance as a user with sudo privileges. Once you’ve logged in, update the system package databases to ensure the latest packages available are installed. We can do this by calling apt-get update from the command line.

Once the database is updated, we can install the Nginx web server with the apt-get command below:

sudo apt-get install nginx

The install process will ask you to confirm the installation, so press Y when it appears. Once the install has finished, you can check the status of the service with the command below:

sudo systemctl status nginx

The Nginx web server is now installed and running. We can confirm this by looking at the output from the command used earlier. You should see a line that reads “active (running)” near the top.

Configuring Nginx On Ubuntu 16.04

Now that you have Nginx installed on your Ubuntu 16.04 server, you can begin to configure it. You can look at the Nginx configuration file like a roadmap of how the web server is set up. It defines the virtual hosts, server blocks, configurations and also includes location and directory blocks.

The configuration file for the Nginx web server is located at /etc/nginx/nginx.conf. This file should already exist if you are running Nginx web server on your server instance. If not, you can create it with the touch command.

sudo touch /etc/nginx/nginx.conf

Open the file in your editor of choice and add the following content:


user www-data;
worker_processes auto;

events {
worker_connections 1024;
}

http {
server {
listen 80;
server_name example.com;
root /var/www/example.com/public;
}
}

This will set up the server block for your domain. After making the changes, you will need to restart the Nginx service for the changes to take effect.

sudo systemctl restart nginx

Installing Passenger For Nginx On Ubuntu 16.04

Now that we have our web server set up, we can move on to installing Passenger. Passenger is an application server for Ruby, Python, Node.js and Meteor applications. It is an open source project that makes it easy to deploy web applications on your Ubuntu server.

To install Passenger, we will first need to grab the official package from the Passenger website. Ubuntu 16.04 uses the Ubuntu 14.04 package since it is still based off of Ubuntu 14.04, so grab the package for that distribution.

wget https://oss-binaries.phusionpassenger.com/binaries/passenger/by_release/5.0.30/passenger_5.0.30-xenial_amd64.deb

Once the package is downloaded, we can install it on our Ubuntu server with the dpkg command below:

sudo dpkg -i passenger_5.0.30-xenial_amd64.deb

This will install Passenger on our Ubuntu 16.04 server. Once the install is complete, we can configure the Passenger module for Nginx. We can do this by editing the Nginx configuration file.

Open the Nginx configuration file with your favorite text editor and add the following content:


passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;

This will enable the Passenger module for Nginx. After making your changes, restart the Nginx service for the changes to take effect:

sudo systemctl restart nginx

Installing Application Dependencies With Bundler

Now that you have Passenger installed, you can begin to deploy your application. Before you deploy your application, you will first need to install the application dependencies. This can be done with the Bundler gem.

In the project directory of your application, install the Bundler gem with the command below:

gem install bundler

Once the gem is installed, you can install the application dependencies with the command below:

bundle install --path vendor/bundle

This will install all of the gem dependencies specified in your Gemfile. Once this is complete, you can move on to deploying your application.

Deploying Your Application With Nginx and Passenger

Now we can deploy our application with Nginx and Passenger. We can do this by creating a new Nginx site configuration in the /etc/nginx/sites-available directory.

Create a new file called example.com in the /etc/nginx/sites-available directory with the following content:


server {
listen 80;
server_name example.com;
root /var/www/example.com/public;
passenger_enabled on;
}

This will set up the server block for your application. After creating the file, you can enable it by creating a symbolic link from the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Finally, restart the Nginx service for the changes to take effect:

sudo systemctl restart nginx

Your application will now be accessible in a web browser like this: http://example.com

Managing Passenger With The Passenger Nginx Module

Now that your application is up and running, we can begin to look at managing it with the Passenger Nginx module. This module allows us to easily set up monitoring, restarting and scaling of our Passenger instance.

To enable the Passenger Nginx module, we will need to edit the Nginx configuration file. Open the Nginx configuration file and add the following content to the server block:


passenger_enabled on;
passenger_monitor_interval 5;
passenger_max_instances_per_app 20;

Once you have made the changes, save and close the file, then restart the Nginx service for the changes to take effect. This will enable the Passenger Nginx module.

Conclusion

In this guide, we have showed you how to install Nginx on Ubuntu 16.04 and configure it to serve your application with Passenger. We have also touched on how to manage your Passenger instance with the Passenger Nginx module.

FAQ

Q: What is Nginx?

A: Nginx is an open source web server that is used to create web and application servers. It is a powerful and stable web server that is commonly used on Linux based systems.

Q: Where is the Nginx configuration file located?

A: The Nginx configuration file is located at /etc/nginx/nginx.conf

Leave a Reply

Your email address will not be published. Required fields are marked *