我正在构建一个Nodejs TCP模块,一个服务器/客户端应用程序,通过tcp套接字发送数据。我有这个模块在我的localhost上运行没有问题,但是当我从localhost发送数据到远程服务器它不起作用。我得到了奇怪的结果,因为我可以在我的nginx访问日志中看到我的数据的标题,所以我知道数据正在传输但我的服务器端应用程序没有按预期保存数据。我显然遗漏了一些东西。我已经尝试过使用ip-addresses和我在网上找到的一些nginx-conf文件,但没有成功。我不确定是否需要打开端口或操作防火墙,但是非常感谢任何帮助。这是节点应用程序和我的nginx.conf文件。
/* Dependencies */
var server_external_ip = '77.77.77.277'
var fs = require('fs');
var hl7 = require('simple-hl7');
/* Build TCP Server */
var server = hl7.Server;
var tcpClient = server.createTcpClient();
/* Connection */
tcpClient.connect('127.0.0.1', 6969);
/* Get XML */
var msg = fs.readFileSync('./data/example.xml').toString();
/* Send Message */
setTimeout(function() {
tcpClient.send(msg, function(ack) {
console.log("ACK: ",ack.toString());
console.log("\nsuccessful transfer");
tcpClient.close();
});
}, 500);
/*
Config class
vars:
baseFolder: Where to save the messages
port : What port to listen on
ip : what ip to listen on
*/
var Config = new function() {
this.baseFolder = "data";
this.port = 6969;
this.ip = '127.0.0.1';
}
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
#include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
upstream backend_nodejs {
# hash $remote_addr consistent;
server 192.168.1.41:9696;
keepalive 512;
}
server {
listen 80;
client_max_body_size 16M;
keepalive_timeout 10;
location / {
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://backend_nodejs;
}
}
xx.xx.xx.123 - - [11/Mar/2016:16:18:27 -0800] "Connection Established" 400 172 "-" "-" "-"
答案 0 :(得分:0)
你把tcp和http弄乱了。您的客户< - >服务器连接根本与nginx无关。它纯粹是nodejs< - > nodejs的事情。您可能只是缺少防火墙配置。防火墙不是nginx。
您还有var server_external_ip = '77.77.77.277'
但是您尝试在本地连接tcpClient.connect('127.0.0.1', 6969);
它应该是tcpClient.connect('77.77.77.277', 6969);