Nginx works as a reverse proxy but doesn't pass traffic to Puma via a socket
<p>I have a web application fronted by Nginx as the web server. When it is configured as below, it works. Hitting <a href="http://192.168.33.10:9174/" rel="nofollow">http://192.168.33.10:9174/</a> yields a "402 Payment Required"</p>

<pre><code># /etc/nginx/sites-enabled/myapp

server {
  listen  9174;
  server_name 127.0.0.1;
  location /status {
    stub_status on;
    access_log off;
  }
  return 402;
}
</code></pre>

<p>It works. </p>

<p>I then tried to get it to forward traffic to a Puma application server, but it failed. I then set up a bunch of proxies as follows:</p>

<pre><code># /etc/nginx/sites-enabled/myapp
upstream sqlitething {
  server www.sqlite.org;
}

upstream hwacithing {
  server www.hwaci.com;
}

upstream appthing {
  #server unix:///home/deployer/myapp/shared/sockets/socktest.sock 
  server unix:/home/deployer/myapp/shared/sockets/puma.sock fail_timeout=0;
}

server {
  listen   80;
  server_name 192.168.33.10;
  location / {
     proxy_pass http://sqlitething;
  }
}

server {
  listen   8080;
  server_name 192.168.33.10;
  location / {
     proxy_pass http://hwacithing;
  }
}

server {
  listen   8099;
  server_name 192.168.33.10;
  location / {
     proxy_set_header X-Forwarded-For $remote_addr;
     proxy_set_header Host $http_host;
     proxy_redirect off;
     proxy_pass http://appthing;
  }
}

server {
  listen  9175;
  server_name 192.168.33.10;
  return 402;
}
</code></pre>

<p>Here are my results when I hit the URL with a browser:</p>

<ul>
<li><a href="http://192.168.33.10:80" rel="nofollow">http://192.168.33.10:80</a>, it proxied  www.sqlite.org (as expected). </li>
<li><a href="http://192.168.33.10:8080" rel="nofollow">http://192.168.33.10:8080</a>, it proxied www.hwaci.com (as expected)</li>
<li><a href="http://192.168.33.10:9175" rel="nofollow">http://192.168.33.10:9175</a>, returned a HTTP 402 (Payment Required) message (as expected)</li>
<li><a href="http://192.168.33.10:8099" rel="nofollow">http://192.168.33.10:8099</a> tried to redirect me to <a href="https://appthing" rel="nofollow">https://appthing</a>, but nothing happened (NOT EXPECTED)</li>
</ul>

<p>The socket file exists with the permissions as follow:</p>

<pre><code>srwxrwxrwx 1 deployer deployer 0 Jun  8 19:15 /home/deployer/myapp/shared/sockets/puma.sock
</code></pre>

<p>-------- UPDATE June 8 5:57 EST --------------------</p>

<p>I tried the following for the failed URL:</p>

<pre><code>$ curl -isL http://192.168.33.10:8099
HTTP/1.1 301 Moved Permanently
Server: nginx/1.1.19
Date: Wed, 08 Jun 2016 21:52:54 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Location: https://appthing/
Vary: Accept-Encoding
</code></pre>

<p>I tried the following for the successful URL</p>

<pre><code>$ curl -isL http://192.168.33.10:8080
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Wed, 08 Jun 2016 21:54:46 GMT
Content-Type: text/html
Content-Length: 1167
Connection: keep-alive
Vary: Host
Last-Modified: Wed, 13 Dec 2006 14:54:32 GMT
ETag: "88047-48f-4247d938f5a00"
Accept-Ranges: bytes

&lt;html&gt;&lt;head&gt;&lt;title&gt;Hwaci Homepage&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor="white"&gt;
    &lt;font size="7"&gt;&lt;b&gt;Hwaci&lt;/b&gt;&lt;/font&gt;&lt;br&gt;



...etc...
</code></pre>

<hr>

<p>-----   UPDATE June 9 11:24 AM EST  --------------</p>

<p>I added in the lines</p>

<pre><code>proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
</code></pre>

<p>to the server/listen block for port 8099 which connected to the Unix socket. I got the same result. </p>

<p>I then went to <a href="http://blog.honeybadger.io/how-unicorn-talks-to-nginx-an-introduction-to-unix-sockets-in-ruby/" rel="nofollow">http://blog.honeybadger.io/how-unicorn-talks-to-nginx-an-introduction-to-unix-sockets-in-ruby/</a> and set up a little socket server as they specified but with the socket at </p>

<pre><code>unix:///home/deployer/myapp/shared/sockets/socktest.sock 
</code></pre>

<p>I then modified the nginx.conf so that it wouldn't daemonize and that errors would go to the stdout. </p>

<pre><code>daemon off;
error_log /dev/stdout info;
</code></pre>

<p>I then ran nginx as </p>

<pre><code>&gt; sudo nginx -c nginx.conf
</code></pre>

<p>When I ran curl to hit the nginx/socket combo, I got this:</p>

<pre><code>$ curl -isL http://192.168.33.10:8099
HTTP/1.1 502 Bad Gateway
Server: nginx/1.1.19
Date: Thu, 09 Jun 2016 15:13:57 GMT
Content-Type: text/html
Content-Length: 173
Connection: keep-alive

&lt;html&gt;
&lt;head&gt;&lt;title&gt;502 Bad Gateway&lt;/title&gt;&lt;/head&gt;
&lt;body bgcolor="white"&gt;
&lt;center&gt;&lt;h1&gt;502 Bad Gateway&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.1.19&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>The nginx logs looked like this:</p>

<pre><code>2016/06/09 15:13:34 [notice] 9885#0: start worker process 9889
2016/06/09 15:13:49 [info] 9886#0: *1 client 192.168.33.1 closed keepalive connection
2016/06/09 15:13:57 [crit] 9886#0: *3 connect() to unix:/home/deployer/myapp/shared/sockets/socktest.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.33.1, server: 192.168.33.10, request: "GET / HTTP/1.1", upstream: "http://unix:/home/deployer/myapp/shared/sockets/socktest.sock:/", host: "192.168.33.10:8099"
2016/06/09 15:13:57 [info] 9886#0: *3 client 192.168.33.1 closed keepalive connection
</code></pre>

<p>----- end June 9 update ------------------- - - - - - - - ---</p>

<p>The Puma processes are running</p>

<pre><code>deployer@host0:/etc/nginx/sites-enabled$ ps -ef | grep puma
deployer 21319     1  0 19:15 ?        00:00:00 puma 2.16.0 (unix:///home/deployer/myapp/shared/sockets/puma.sock) [20160608191112]                                                                                                                                                                                                                                                                                                                                    
deployer 21322 21319  0 19:15 ?        00:00:09 puma: cluster worker 0: 21319 [20160608191112]                                                                                                                                                                                                                                                                                                                                                                              
deployer 21326 21319  0 19:15 ?        00:00:10 puma: cluster worker 1: 21319 [20160608191112] 
</code></pre>

<p>I am configuring the upstream to Puma as specified in various configuration guides. What am I doing wrong?</p>

<p>Is there a way to see if the Puma process is actually serving my web app?</p>

<p>Is there a way to access the Puma process using curl or wget and via the Unix socket (unix:/home/deployer/myapp/shared/sockets/puma.sock)?</p>