Store credentials for your Rails app in credentials.yml. Read them out in configuration .yml and .rb files. Never share your master.key.
This article details how to setup Nginx and Passenger to run a Rails app in production environment on a Ubuntu machine. It uses Ubuntu 20.04 LTS, Nginx 1.18 and Phusion Passenger 6.0.12.