Ruby on rails node.js+;nginx+;rails聊天在localhost上工作,而不是';我不能在AmazonEC2上工作
聊天可以在本地主机上运行,但不能在AmazonEC2上运行 index.htmlRuby on rails node.js+;nginx+;rails聊天在localhost上工作,而不是';我不能在AmazonEC2上工作,ruby-on-rails,node.js,amazon-web-services,nginx,amazon-ec2,Ruby On Rails,Node.js,Amazon Web Services,Nginx,Amazon Ec2,聊天可以在本地主机上运行,但不能在AmazonEC2上运行 index.html <html> <head> <title> Chat with socket.io and node.js</title> <style> #chat { height:500px; } </style> <head> <body> <h1 style="text-ali
<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>
聊天示例取自
节点-v
v0.10.13
轨道“3.2.13”
当我运行->node app.js时
我得到->信息-socket.io启动
&当我尝试访问我的ip:3333时——没有运气
任何帮助或提示都将不胜感激。解决方案:)
“Node.js应用程序配置
Node.js运行的主文件必须命名为server.js,并位于已部署应用程序的根目录中
Node.js应用程序必须设置为侦听端口80(或端口443,如果适用)。”
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);
});
});