undefined
undefined

Reputation: 3622

socket.io.js not found on production instance

First of all, yes I know there are many related question on SO for similar problem. I have gone through almost all of them before asking.

I have a very strange issue where, socket.io.js file is not served by server on production instance.

Exactly same code works on my development instance. The only difference between development annd Production instance is that, produciton instance runs using nginx proxy but I do not think that should be the problem.

When I am trying to access https://my-host-name.com/socket.io/socket.io.js

I get Error "404 Not Found"

Nginx log gives this error:

2017/08/17 12:01:28 [error] 30437#0: *2298619 open() "/data/api/current/socket.io/socket.io.js" failed (2: No such file or directory), client: 10.xxx.x.xx, server: , request: "GET /socket.io/socket.io.js HTTP/1.1", host: ""

I am completely clueless whats going wrong here. Can any one please help me?

Here is my socket confiiguration on app.js file:

var server = https.createServer(app.get("httpsOptions"), app);
var socket = require('socket.io');
var io = socket.listen(server);
server.listen(app.get('port'), function(){
    logger.info("Starting the express app...");
    logger.info("Express server listening on port " + app.get('port'));
});
require('./routes/sockets/base')(io); // separating the socket.io related code in separate file

I can see my node_modules already has socket.io, socket.io-adaptor, socket.io-client and socket.io-parser

Upvotes: 1

Views: 1428

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

The only difference between development annd Production instance is that, produciton instance runs using nginx proxy but I do not think that should be the problem. That is a very big assumption and a wrong one too.

You should set the development environment with a nginx proxy and then move to production. All the static files needs to be accessible to the nginx container so it can sever those static files and they don't go to your NodeJS code

Also you would need below directives in your nginx config

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

See this for more details https://www.nginx.com/blog/nginx-nodejs-websockets-socketio/

Upvotes: 1

Related Questions