Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install and Setup Nginx+Puma+PostgresSQL on Ubuntu-18

Install and Setup Nginx+Puma+PostgresSQL on Ubuntu-18

Create Deploy User:

  From the root user 
  $ adduser involvio
  $ adduser involvio sudo
  $ exit

Next let's add your SSH key to the server to make it faster to login.

  • Install the dependency packages
$ sudo apt-get update
$ sudo apt-get install -y libgdbm-dev libncurses5-dev automake libtool bison libffi-dev imagemagick libpq-dev gnupg2 nodejs
  • Install Ruby
$ gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

$ \curl -sSL | bash -s stable
$ rvm install 2.5.1
$ source ~/.rvm/scripts/rvm
$ rvm install 2.5.1
$ rvm use 2.5.1 --default

Install Nginx $ sudo apt-get install nginx

Config Nginx Create a new or update nginx config under config/nginx.conf in the local project directory and replacing with your parameters:

upstream puma {
  server unix:///home/involvio/apps/api/shared/tmp/sockets/api-puma.sock;

server {
  listen 80 default_server deferred;

  # If you're planning on using SSL (which you should), you can also go ahead and fill out the following server_name variable:
  # server_name;

  # Don't forget to update these, too
  root /home/involvio/apps/api/current/public;
  access_log /home/involvio/apps/api/current/log/nginx.access.log;
  error_log /home/involvio/apps/api/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;

$ sudo service nginx restart

Install Redis $ sudo apt-get update && sudo apt-get install redis-server

Now open the service file it creates and change supervised to be systemd.

sudo vim /etc/redis/redis.conf
# /etc/redis/redis.conf
supervised systemd

Exit and then restart redis.

$ sudo systemctl reload redis.service
$ sudo systemctl status redis

Install and Configure PostgreSQL Database

$ sudo apt-get install postgresql postgresql-contrib libpq-dev
$ sudo su - postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.