gpt4 book ai didi

node.js - 在 socket.io 的情况下出现错误 'XMLHttpRequest cannot load/socket.io'

转载 作者:太空宇宙 更新时间:2023-11-04 02:26:35 25 4
gpt4 key购买 nike

我收到错误:“XMLHttpRequest无法加载/socket.io”进行套接字调用。出了什么问题,我不明白。我是网络套接字新手,我的其他 api 调用运行良好,但 socket.io 调用不起作用。我已经为 nginx 安装了 ssl 证书,请帮帮我。

我的nginx配置是

server{
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
#listen 80;
listen 443 ssl;

# Make site accessible from http://localhost/
server_name www.example.com;
ssl_certificate "/home/oodles4/sslcertificate/public.crt";
ssl_certificate_key "/home/oodles4/sslcertificate/keyfile.key";
proxy_set_header X-Forwarded-For $remote_addr;

add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";

#location / {
root "/home/oodles4/Documents/dcx/user/dev";
#root "/home/oodles4/Documents/dcx/explorer";
index home.html home.htm;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
# }
location /{
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
9,51 2%
#location / {
root "/home/oodles4/Documents/dcx/user/dev";
#root "/home/oodles4/Documents/dcx/explorer";
index home.html home.htm;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
# }
location /{
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;

fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
}
location /admin{
alias "/home/oodles4/Documents/dcx/admin/dev";
index home.html home.htm;
}

location /api {
proxy_pass http://localhost:8080/api;
}

location /admin/api{
proxy_pass http://localhost:8080/api;
}


location /explorer{
alias "/home/oodles4/Documents/dcx/explorer";
# try_files $uri $uri/ /views/main/main.html;
index dev/views/main/main.html;
}

location /explorer/api{
proxy_pass http://localhost:3000/api;
}

当我执行“/explorer”时,我的所有 api 调用和套接字都会工作

var socket = io.connect('http://www.example.com:3000', {
'reconnect': true,
'reconnection delay': 500
});

最佳答案

我猜你有服务器 block 来监听端口 80、443。但你没有任何服务器 block 来监听 3000。这里我假设您有任何应用程序在端口 3000 上运行。

只需将此 block 附加到当前 nginx 配置即可。

server {
server_name example.com www.example.com;
location / {
proxy_pass http://localhost:3000/;
}
}

关于node.js - 在 socket.io 的情况下出现错误 'XMLHttpRequest cannot load/socket.io',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30045640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com