Browse Source

日志记录 referer;配置文件增加注释

zjcqoo 6 years ago
parent
commit
630b4e9d79
3 changed files with 16 additions and 3 deletions
  1. 1 1
      api.conf
  2. 3 0
      lua/http-dec-req-hdr.lua
  3. 12 2
      nginx.conf

+ 1 - 1
api.conf

@@ -9,7 +9,7 @@ proxy_set_header      Connection  $http_connection;
 
 set                   $_url       '';
 set                   $_ver       '';
-
+set                   $_ref       '';
 
 location = /preflight {
   internal;

+ 3 - 0
lua/http-dec-req-hdr.lua

@@ -21,6 +21,9 @@ for k, v in pairs(hdrs) do
   elseif k == 'ext' then
     extHdrs = require('cjson').decode(v)
   else
+    if k == 'referer' then
+      ngx.var._ref = v
+    end
     ngx.req.set_header(k, v)
   end
 

+ 12 - 2
nginx.conf

@@ -7,6 +7,8 @@ http {
     listen                8080;
     include               api.conf;
   }
+
+  # https://nginx.org/en/docs/http/ngx_http_core_module.html
   resolver                1.1.1.1 ipv6=off;
   resolver_timeout        10s;
 
@@ -15,26 +17,31 @@ http {
   server_tokens           off;
   underscores_in_headers  on;
 
+  # https://nginx.org/en/docs/http/ngx_http_ssl_module.html
   ssl_protocols           TLSv1.2 TLSv1.3;
   ssl_ciphers             TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-256-GCM-SHA384:TLS13-AES-128-GCM-SHA256:EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
   ssl_session_cache       shared:SSL:30m;
   ssl_session_timeout     1d;
   ssl_prefer_server_ciphers on;
 
+  # https://nginx.org/en/docs/http/ngx_http_limit_req_module.html
   limit_req_log_level     warn;
   limit_req_zone          $binary_remote_addr zone=reqip:16m rate=100r/s;
   limit_req               zone=reqip burst=200 nodelay;
 
+  # https://nginx.org/en/docs/http/ngx_http_log_module.html
   # separated by tab (\t)
   log_format              log_proxy escape=none
     '$time_iso8601	$_origin_id	$_ver	$remote_addr	'
     '$upstream_cache_status	$request_time	'
     '$request_length	$bytes_sent	'
-    '$request_method $_url	$status	$upstream_http_access_control_allow_origin	'
-    '$http_user_agent'
+    '$request_method	$_url	$status	$upstream_http_access_control_allow_origin	'
+    '$http_user_agent	$_ref'
   ;
   access_log              logs/proxy.log log_proxy buffer=64k flush=1s;
 
+  # https://nginx.org/cn/docs/http/ngx_http_proxy_module.html
+  # 1MB = 8000key
   proxy_cache_path        cache
     levels=1:2
     keys_zone=my_cache:32m
@@ -50,6 +57,8 @@ http {
   proxy_busy_buffers_size 64k;
   proxy_send_timeout      10s;
 
+  # https://github.com/openresty/lua-nginx-module
+
   # traffic statistics
   lua_shared_dict         traff   16k;
 
@@ -63,6 +72,7 @@ http {
   }
 }
 
+# https://nginx.org/en/docs/ngx_core_module.html
 events {
   worker_connections      4096;
 }