Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在apache中为聊天功能实例化Node.js时出现的问题_Javascript_Node.js_Apache_.htaccess_Sockets - Fatal编程技术网

Javascript 在apache中为聊天功能实例化Node.js时出现的问题

Javascript 在apache中为聊天功能实例化Node.js时出现的问题,javascript,node.js,apache,.htaccess,sockets,Javascript,Node.js,Apache,.htaccess,Sockets,在服务器上安装SSL后,Node.js没有实例化,这是一个令人惊讶的问题。我们尝试了很多东西&我个人对apache或Node.js不是很精通。下面是错误和我们尝试过的几件事。任何帮助都将不胜感激 这是我们的domain.com.conf文件 <VirtualHost *:80> ServerName domain.com ServerAlias www.domain.com DocumentRoot /var/www/html

在服务器上安装SSL后,Node.js没有实例化,这是一个令人惊讶的问题。我们尝试了很多东西&我个人对apache或Node.js不是很精通。下面是错误和我们尝试过的几件事。任何帮助都将不胜感激

这是我们的domain.com.conf文件

<VirtualHost *:80>
        ServerName domain.com
        ServerAlias www.domain.com
        DocumentRoot /var/www/html
        <Directory /var/www/html>
                Options -Indexes FollowSymLinks -MultiViews
                AllowOverride All
        </Directory>

        CustomLog /var/log/httpd/domain.com-access.log combined
        ErrorLog /var/log/httpd/domain.com-error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass /socket.io http://192.237.xxx.xxx:8080
</VirtualHost>

<VirtualHost *:443>
        ServerName domain.com
        ServerAdmin info@domain.com
        DocumentRoot /var/www/html
        <Directory /var/www/html>
                Options -Indexes FollowSymLinks -MultiViews
                AllowOverride All
        </Directory>

        CustomLog /var/log/httpd/domain.com-ssl-access.log combined
        ErrorLog /var/log/httpd/domain.com-ssl-error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        SSLEngine on
        SSLCertificateFile    /var/cert/www_domain_com.crt
        SSLCACertificateFile    /var/cert/certificate.crt
        SSLCertificateKeyFile /var/cert/www_domain_com.key

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass /socket.io http://192.237.xxx.xxx:8080
    ProxyPassReverse /socket.io http://192.237.xxx.xxx:8080

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>

        BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
在这个设置中,我们出现了这个错误

>>“>

然后我们将我们实例化socket.io的方式(根据朋友的建议)改为

我们在下面看到了这个

在做了一些研究之后,我们通过将此行添加到上述.htaccess文件中,在服务器上启用了CORS:

Header set Access-Control-Allow-Origin "*"
但是,仍然是相同的错误…(安装了mod_头)

我们几乎把头发都拔了,希望有人也有同样的问题能帮我们解决

///

根据请求,这里有完整的socket.js:

