连接Websocket io节点js和wordpress时出错

时间:2019-04-06 11:00:19

标签: node.js wordpress nginx websocket

我正在尝试将节点js集成到wordpress中。在本地服务器(Open Server)上,一切正常。这是server.js部分:

var app = require("express")();
var http = require('http').Server(app);
var io = require("socket.io")(http);

header.php

<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script type="text/javascript">var socket = io.connect("http://localhost:3000/");</script>

我在VPS上做同样的事情-我收到错误消息:

Failed to load resource: the server responded with a status of 404 (Not Found)  socket.io.js:1

只能通过下载文件socket.io.js并将其连接到标题来解决此错误:

<script src="/wp-content/themes/NAME/assets/min/js/socket.io.js"></script>
<script>var socket = io('/', {path : '/trading-platform/socket.io'});</script>

在server.js中更改

var io = require("socket.io")(http); 

var io = require('socket.io')(http, {path: '/trading-platform/socket.io'});

现在我收到此错误:

GET https://domen.com/trading-platform/socket.io/?EIO=3&transport=polling&t=MdoB4Yb 404 (Not Found) VM4022:1

我尝试编写localhost:port和IP:port和domen:port

我怀疑您需要在VPS / nginx上配置端口或其他功能,但我不知道确切的内容和位置。而且,在OpenServer上似乎是Apache,而不是nginx。 我以前从未有过配置VPS的经验。请帮助我进行网络套接字连接。

0 个答案:

没有答案