If you want to know how to develop a websocket server, refer to the code in the 't/ngx_websocket_echo_module.c' .
$
$ git clone https://github.com/nginx/nginx.git
$
$ git clone https://github.com/im-pingo/nginx-websocket-module.git
$
$ cd nginx
$
$ ./auto/configure --add-module=../nginx-websocket-module --add-module=../nginx-websocket-module/t
$
$ sudo make && sudo make install
$
-
syntax : websocket [any]
-
context: location
The switch of websocket service has no args
websocket out_queue=[num] message_length=[num] frame_length=[num] ping_interval=[time] timeout=[time];
- syntax: out_queue=[num] (default 512)
- context: websocket's arg
Number of out queue
- syntax: message_length=[num] (default 4096000 bytes)
- context: websocket's arg
Max length of websocket message
- syntax: ping_interval=[msec] (default 5000ms)
- context: websocket's arg
Time interval between pings
- syntax: timeout=[msec] (default 15000ms)
- context: websocket's arg
receive timeout
- syntax: websocket_echo [no args]
- context: location
The server responses the data it received
websocket_echo;
daemon on;
master_process on;
#user nobody;
worker_processes 1;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
# use wss(ssl)
listen 443 ssl;
ssl_certificate /usr/local/nginx/key/im-pingo.crt;
ssl_certificate_key /usr/local/nginx/key/im-pingo.key;
server_name localhost;
location /im-pingo {
websocket out_queue=512 message_length=4096000 ping_interval=5000ms timeout=15s;
websocket_echo;
}
}
}