title: nginx as webserver incl. socket.io and node.js / ws:// 400 Bad Request
body: <p>i've got this error requests.</p>
  
  <p><img src="https://i.stack.imgur.com/udN8b.png" alt="Errors from FireBug"></p>
  
  <p>The last sentence in german means "Firefox cant connect to the server which is located in ws://.......".</p>
  
  <p>The server wouldnt be the problem i think.</p>
  
  <p>Because that here is the nginx configuration, because i think there is the problem!</p>
  
  <pre><code>server {
      server_name example.org;
      listen 80 default_server;
      root /var/www/web;
  
      location / # for symfony2
      {
          try_files $uri @rewriteapp;
      }
  
      location @rewriteapp # for symfony2
      {
                  rewrite ^(.*)$ /app.php/$1 last;
      }
  
      location ~ ^/app\.php(/|$)
      {
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_split_path_info ^(.+\.php)(/.*)$;
          include fastcgi_params;
          fastcgi_param HTTPS off;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
  
      location ~ ^/socket
      {
          proxy_pass http://127.0.0.1:8080;
          proxy_redirect off;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $http_host;
      }
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  }
  </code></pre>
  
  <p>nginx version: nginx/1.4.7</p>
  
  <p>app.js (thats the server!)</p>
  
  <pre><code>var express = require('express'),
      io = require('socket.io').listen(server),
      server = require('http').createServer(app),
      bodyParser = require('body-parser');
  
  var app = express();
  server.listen(8080);
  
  app.use(bodyParser.json());
  
  app.post('/', function(request, response)
  {
      response.send('OK');
      io.emit('MessageForAll', request.body);
  });
  
  io.on('connection', function (socket){});
  
  console.log('Server running on port 8080.');
  </code></pre>