Skip to content

Instantly share code, notes, and snippets.

@fox-alvarez
Created February 21, 2014 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fox-alvarez/9144047 to your computer and use it in GitHub Desktop.
Save fox-alvarez/9144047 to your computer and use it in GitHub Desktop.
this is the configuration with which we are working, nginx v1.4.4, the error message is as follows "WebSocket is closed before the connection is established".
<script src="socket.io/socket.io.js"></script>
<script>
var websocket = io.connect("/");
$(document).on("ready", iniciar);
function iniciar(e)
{
websocket.emit('my other event', { my: 'data' });
}
</script>
# HTTPS server
upstream node {
server 127.0.0.1:8080;
keepalive 256; # not necessary
}
server {
listen 443 ssl;
server_name misite.com www.misite.com;
root /var/www/html/misite;
access_log /var/log/nginx/misite.access.log;
error_log /var/log/nginx/misite.error.log;
ssl_certificate /etc/nginx/ssl/misite.crt;
ssl_certificate_key /etc/nginx/ssl/misite.key;
location / {
rewrite ^/([\.a-zA-Z0-9_-]*)/?$ index.php?d1=$1 last;
rewrite ^/([\.a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)/?$ index.php?d1=$1&d2=$2 last;
rewrite ^/([\.a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)/?$ index.php?d1=$1&d2=$2&d3=$3 last;
rewrite ^/([\.a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)/?$ index.php?d1=$1&d2=$2&d3=$3&d4=$4 last;
rewrite_log on;
index index.html index.htm index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/misite/$fastcgi_script_name;
include fastcgi_params;
}
location /socket.io/ {
# the following is required for WebSockets
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# supposedly prevents 502 bad gateway error;
# ultimately not necessary in my case
proxy_buffers 8 32k;
proxy_buffer_size 64k;
#proxy_busy_buffers_size 10m;
# the following is required
proxy_pass http://node;
proxy_redirect off;
# the following is required as well for WebSockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment