title: Command to start rails server when using Puma + Nginx
body: <p>I just pushed my Rails app to my remote server using Capistrano. The app is deployed under the <code>deploy</code> user's home directory - <code>/home/deploy/my_app/current/</code></p>
  
  <p>I'm using puma as a web server and have nginx configured to look for a socket to which it should forward all incoming web traffic. Snippet from my nginx site config file -</p>
  
  <pre><code>upstream app {
      server unix:/home/deploy/my_app/shared/sockets/puma.sock fail_timeout=0;
  }
  </code></pre>
  
  <p>Correspondingly, my <code>puma.rb</code> file uses <code>bind</code> to create the same socket mentioned above.</p>
  
  <pre><code># config/puma
  
  # Change to match your CPU core count
  workers Integer(ENV["PUMA_WORKERS"] || 2)
  
  # Min and Max threads per worker
  threads 1, Integer(ENV["PUMA_MAX_THREADS"] || 5)
  
  DEPLOY_ROOT = "/home/deploy/my_app"
  app_dir = File.expand_path("../..", __FILE__)
  shared_dir = "#{DEPLOY_ROOT}/shared"
  
  # Default to production
  port ENV["PORT"] || 3000
  rails_env = ENV['RAILS_ENV'] || "production"
  environment rails_env
  
  # Set up socket location
  bind "unix://#{shared_dir}/sockets/puma.sock"
  
  # Logging
  stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true
  
  # Set master PID and state locations
  pidfile "#{shared_dir}/pids/puma.pid"
  state_path "#{shared_dir}/pids/puma.state"
  activate_control_app
  
  on_worker_boot do
    require "active_record"
    ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
    ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
  end
  </code></pre>
  
  <p>The last piece is to start my Rails app. What is the command that I should use to start it? I tried </p>
  
  <pre><code>SECRET_KEY_BASE=blahblahblah rails s -e production --daemon
  </code></pre>
  
  <p>however this did not create a socket at the path mentioned above. I also confirmed it by trying to hit my URL and nginx threw up a 502 bad gateway.</p>
  
  <p>Should I be using <code>puma -C config/puma.rb</code> instead? What's the difference, I assume <code>rails server</code> starts puma anyway. And how do I get that socket to be created?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong> When I search for the puma process that's running, it tells me it's listening on a TCP port. I'm not sure how that differs from sockets, but could that be the problem?</p>
  
  <pre><code>[01:08:09] deploy:~  &gt; ps aux | grep puma
  deploy   12132  0.0  7.6 523736 78160 ?        Sl   00:59   0:00 puma 3.4.0 (tcp://localhost:3000) [/]
  deploy   12314  0.0  0.0  14512   936 pts/0    S+   01:08   0:00 grep puma
  </code></pre>