Description
hi...
I follow https://medium.com/p/1778601c9e05 to try to make a demo,but when i connect to server ,it got socket init error.
nginx version: ngx_openresty/1.4.2.5
Nginx Log :
2013/09/18 00:32:13 [error] 6245#0: *3 lua entry thread aborted: runtime error: /usr/local/lualib/resty/websocket/server.lua:105: expecting zero arguments, but got 1
stack traceback:
coroutine 0:
[C]: in function 'req_sock'
/usr/local/lualib/resty/websocket/server.lua:105: in function 'new'
[string "content_by_lua"]:3: in function <[string "content_by_lua"]:1>, client: 192.168.56.1, server: ko.local.freeflare.com, request: "GET /1.0/websocket HTTP/1.1", host: "ko.local.freeflare.com"
nginx conf:
worker_processes 2;
error_log logs/error.log;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
resolver 8.8.8.8;
server_tokens off;
server_names_hash_bucket_size 128;
client_body_buffer_size 4m;
client_max_body_size 300m;
large_client_header_buffers 2 1k;
client_body_timeout 3;
client_header_timeout 3;
keepalive_timeout 5;
send_timeout 5;
sendfile on;
tcp_nopush on;
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 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_vary on;
#close lua code cache, if is product please open .
lua_code_cache off;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
lua_shared_dict haddit_shared_dict 300m;
#add websocket lib
lua_package_path "/usr/local/lualib/resty/websocket/?.lua;;";
# add firewall
init_by_lua_file conf/waf/init.lua;
access_by_lua_file conf/waf/waf.lua;
include vhosts/*.conf;
}
vhosts/yagamiko.conf
log_format yagamiko '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_cookie" $http_x_forwarded_for';
server {
listen 80 so_keepalive=2s:2s:8;
server_name ko.local.freeflare.com;
encrypted_session_key "asdfghjklqasdfghjklqasdfghjklqwe";
encrypted_session_iv "12345678123456";
encrypted_session_expires 30d;
#static file directory
location ~ ^/(static|media)/ {
root '__YAGAMI_APP_PATH_VALUE__/static';
expires 30d;
}
location /1.0/websocket {
lua_socket_log_errors off;
lua_check_client_abort on;
content_by_lua '
local server = require "resty.websocket.server"
local wb, err = server:new{
timeout = 5000, -- in milliseconds
max_payload_len = 65535,
}
if not wb then
ngx.log(ngx.ERR, "failed to new websocket: ", err)
return ngx.exit(444)
end
while true do
local data, typ, err = wb:recv_frame()
if wb.fatal then
ngx.log(ngx.ERR, "failed to receive frame: ", err)
return ngx.exit(444)
end
if not data then
local bytes, err = wb:send_ping()
if not bytes then
ngx.log(ngx.ERR, "failed to send ping: ", err)
return ngx.exit(444)
end
elseif typ == "close" then break
elseif typ == "ping" then
local bytes, err = wb:send_pong()
if not bytes then
ngx.log(ngx.ERR, "failed to send pong: ", err)
return ngx.exit(444)
end
elseif typ == "pong" then
ngx.log(ngx.INFO, "client ponged")
elseif typ == "text" then
local bytes, err = wb:send_text(data)
if not bytes then
ngx.log(ngx.ERR, "failed to send text: ", err)
return ngx.exit(444)
end
end
end
wb:send_close()
';
}
#lua_code_cache off;
location / {
#default_type text/html;
set $YAGAMI_HOME '__YAGAMI_HOME_VALUE__';
set $YAGAMI_APP_NAME '__YAGAMI_APPNAME_VALUE__';
set $YAGAMI_APP_PATH '__YAGAMI_APP_PATH_VALUE__';
#set $wdfsproxy $uri;
#load yagami
content_by_lua_file '$YAGAMI_HOME/luasrc/yagami.lua';
}
#location /weedfsproxy {
#proxy_pass http://127.0.0.1:9331/$wdfsproxy;
#proxy_pass http://127.0.0.1:9331/6,75735795edd1;
#}
#set error
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
access_log /freeflare/trunk/foundation/server/lua/yagamiko/nginx_runtime/logs/__YAGAMI_APPNAME_VALUE__.log yagamiko;
error_log /freeflare/trunk/foundation/server/lua/yagamiko/nginx_runtime/logs/__YAGAMI_APPNAME_VALUE___err.log debug;
}