简体   繁体   English

无法使用Nginx将请求代理到node.js(socket.io)

[英]Can't proxy request with nginx to node.js (socket.io)

Tutorials and other answers doesn't help. 教程和其他答案无济于事。 I know that thing is in nginx config, but where? 我知道那是在Nginx配置中,但是在哪里?

I have CentOS 6.5, nginx 1.4.4, node 0.10.24, socket.io.js 0.9.16 and 我有CentOS 6.5,nginx 1.4.4,节点0.10.24,socket.io.js 0.9.16和

in my_server_nginx.conf, node section: 在my_server_nginx.conf的“节点”部分中:

location ~ /node {

    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";      
    proxy_set_header Host $host;    
    proxy_redirect     off;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

}

in app.js: 在app.js中:

var io = require('/usr/lib/node_modules/socket.io/lib/socket.io').listen(3000);

in html: 在html中:

<script type="text/javascript" src="/node/socket.io/socket.io.js"></script>

in browser console: 在浏览器控制台中:

Uncaught ReferenceError: io is not defined

Direct open /node/socket.io/socket.io.js returns 直接打开/node/socket.io/socket.io.js返回

Welcome to socket.io.

In this case, '/node/socket.io/socket.io.js' is your socket root directory. 在这种情况下,“ / node / socket.io / socket.io.js”是您的套接字根目录。 and the socket.io js file will be served from within there. 并且socket.io js文件将在其中提供。 try linking to '/node/socket.io/socket.io.js/socket.io.js' 尝试链接到'/node/socket.io/socket.io.js/socket.io.js'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM