https://github.com/openresty/lua-nginx-modulephp
context: init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer., balancer_by_lua, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*nginx
value = ngx.HTTP_CONTINUE (100) (first added in the v0.9.20 release) value = ngx.HTTP_SWITCHING_PROTOCOLS (101) (first added in the v0.9.20 release) value = ngx.HTTP_OK (200) value = ngx.HTTP_CREATED (201) value = ngx.HTTP_ACCEPTED (202) (first added in the v0.9.20 release) value = ngx.HTTP_NO_CONTENT (204) (first added in the v0.9.20 release) value = ngx.HTTP_PARTIAL_CONTENT (206) (first added in the v0.9.20 release) value = ngx.HTTP_SPECIAL_RESPONSE (300) value = ngx.HTTP_MOVED_PERMANENTLY (301) value = ngx.HTTP_MOVED_TEMPORARILY (302) value = ngx.HTTP_SEE_OTHER (303) value = ngx.HTTP_NOT_MODIFIED (304) value = ngx.HTTP_TEMPORARY_REDIRECT (307) (first added in the v0.9.20 release) value = ngx.HTTP_PERMANENT_REDIRECT (308) value = ngx.HTTP_BAD_REQUEST (400) value = ngx.HTTP_UNAUTHORIZED (401) value = ngx.HTTP_PAYMENT_REQUIRED (402) (first added in the v0.9.20 release) value = ngx.HTTP_FORBIDDEN (403) value = ngx.HTTP_NOT_FOUND (404) value = ngx.HTTP_NOT_ALLOWED (405) value = ngx.HTTP_NOT_ACCEPTABLE (406) (first added in the v0.9.20 release) value = ngx.HTTP_REQUEST_TIMEOUT (408) (first added in the v0.9.20 release) value = ngx.HTTP_CONFLICT (409) (first added in the v0.9.20 release) value = ngx.HTTP_GONE (410) value = ngx.HTTP_UPGRADE_REQUIRED (426) (first added in the v0.9.20 release) value = ngx.HTTP_TOO_MANY_REQUESTS (429) (first added in the v0.9.20 release) value = ngx.HTTP_CLOSE (444) (first added in the v0.9.20 release) value = ngx.HTTP_ILLEGAL (451) (first added in the v0.9.20 release) value = ngx.HTTP_INTERNAL_SERVER_ERROR (500) value = ngx.HTTP_METHOD_NOT_IMPLEMENTED (501) value = ngx.HTTP_BAD_GATEWAY (502) (first added in the v0.9.20 release) value = ngx.HTTP_SERVICE_UNAVAILABLE (503) value = ngx.HTTP_GATEWAY_TIMEOUT (504) (first added in the v0.3.1rc38 release) value = ngx.HTTP_VERSION_NOT_SUPPORTED (505) (first added in the v0.9.20 release) value = ngx.HTTP_INSUFFICIENT_STORAGE (507) (first added in the v0.9.20 release)
Nginx log level constants
context: init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer., balancer_by_lua, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*git
ngx.STDERR ngx.EMERG ngx.ALERT ngx.CRIT ngx.ERR ngx.WARN ngx.NOTICE ngx.INFO ngx.DEBUG
print(...) 等於 ngx.log(ngx.NOTICE, ...)github
nginx 內置綁定變量 ngx.var.xxx
名稱 說明sql
$arg_name 請求中的name參數 $args 請求中的參數 $binary_remote_addr 遠程地址的二進制表示 $body_bytes_sent 已發送的消息體字節數 $content_length HTTP請求信息裏的"Content-Length" $content_type 請求信息裏的"Content-Type" $document_root 針對當前請求的根路徑設置值 $document_uri 與$uri相同; 好比 /test2/test.php $host 請求信息中的"Host",若是請求中沒有Host行,則等於設置的服務器名 $hostname 機器名使用 gethostname系統調用的值 $http_cookie cookie 信息 $http_referer 引用地址 $http_user_agent 客戶端代理信息 $http_via 最後一個訪問服務器的Ip地址。 $http_x_forwarded_for 至關於網絡訪問路徑 $is_args 若是請求行帶有參數,返回「?」,不然返回空字符串 $limit_rate 對鏈接速率的限制 $nginx_version 當前運行的nginx版本號 $pid worker進程的PID $query_string 與$args相同 $realpath_root 按root指令或alias指令算出的當前請求的絕對路徑。其中的符號連接都會解析成真是文件路徑 $remote_addr 客戶端IP地址 $remote_port 客戶端端口號 $remote_user 客戶端用戶名,認證用 $request 用戶請求 $request_body 這個變量(0.7.58+)包含請求的主要信息。在使用proxy_pass或fastcgi_pass指令的location中比較有意義 $request_body_file 客戶端請求主體信息的臨時文件名 $request_completion 若是請求成功,設爲"OK";若是請求未完成或者不是一系列請求中最後一部分則設爲空 $request_filename 當前請求的文件路徑名,好比/opt/nginx/www/test.php $request_method 請求的方法,好比"GET"、"POST"等 $request_uri 請求的URI,帶參數 $scheme 所用的協議,好比http或者是https $server_addr 服務器地址,若是沒有用listen指明服務器地址,使用這個變量將發起一次系統調用以取得地址(形成資源浪費) $server_name 請求到達的服務器名 $server_port 請求到達的服務器端口號 $server_protocol 請求的協議版本,"HTTP/1.0"或"HTTP/1.1" $uri 請求的URI,可能和最初的值有不一樣,好比通過重定向之類的
nginx api for Lua https://github.com/openresty/lua-nginx-module#nginx-api-for-lua
Nginx API for Lua Introduction ngx.arg ngx.var.VARIABLE Core constants HTTP method constants HTTP status constants Nginx log level constants print ngx.ctx ngx.location.capture ngx.location.capture_multi ngx.status ngx.header.HEADER ngx.resp.get_headers ngx.req.is_internal ngx.req.start_time ngx.req.http_version ngx.req.raw_header ngx.req.get_method ngx.req.set_method ngx.req.set_uri ngx.req.set_uri_args ngx.req.get_uri_args ngx.req.get_post_args ngx.req.get_headers ngx.req.set_header ngx.req.clear_header ngx.req.read_body ngx.req.discard_body ngx.req.get_body_data ngx.req.get_body_file ngx.req.set_body_data ngx.req.set_body_file ngx.req.init_body ngx.req.append_body ngx.req.finish_body ngx.req.socket ngx.exec ngx.redirect ngx.send_headers ngx.headers_sent ngx.print ngx.say ngx.log ngx.flush ngx.exit ngx.eof ngx.sleep ngx.escape_uri ngx.unescape_uri ngx.encode_args ngx.decode_args ngx.encode_base64 ngx.decode_base64 ngx.crc32_short ngx.crc32_long ngx.hmac_sha1 ngx.md5 ngx.md5_bin ngx.sha1_bin ngx.quote_sql_str ngx.today ngx.time ngx.now ngx.update_time ngx.localtime ngx.utctime ngx.cookie_time ngx.http_time ngx.parse_http_time ngx.is_subrequest ngx.re.match ngx.re.find ngx.re.gmatch ngx.re.sub ngx.re.gsub ngx.shared.DICT ngx.shared.DICT.get ngx.shared.DICT.get_stale ngx.shared.DICT.set ngx.shared.DICT.safe_set ngx.shared.DICT.add ngx.shared.DICT.safe_add ngx.shared.DICT.replace ngx.shared.DICT.delete ngx.shared.DICT.incr ngx.shared.DICT.lpush ngx.shared.DICT.rpush ngx.shared.DICT.lpop ngx.shared.DICT.rpop ngx.shared.DICT.llen ngx.shared.DICT.ttl ngx.shared.DICT.expire ngx.shared.DICT.flush_all ngx.shared.DICT.flush_expired ngx.shared.DICT.get_keys ngx.shared.DICT.capacity ngx.shared.DICT.free_space ngx.socket.udp udpsock:setpeername udpsock:send udpsock:receive udpsock:close udpsock:settimeout ngx.socket.stream ngx.socket.tcp tcpsock:connect tcpsock:sslhandshake tcpsock:send tcpsock:receive tcpsock:receiveany tcpsock:receiveuntil tcpsock:close tcpsock:settimeout tcpsock:settimeouts tcpsock:setoption tcpsock:setkeepalive tcpsock:getreusedtimes ngx.socket.connect ngx.get_phase ngx.thread.spawn ngx.thread.wait ngx.thread.kill ngx.on_abort ngx.timer.at ngx.timer.every ngx.timer.running_count ngx.timer.pending_count ngx.config.subsystem ngx.config.debug ngx.config.prefix ngx.config.nginx_version ngx.config.nginx_configure ngx.config.ngx_lua_version ngx.worker.exiting ngx.worker.pid ngx.worker.count ngx.worker.id ngx.semaphore ngx.balancer ngx.ssl ngx.ocsp ndk.set_var.DIRECTIVE coroutine.create coroutine.resume coroutine.yield coroutine.wrap coroutine.running coroutine.status