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.

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

报告相同问题?

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 添加组件无法加载页面,某块加载卡住
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用