douqi0090 2016-02-10 10:55
浏览 266
已采纳

Apache + socketIO失败

I have made a chat with SocketIO who is working well on local, but i'm trying to deploy it on my Apache server.

I'm using Php + NodeJs, not only Node

I had ERR_CONNECTION_REFUSED error but solved it by opening the good port, Listen 8000 in my ports.conf

My server.js look like this

var io = require('socket.io').listen(8000);
// Socket IO usage

My client.js is

var socket = io.connect('http://[MY SERVER IP]:8000');
// Other client code

I use localhost in local but I changed by my server ip.

But I still have this error

XMLHttpRequest cannot load http://[MY_SERVER_IP]:8000/socket.io/?EIO=3&transport=polling&t=1455101301883-60. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'MY DOMAIN' is therefore not allowed access. The response had HTTP status code 404.

I really don't know what to do, this is the first I try to deploy a Nodejs + php app. I had read some Stackoverflow questions to try to fix it, but i really don't know how...

I don't knwo if this is due to my Apache conf or I must change some NodeJS or SocketIO conf

Thanks for your help.

  • 写回答

1条回答 默认 最新

  • dongxiansi0158 2016-02-15 22:56
    关注

    I found the problem.

    Do not open the NodeJS server port on Apache config. It will make some conflicts and will prevent your Node server to work.

    Just change the localhost by your server IP and it will work fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?