我试图让nginx从端口80上的目录提供websockets,而不是在node.js正在侦听的端口上的根域。
直接连接到端口工作,但试图通过nginx配置中指定的目录连接,我一直从浏览器获得代码502,使用curl时获得代码301。
我的nginx服务器配置如下:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /www;
index index.html index.htm index.php;
server_name my_ip;
location /smth-chat/ {
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://127.0.0.1:3335;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
try_files $uri $uri/ =404;
}
location /something-something/ {
try_files $uri $uri/ /something-something/index.php?q=$uri&$args;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
my_ip/something-something/chat提供一个带有套接字的HTML页面。IO聊天,试图连接到my_ip/smth-chat通过websocket(强制在套接字)。io设置).
在我的nginx error.log中有一个条目如下:
2015/09/07 17:42:15 [error] 19277#0: *264 upstream prematurely closed connection while reading response header from upstream, client: some_ip, server: my_ip, request: "GET /smth-chat/?EIO=3&transport=websocket HTTP/1.1", upstream: "http://127.0.0.1:3335/smth-chat/?EIO=3&transport=websocket", host: "my_ip"
客户端套接字。IO初始化:
var socket = io('http://my_ip', {
path: '/smth-chat',
transports: ['websocket']
});
我做错了什么?
你的问题是你的nginx配置允许连接到/en
,它应该只允许/en/
。看看这个。
nginx.conf中正确的代理路径