title: Missing `secret_key_base` for 'production' environment on Ubuntu 18.04 server (Rails 6.0), multiple topics tried
body: <p>This topic has a <strong>SOLUTION</strong> embeded at the end.</p>
  <h1>PROBLEM</h1>
  <p>I'm deploying for the first time a Rails app on a VPS on Ubuntu 18.04. with Nginx.
  I followed the good tutorial of <a href="https://www.youtube.com/watch?v=vzEEfAj45zw" rel="noreferrer">Gorails</a> &quot;Deploy Ruby on Rails To Production in 2019&quot;.
  Everything worked, until I had the &quot;Incomplete response received from application&quot; page.</p>
  <p>I checked the nginx logs on <code>/var/log/nginx/error.log</code>and saw the typical message &quot;Missing <code>secret_key_base</code> for 'production' environment, set this string with <code>rails credentials:edit</code>&quot;</p>
  <p>As the method of Gorails didn't seems to work (after a <code>bundle exec rails secret</code> on his console app-side, he add a file /my_website/.rbenv-vars with a SECRET_KEY_BASE line, filled with the generated secret key), I decided to follow the multiples topics answering to this question.
  Here is the thing, I'm not sure if the followings steps are the goods one.</p>
  <ol>
  <li>I run <code>bundle exec rails secret</code>on my console, server-side, as deploy user. So I have my GENERATED_KEY_1</li>
  <li>I add to <code>~/.bashrc</code> : <code>export SECRET_KEY_BASE=&quot;GENERATED_KEY_1&quot;</code></li>
  <li>I <code>source ~/.bashrc</code></li>
  <li>I check my key with <code>echo $SECRET_KEY_BASE</code>, and I have the good key displayed (GENERATED_KEY_1)</li>
  <li>I edited my credential file as</li>
  </ol>
  <pre><code>development:
    secret_key_base: ORIGINAL_KEY
  
  test:
    secret_key_base: ORIGINAL_KEY
  
  production:
    secret_key_base: &lt;%= ENV[&quot;SECRET_KEY_BASE&quot;] %&gt;
  </code></pre>
  <p>and added Dotenv to my Gemfile, required it in application.rb</p>
  <p>But none of this worked, after restarted nginx server.
  So I restarted the previous step, with the root-user.</p>
  <p>But again, it failed.
  My questions are:</p>
  <ul>
  <li>what I am missing ?</li>
  <li>How can I know, if it's searching the key in the good place, as I have always the same error message ?</li>
  <li>Which key am I suppose to generate ? App-side ? Server-side ? As root or deploy user ?</li>
  <li>Do I have something else to configure in /etc/nginx/sites-available/default ? (I saw on this <a href="https://stackoverflow.com/a/29259581/10717993">topic</a> that this guys changed a <code>rails_env production; to rails_env development;</code> but I haven't any rails line)</li>
  </ul>
  <p>Thank you, I'm a little bit desperate ^^</p>
  <h1>SOLUTION</h1>
  <p>During my many tests, I logged with the root user, and run <code>EDITOR=&quot;vim&quot; rails credentials:edit</code>. This command had generated a <code>master.key</code>, which doesn't exist on your Github repo.</p>
  <p>But first, I didn't modified it. I think that was the main problem, as the application use it to decrypt your <code>credentials.yml.enc</code> file. When I understood it, I edited the <code>master.key</code> with the content of the <code>master.key</code> on my computer app.</p>
  <p>Even after editing <code>credentials.yml.enc</code>with <code>&lt;%= ENV[&quot;SECRET_KEY_BASE&quot;] %&gt;</code>, this solution works. This corresponds to the answer of <a href="https://stackoverflow.com/users/11801415/lyzard-kyng">Lyzard Kyng</a>, even if it's a bit different.</p>
  <p>I can't run <code>EDITOR=&quot;vim&quot; rails credentials:edit</code>with the deploy user, it doesn't work.</p>