【问题标题】:node.js + nginx + rails Chat does work on localhost, doesn't work on Amazon EC2node.js + nginx + rails Chat 可以在 localhost 上工作,但不能在 Amazon EC2 上工作
【发布时间】:2013-10-10 23:47:35
【问题描述】:

聊天在 localhost 上有效,但在 Amazon EC2 上无效

index.html

    <html>
<head>
  <title> Chat with socket.io and node.js</title>
  <style>
    #chat {
      height:500px;
  }
  </style>
<head>
<body>
<h1 style="text-align:center;">CHAT</h1>
  <div id="chat"></div>
  <form id="send-message">
    <input size="35" id="message"></input>
    <input type="submit"></input>
  </form>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  <script src="/socket.io/socket.io.js"></script>
  <script>
    $(function(){
  var socket = io.connect();
  var $messageForm = $('#send-message');
  var $messageBox = $('#message');
  var $chat = $('#chat');

  $messageForm.submit(function(e){
    e.preventDefault();
    socket.emit('send message', $messageBox.val());
    $messageBox.val('');
  });

  socket.on('new message', function(data) {
    $chat.append(data + '<br />');
  });
});
  </script>
</body>
</html>

app.js

var express = require('express'),
  app = express(),
  server = require('http').createServer(app),
  io = require('socket.io').listen(server);

server.listen(3333);

app.get('/', function(req, res){
  res.sendfile(__dirname + '/index.html');
});

io.sockets.on('connection', function(socket){
  socket.on('send message', function(data){
    io.sockets.emit('new message', data);
  });
});

聊天示例取自http://www.youtube.com/watch?v=pNKNYLv2BpQ

节点-v v0.10.13

导轨'3.2.13'

当我运行时-> node app.js 我得到 -> 信息 - socket.io 已启动 & 当我尝试访问 my_ip:3333 时——不走运。

任何帮助或提示将不胜感激。

【问题讨论】:

    标签: ruby-on-rails node.js amazon-web-services nginx amazon-ec2


    【解决方案1】:

    解决方案:) http://docs.aws.amazon.com/opsworks/latest/userguide/layers-server-nodejs.html

    "Node.js 应用配置

    Node.js 运行的主文件必须命名为 server.js 并位于已部署应用程序的根目录中。

    必须将 Node.js 应用程序设置为侦听端口 80(或端口 443,如果适用)。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多