Pau*_* T. 3 port bind http nginx node.js
我想绑定nodejs到一个网址,如下所示:http://myproject.com/nodejs/
目前,我在端口8080中有节点.
我有nginx配置:
upstream app {
server 127.0.0.1:8080;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
root /home/myproject/www;
index index.html index.htm;
server_name myproject.com;
location /nodejs/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app/;
proxy_redirect off;
}
}
Run Code Online (Sandbox Code Playgroud)
当我打开网址时,我得到:
Welcome to socket.io.
Run Code Online (Sandbox Code Playgroud)
连接还可以.
但是,当我尝试在我的网站连接时,我得到这个:
GET http://myproject.com/socket.io/1/?t=1385767934694 404 (Not Found) socket.io.js:1659
Run Code Online (Sandbox Code Playgroud)
这是我的网站连线:
var socket = io.connect('http://myproject.com/nodejs/');
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点 ?
我收到错误=/
WebSocket connection to 'ws://myproject/socket.io/1/websocket/IomP5jiBBNv8rgGYFFUS' failed: Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'
Run Code Online (Sandbox Code Playgroud)
这是我的nginx服务器端conf:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
root /home/myproject/www;
index index.html index.htm;
server_name myproject.com;
location /socket.io/ {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我不添加:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Restarting nginx: nginx: [emerg] unknown "connection_upgrade" variable
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)
我在这个链接中看到了这个内容:http://mattpatenaude.com/hosting-chatroom/
| 归档时间: |
|
| 查看次数: |
5289 次 |
| 最近记录: |