I have my app written in node on a Debian 7 server launched with forever and working with apache proxy via a url (without port like http.//subdomain.domain.com) with this config:
<VirtualHost *:80>
ServerName subdomain.domain.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8081/
ProxyPassReverse http://localhost:8081/
</Location>
</VirtualHost>
The app is running ok but the problem comes with socket.io, I´m getting this error:
GET http://192.168.1.1:8081/socket.io/?EIO=2&transport=polling&t=1424074094677-75 net::ERR_CONNECTION_TIMED_OUT
This is my server.js:
var server = express.createServer();
server.configure(function(){
server.set('views', __dirname + '/views');
server.set('view options', { layout: false });
server.use(connect.bodyParser());
server.use(express.cookieParser());
server.use(express.session({ secret: "ezdoknahi!!"}));
server.use(connect.static(__dirname + '/static'));
});
server.configure('development', function(){
server.use(express.errorHandler());
});
//setup the errors
server.error(function(err, req, res, next){
if (err instanceof NotFound) {
res.render('404.jade', { locals: {
title : '404 - Not Found'
,description: ''
,author: ''
,analyticssiteid: 'XXXXXXX'
},status: 404 });
} else {
res.render('500.jade', { locals: {
title : 'The Server Encountered an Error'
,description: ''
,author: ''
,analyticssiteid: 'XXXXXXX'
,error: err
},status: 500 });
}
});
server.listen( port);
//Setup Socket.IO
var io = io.listen(server);
io.sockets.on('connection', function(socket){
console.log('Client Connected');
socket.on('message', function(data){
// socket.broadcast.emit('server_message',data);
// socket.emit('server_message',data);
console.log(data);
});
socket.on('disconnect', function(){
console.log('Client Disconnected.');
});
});
///////////////////////////////////////////
// Routes //
And this is my client app (Angular.js):
produccionApp.factory('socket', function () {
var socket = io.connect('http://192.168.1.1:8081');
return socket;
});
(192.168.1.1 is my subdomain.domain.com IP Address (enterprise server))
In my localhost works perfectly (how not!) but in production not. I suspect the problem is connecting through apache proxy. How to solve it?
Thanks in advance
UPDATE:
I installed nginx 1.6 on this server ( Debian 7 ) and I configured like this:
server {
listen 80;
server_name subdomain.domain.com;
access_log /var/log/nginx/subdomain.domain.com.log;
error_log /var/log/nginx/subdomain.domain.com.error.log;
location / {
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;
proxy_pass http://127.0.0.1:8081/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
And still the same error:
GET http://192.168.1.1:8081/socket.io/?EIO=2&transport=polling&t=1424074094677-75 net::ERR_CONNECTION_TIMED_OUT
I also tried to connect socket.io to http://subdomain.domain.com but still same error.
any help?