title: How to resolve 504 Gateway Timeout and WebSockets errors with Nginx and Express app
body: <p>When I run my express app locally, there are no issues whatsoever, but since I've placed it on an AWS EC2 instance running an Nginx web server, there are a few problems whenever I visit the designated domain.</p>
  
  <p>Whenever I go to the domain, it displays a 504 Gateway Timeout for the main.css file that is being served from the public directory.  Not sure if it's relevant, but I am using Jade templates with Express, and sass files are being compiled at runtime to the public/css directory.</p>
  
  <p>Here's the request headers:
  GET /css/main.css HTTP/1.1
  Host: dispatch.nucleus.technology
  Connection: keep-alive
  Pragma: no-cache
  Cache-Control: no-cache
  Accept: text/css,<em>/</em>;q=0.1
  User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
  DNT: 1
  Referer: <a href="http://dispatch.nucleus.technology/" rel="nofollow">http://dispatch.nucleus.technology/</a>
  Accept-Encoding: gzip, deflate, sdch
  Accept-Language: en-US,en;q=0.8</p>
  
  <p>There also seems to be a websocket error:
  WebSocket connection to 'ws://dispatch.nucleus.technology/socket.io/?EIO=3&amp;transport=websocket&amp;sid=W0qJNlmaVdFbKoeBAAAA' failed: Error during WebSocket handshake: Unexpected response code: 400</p>
  
  <p>I've since fixed the css problem, and it seems that running the app as root solves it, but I'm not sure why - if anyone has some insight regarding that it would be very helpful.</p>
  
  <p>As for the websocket error, I'm still receiving that despite running the app as root.</p>