最近有一個需求,就是需要使用 nginx 反向代理 websocket,經過查找一番資料,目前已經測試通過,本文只做一個記錄
代碼如下:
注: 看官方文檔說 Nginx 在 1.3 以后的版本才支持 websocket 反向代理,所以要想使用支持 websocket 的功能,必須升級到 1.3 以后的版本,因此我這邊是下載的 Tengine 的最新版本測試的
1.下載 tengine 最近的源碼
代碼如下:
wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz
2.安裝基礎的依賴包
代碼如下:
yum -y install pcre*
yum -y install zlib*
yum -y install openssl*
3.解壓編譯安裝
代碼如下:
tar -zxvf tengine-2.0.3.tar.gz cd tengine-2.0.3 ./configure --prefix=安裝目錄 make sudo make install
nginx.conf 的配置如下:
代碼如下:
user apps apps;
worker_processes 4; # 這個由于我是用的虛擬機,所以配置的 4 ,另外 tengine 可以自動根據CPU數目設置進程個數和綁定CPU親緣性
# worker_processes auto
# worker_cpu_affinity auto
error_log logs/error.log;
pid logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
# load modules compiled as Dynamic Shared Object (DSO)
#
#dso {
# load ngx_http_fastcgi_module.so;
# load ngx_http_rewrite_module.so;
#}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 80m;
sendfile on;
tcp_nopush on;
client_body_timeout 5;
client_header_timeout 5;
keepalive_timeout 5;
send_timeout 5;
open_file_cache max=65535 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
新聞熱點
疑難解答