title: nginx blocking puma from same port
body: <p>I have a rails app running on puma and nginx. I launch nginx with <code>sudo service nginx restart</code> then puma/rails with <code>rvmsudo rails server -p 80</code></p>
  
  <p>This is my error:</p>
  
  <pre><code>`initialize': Address already in use - bind(2) for "localhost" port 80 (Errno::EADDRINUSE)
  </code></pre>
  
  <p>This error only occurs when nginx is already running.</p>
  
  <p>The full error is:</p>
  
  <pre><code> $rvmsudo rails server -p 80
  
  =&gt; Booting Puma
  =&gt; Rails 4.2.4 application starting in development on http://localhost:80
  =&gt; Run `rails server -h` for more startup options
  =&gt; Ctrl-C to shutdown server
  Puma 2.14.0 starting...
  * Min threads: 0, max threads: 16
  * Environment: development
  * Listening on tcp://localhost:80
  Exiting
  /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `initialize': Address already in use - bind(2) for "localhost" port 80 (Errno::EADDRINUSE)
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `new'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `add_tcp_listener'
      from (eval):2:in `add_tcp_listener'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/rack/handler/puma.rb:33:in `run'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
      from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `&lt;top (required)&gt;'
      from bin/rails:4:in `require'
      from bin/rails:4:in `&lt;main&gt;'
  </code></pre>
  
  <p>Any help on how to get nginx to allow puma to talk to it would be very appreciated.</p>
  
  <p><strong>EDIT 1</strong> nginx.conf</p>
  
  <pre><code>upstream puma {
    server unix:///home/my-user-name/apps/my-web-app/shared/tmp/sockets/my-web-app-puma.sock;
  }
  
  server {
    listen 80 default_server deferred;
  
    listen 443 ssl;
  
    # server_name example.com;
    ssl_certificate /etc/ssl/mysite/mysite.com.chained.crt;
    ssl_certificate_key /etc/ssl/mysite/mysite.key;
  
    root /home/my-user-name/apps/my-web-app/current/public;
    access_log /home/my-user-name/apps/my-web-app/current/log/nginx.access.log;
    error_log /home/my-user-name/apps/my-web-app/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;
  }
  </code></pre>