0

I am trying to run multiple socketio endpoints behind a nginx proxy. My first socket site is at the endpoint '/'. This one works fine. The second socketio endpoint is at '/red/'. This appears to work. The socketio client in my html

    var socket = io.connect('http://www.vagrantdevhost.com:8080', {path:'/red/'});
    socket.on('connect', function() {
        socket.emit('connectevent', {data: 'I\'m connected!'});
    });

appears to connect properly. My connect event is called. However, I get the following errors in my console.

POST http://www.vagrantdevhost.com:8080/red/?EIO=3&transport=polling&t=MKUdom- 405 (METHOD NOT ALLOWED) index.js:83

Any explanations? I'm on day three of this and would appreciate any advice. I have included my nginx config.

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {

        listen       8080 default_server;
        listen       [::]:8080 default_server;
        server_name _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

    location /socket.io {
        proxy_pass http://127.0.0.1:8092/socket.io;
        proxy_redirect off;
        proxy_buffering off;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    location / {
        proxy_pass http://127.0.0.1:8092;
        proxy_redirect off;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /red/ {
        proxy_pass http://127.0.0.1:8093/;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    } 

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }


    }

}
blackirishman
  • 903
  • 1
  • 10
  • 23

1 Answers1

1

Usually these error messaged are caused by the limitation that Nginx can't serve static content on POST request. So, there is a hack in this post where you redirect 405 to 200.

check here: POST request not allowed - 405 Not Allowed - nginx, even with headers included

server {
    listen       80;
    server_name  localhost;

    location / {
        root   html;
        index  index.html index.htm;
    }

    error_page  404     /404.html;
    error_page  403     /403.html;

    # To allow POST on static pages
    error_page  405     =200 $uri;

    # ...
}
Aritra Chakraborty
  • 12,123
  • 3
  • 26
  • 35