Я не могу найти решение этой проблемы. Другие сообщения говорят об отключении через несколько минут. Моя конфигурация отключается сразу после первого ответа во время рукопожатия. Тайм-ауты, похоже, не работают. Журналы ошибок ничего не говорят мне.
Почему соединения не остаются открытыми?
nginx.conf
user nginx;
#user root;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_processes 2;
events {
worker_connections 1024;
multi_accept off;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
client_max_body_size 64m;
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 buffer=16k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100;
#gzip on;
disable_symlinks off;
proxy_intercept_errors on;
#fastcgi_intercept_errors on;
#############################
# NICOLAS WEBSOCKET SUPPORT #
#############################
upstream websocket {
server 10.100.14.8:9026;
}
server {
listen 80;
location /mqtt {
proxy_pass http://websocket/api/v2/mqtt;
proxy_http_version 1.1;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
proxy_connect_timeout 5s;
proxy_read_timeout 20s;
proxy_send_timeout 20s;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
proxy_redirect off;
more_set_headers "Sec-WebSocket-Protocol: $http_Sec_WebSocket_Protocol";
#add_header Sec-WebSocket-Protocol $http_Sec_WebSocket_Protocol;
#proxy_set_header Sec-WebSocket-Protocol $http_Sec_WebSocket_Protocol;
}
}
#############################
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/conf.d/<deleted>;
}
Тестовая страница клиента Paho / html
<html>
<head>
<title>Mqtt client</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/1.8.0/fingerprint2.min.js" type="text/javascript"></script>
<script type = "text/javascript" language = "javascript">
var mqtt;
var reconnectTimeout = 2000;
var host = "10.100.14.10";
var port = 80;
var path = "/mqtt";
/* Handling Mqtt stuff */
function onConnect() {
console.log("Connected ");
}
function onFailure(message) {
console.log("Connection Attempt to Host " + host + "Failed");
console.log("Error message: " + JSON.stringify(message));
setTimeout(MQTTconnect, reconnectTimeout);
}
function onMessageArrived(msg) {
out_msg = msg.payloadString;
out_dest = msg.destinationName;
console.log(out_msg);
calculateResult(out_msg);
}
function MQTTconnect(fingerprint) {
console.log("connecting to " + host + " " + port);
mqtt = new Paho.MQTT.Client(host, port, path, fingerprint);
var options = {
timeout: 3,
onSuccess: onConnect,
onFailure: onFailure
};
mqtt.onMessageArrived = onMessageArrived;
mqtt.connect(options); //connect
}
function subscribe(path) {
mqtt.subscribe(path);
console.log("Subscribed to: " + path);
}
/* interpret result */
function calculateResult(msg) {
obj = JSON.parse(msg);
console.log(obj);
document.getElementById("flexi").innerHTML = "<div style='color: green;'>" + obj.hello + "</div>";
alert("done");
}
function load() {
var that = this;
new Fingerprint2().get(function (result, components) {
console.log(result);
console.log(components);
that.MQTTconnect(result);
});
}
function doYourStuff() {
var rrn = document.getElementById("rrn").value;
var path = "/test";
subscribe(path);
//callBackend(rrn);
}
function simulateResult() {
var value = document.getElementById("rrn").value;
var path = "/flexichecker/" + value;
message = new Paho.MQTT.Message('{ "hello": "world" }');
message.destinationName = path;
mqtt.send(message);
}
</script>
</head>
<body>
<h1>MQTT websocket</h1>
<div id="flexi">
<input id="rrn" name="rrn" type="text" />
<button onclick="doYourStuff()">Check</button>
<button onclick="simulateResult()">Simulate result</button>
</div>
<script>
load();
</script>
</body>
</html>