Skip to content

Instantly share code, notes, and snippets.

@ahmadhasankhan
Last active December 15, 2020 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadhasankhan/46354b0db396f73b32bf7ad0775e5263 to your computer and use it in GitHub Desktop.
Save ahmadhasankhan/46354b0db396f73b32bf7ad0775e5263 to your computer and use it in GitHub Desktop.
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 deploy
  $ adduser deploy 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 https://get.rvm.io | 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/deploy/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 example.com;

  # Don't forget to update these, too
  root /home/deploy/apps/api/current/public;
  access_log /home/deploy/apps/api/current/log/nginx.access.log;
  error_log /home/deploy/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