Я искал решение в течение последних двух дней и не могу понять это. У меня есть приложение, узел, который использует сокет И.О. жить под субдомен, который находится под несколько папок https://my.example.com/node/app1/
Каждый раз, когда я иду к URL я получаю GET https://my.example.com/socket.io/socket.io.js Uncaught ReferenceError: io is not defined
NodeJS и Nginx
Вот что мои файлы выглядеть следующим образом: Nginx конфигурационный файл:
server {
listen 443 ssl http2;
server_name my.example.com;
include /etc/nginx/include.d/ssl-common;
include /etc/nginx/include.d/ssl-example;
include /etc/nginx/include.d/all-common;
root /var/example/my;
location /node/app1/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:3131;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/ssl_example_com.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
access_log /var/virdisoft/logs/access.log;
error_log /var/virdisoft/logs/error.log;
}
app.js
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
app.listen(3131, function() {
console.log('Listening on 3131');
});
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
index.html
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io('http://localhost:3131');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
В 'index.html', сценарий обновления тега, который должен нравится' <сценарий SRC = "socket.io/socket.io.js"> ' –
@ArifKhan Я пытался сделать это раньше, но все еще получал ошибку. Это то, что я получаю в журнале консоли: 'Не удалось загрузить ресурс: сервер ответил со статусом 404() https://my.example.com/node/app1/socket.io/socket.io.js Непонятно ReferenceError: io не определен' – Sonu