$(function(){

  window.MY_Socket = {


    // Instantiate the Socket.IO client and connect to the server
    socket : io.connect('https://domain.com:8080/socket.io', {secure: true}),


    // Set up the initial event handlers for the Socket.IO client
    bindEvents : function() {
        this.socket.on('startup',MY_Socket.startupMessage);
        //this.socket.on('startup',MY_Socket.startupComment);
        this.socket.on('broadcastNewPost',MY_Socket.updateMessages);
        this.socket.on('broadcastNewComment',MY_Socket.updateComment);
        this.socket.on('broadcastNewChat',MY_Socket.updateChat);
    },

    // This just indicates that a Socket.IO connection has begun.
    startupMessage : function(data) {
      //console.log(data.message);
    },

    startupComment : function(data) {
      //console.log(data.message);
    },

    // on 'broadcastNewPost' update the message list from other users
    updateMessages : function(data) {
        // Because the message is broadcasted twice (once for the team, again for the admins)
        // we need to make sure it is only displayed once if the Admin is also on the same
        // team as the sender.
        //if( ( !userIsAnAdmin() && data.team != 'admin') ||
        //  ( userIsAnAdmin() && data.team === 'admin') ){
        //console.log("TEAM " + data.team);
        //console.log(session_co_id);
        if(data.team == session_co_id) {
            // Send the html partial with the new message over to the jQuery function that will display it.
            App.showBroadcastedMessage(data.message);
        }
    },

    updateComment : function(data) {
        // Because the message is broadcasted twice (once for the team, again for the admins)
        // we need to make sure it is only displayed once if the Admin is also on the same
        // team as the sender.
        //if( ( !userIsAnAdmin() && data.team != 'admin') ||
        //  ( userIsAnAdmin() && data.team === 'admin') ){
        if(data.team == session_co_id) {
        // Send the html partial with the new message over to the jQuery function that will display it.
        App.showBroadcastedComment(data.message, data.team, data.status);
      }
    },

    updateChat : function(data) {
        //console.log("TEAM " + data.team);
        //console.log(session_co_id);
        //if(data.co_id == session_co_id) {
            // Send the html partial with the new message over to the jQuery function that will display it.
            // post: post, diss_id: diss_id, last_sender: last_sender, co_id: co_id
            //console.log(data.diss_id);

            App.showBroadcastedChat(data.first_name, data.html, data.broadcast_post, data.profile_picture, data.diss_id, data.last_poster, data.session_co_id);
        //}
    },

    // This will emit an html partial containing a new message,
    // plus the teamId of the user sending the message.

    sendNewComment : function(msg,team,status) {
      MY_Socket.socket.emit('newComment',msg,team,status);
    },

    sendNewChat : function(first_name, html, broadcast_post, profile_picture, diss_id, last_poster, session_co_id) {

        MY_Socket.socket.emit('newChat', first_name, html, broadcast_post, profile_picture, diss_id, last_poster, session_co_id);
    },

    sendDiscussionNewComment : function(msg,team,status) {
      MY_Socket.socket.emit('newDiscussionComment', msg, team, status);
    },

    sendNewPost : function(msg,team) {

        MY_Socket.socket.emit('newPost',msg,team);
    },

    // Join a socket.io 'room' based on the user's team
    joinRoom : function(session_co_id){
      // get the CodeIgniter sessionID from the cookie
      //var sessionId = readCookie('ci_session');
        sessionId = session_co_id; //1  // CHANGE IT ******************************************************
        //console.log(sessionId);
      if(sessionId) {
        // Send the sessionID to the Node server in an effort to join a 'room'
        MY_Socket.socket.emit('joinRoom', session_co_id);
      } else {
        // If no sessionID exists, don't try to join a room.
        //console.log('No session id found. Broadcast disabled.');
        //forward to logout url?
      }
    }

  } // end window.MY_Socket

  // Start it up!
  MY_Socket.bindEvents();

    // Read a cookie. http://www.quirksmode.org/js/cookies.html#script
    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }

});
$(函数(){
window.MY_套接字={
//实例化Socket.IO客户端并连接到服务器
套接字:io.connect('https://domain.com:8080/socket.io“,{secure:true}),
//为Socket.IO客户端设置初始事件处理程序
bindEvents:function(){
this.socket.on('startup',MY_socket.startupMessage);
//this.socket.on('startup',MY_socket.startupComment);
this.socket.on('broadcastNewPost',MY_socket.updateMessages);
this.socket.on('broadcastingnewcomment',MY_socket.updateComment);
this.socket.on('broadcastNewChat',MY_socket.updateChat);
},
//这只是表示Socket.IO连接已经开始。
启动消息:功能(数据){
//console.log(data.message);
},
startupComment:功能(数据){
//console.log(data.message);
},
//在“broadcastNewPost”上更新来自其他用户的消息列表
updateMessages:函数(数据){
//因为消息会广播两次(一次用于团队,另一次用于管理员)
//我们需要确保它只显示一次,如果管理员也在同一台计算机上
//团队作为发送者。
//如果((!userIsAnAdmin()&&data.team!=“admin”)||
//(userIsAnAdmin()&&data.team==='admin')){
//console.log(“TEAM”+data.TEAM);
//console.log(session\u co\u id);
if(data.team==session\u co\u id){
//将包含新消息的html部分发送到将显示它的jQuery函数。
App.showBroadcastedMessage(data.message);
}
},
updateComment:函数(数据){
//因为消息会广播两次(一次用于团队,另一次用于管理员)
//我们需要确保它只显示一次,如果管理员也在同一台计算机上
//团队作为发送者。
//如果((!userIsAnAdmin()&&data.team!=“admin”)||
//(userIsAnAdmin()&&data.team==='admin')){
if(data.team==session\u co\u id){
//将包含新消息的html部分发送到将显示它的jQuery函数。
App.showBroadcastedComment(data.message、data.team、data.status);
}
},
updateChat:函数(数据){
//console.log(“TEAM”+data.TEAM);
//console.log(session\u co\u id);
//if(data.co\u id==会话\u co\u id){
//将包含新消息的html部分发送到将显示它的jQuery函数。
//post:post,diss\u id:diss\u id,last\u发送者:last\u发送者,co\u id:co\u id
//console.log(data.diss_id);
App.showBroadcastedChat(data.first\u name、data.html、data.broadcast\u post、data.profile\u picture、data.diss\u id、data.last\u poster、data.session\u co\u id);
//}
},
//这将发出一个包含新消息的html部分,
//加上发送消息的用户的teamId。
sendNewComment:功能(消息、团队、状态){
MY_Socket.Socket.emit('newComment',msg,team,status);
},
sendNewChat:函数(名字、html、广播帖子、个人资料图片、diss\u id、最后海报、会话合作id){
MY_Socket.Socket.emit('newChat',名字,html,广播帖子,个人资料图片,diss_id,last_poster,session_co_id);
},
sendDiscussionNewComment:功能(消息、团队、状态){
MY_Socket.Socket.emit('newDiscussionComment',msg,team,status);
},
sendNewPost:功能(消息,团队){
MY_Socket.Socket.emit('newPost',msg,team);
},
//根据用户团队加入socket.io“房间”
joinRoom:功能(会话合作id){
//从cookie中获取CodeIgniter会话ID
//var sessionId=readCookie(“ci_会话”);
sessionId=session\u co\u id;//1//更改它******************************************************
//console.log(sessionId);
if(sessionId){
//将sessionID发送到节点服务器以加入“房间”
MY_Socket.Socket.emit('joinRoom',session_co_id);
}否则{
//如果不存在sessionID,请不要尝试加入会议室。
//log('找不到会话id。广播已禁用');
//转发到注销url?
}
}
}//结束window.MY\u套接字
//启动它!
MY_Socket.bindEvents();
//读饼干。http://www.quirksmode.org/js/cookies.html#script
函数readCookie(名称){
变量nameEQ=name+“=”;
var ca=document.cookie.split(“;”);
对于(变量i=0;i
您的朋友建议使用端口8080可能会绕过Apache代理(在端口80上运行),并通过直接访问Node.js(因为不同的端口是不同的域)产生跨源问题。由于您在/socket.io/1/?t=000上获得了200分,您似乎在从Apache到节点之间获得了200分。好的。我可能会将您的重点从Apache转移到节点-可以吗
socket : io.connect('https://domain.com:8080/socket.io', {secure: true}),
Header set Access-Control-Allow-Origin "*"
$(function(){

  window.MY_Socket = {


    // Instantiate the Socket.IO client and connect to the server
    socket : io.connect('https://domain.com:8080/socket.io', {secure: true}),


    // Set up the initial event handlers for the Socket.IO client
    bindEvents : function() {
        this.socket.on('startup',MY_Socket.startupMessage);
        //this.socket.on('startup',MY_Socket.startupComment);
        this.socket.on('broadcastNewPost',MY_Socket.updateMessages);
        this.socket.on('broadcastNewComment',MY_Socket.updateComment);
        this.socket.on('broadcastNewChat',MY_Socket.updateChat);
    },

    // This just indicates that a Socket.IO connection has begun.
    startupMessage : function(data) {
      //console.log(data.message);
    },

    startupComment : function(data) {
      //console.log(data.message);
    },

    // on 'broadcastNewPost' update the message list from other users
    updateMessages : function(data) {
        // Because the message is broadcasted twice (once for the team, again for the admins)
        // we need to make sure it is only displayed once if the Admin is also on the same
        // team as the sender.
        //if( ( !userIsAnAdmin() && data.team != 'admin') ||
        //  ( userIsAnAdmin() && data.team === 'admin') ){
        //console.log("TEAM " + data.team);
        //console.log(session_co_id);
        if(data.team == session_co_id) {
            // Send the html partial with the new message over to the jQuery function that will display it.
            App.showBroadcastedMessage(data.message);
        }
    },

    updateComment : function(data) {
        // Because the message is broadcasted twice (once for the team, again for the admins)
        // we need to make sure it is only displayed once if the Admin is also on the same
        // team as the sender.
        //if( ( !userIsAnAdmin() && data.team != 'admin') ||
        //  ( userIsAnAdmin() && data.team === 'admin') ){
        if(data.team == session_co_id) {
        // Send the html partial with the new message over to the jQuery function that will display it.
        App.showBroadcastedComment(data.message, data.team, data.status);
      }
    },

    updateChat : function(data) {
        //console.log("TEAM " + data.team);
        //console.log(session_co_id);
        //if(data.co_id == session_co_id) {
            // Send the html partial with the new message over to the jQuery function that will display it.
            // post: post, diss_id: diss_id, last_sender: last_sender, co_id: co_id
            //console.log(data.diss_id);

            App.showBroadcastedChat(data.first_name, data.html, data.broadcast_post, data.profile_picture, data.diss_id, data.last_poster, data.session_co_id);
        //}
    },

    // This will emit an html partial containing a new message,
    // plus the teamId of the user sending the message.

    sendNewComment : function(msg,team,status) {
      MY_Socket.socket.emit('newComment',msg,team,status);
    },

    sendNewChat : function(first_name, html, broadcast_post, profile_picture, diss_id, last_poster, session_co_id) {

        MY_Socket.socket.emit('newChat', first_name, html, broadcast_post, profile_picture, diss_id, last_poster, session_co_id);
    },

    sendDiscussionNewComment : function(msg,team,status) {
      MY_Socket.socket.emit('newDiscussionComment', msg, team, status);
    },

    sendNewPost : function(msg,team) {

        MY_Socket.socket.emit('newPost',msg,team);
    },

    // Join a socket.io 'room' based on the user's team
    joinRoom : function(session_co_id){
      // get the CodeIgniter sessionID from the cookie
      //var sessionId = readCookie('ci_session');
        sessionId = session_co_id; //1  // CHANGE IT ******************************************************
        //console.log(sessionId);
      if(sessionId) {
        // Send the sessionID to the Node server in an effort to join a 'room'
        MY_Socket.socket.emit('joinRoom', session_co_id);
      } else {
        // If no sessionID exists, don't try to join a room.
        //console.log('No session id found. Broadcast disabled.');
        //forward to logout url?
      }
    }

  } // end window.MY_Socket

  // Start it up!
  MY_Socket.bindEvents();

    // Read a cookie. http://www.quirksmode.org/js/cookies.html#script
    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }

});