在开发http://mqtt.phodal.com/使用Socket.io的时候,本地是没什么问题,但是发现到服务器上后就不行了,看了看当前版本的Nginx是支持的,网上搜索了下看到了方案。
在配置中添加下面的内容:
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
最后我的配置如下所示:
server {
listen 80;
server_name mqtt.phodal.com;
add_header Cache-Control "max-age=600";
location / {
etag on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_redirect off;
proxy_pass http://127.0.0.1:3000;
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
顺便又更新了一下NGINX,有强迫症真伤不起。
配置记录一下:
./configure --user=www --group=www --add-module=../nginx_tcp_proxy_module --add-module=../ngx_pagespeed-1.9.32.3-beta --prefix=/usr/local/nginx --with-pcre --with-http_spdy_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-ipv6
围观我的Github Idea墙, 也许,你会遇到心仪的项目