nginx: [emerg] /etc/nginx/nginx.conf:41 中未知的指令“lua_shared_dict”

nginx: [emerg] /etc/nginx/nginx.conf:41 中未知的指令“lua_shared_dict”

我的 nginx.conf 檔案中的程式碼:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
# remote the escape char if you are going to use this config
include /etc/nginx/modules-enabled/\*.conf;

events {
  worker_connections 768;
}

http {

  # basic config
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  # ssl config
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
  ssl_prefer_server_ciphers on;

  # logging config
  log_format custom   '$remote_addr - $remote_user [$time_local] '
                      '"$request" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';

  access_log /var/log/nginx/access.log custom;
  error_log /var/log/nginx/error.log;

  # gzip
  gzip on;

  # virtual host config
  include /etc/nginx/conf.d/*.conf;
#  include /etc/nginx/sites-enabled/*;

  lua_shared_dict prometheus_metrics 10M;
  lua_package_path "/home/kunal/Documents/nginx-lua-prometheus/?.lua;;";
  init_worker_by_lua_block {
   prometheus = require("prometheus").init("prometheus_metrics")
   metric_requests = prometheus:counter(
   "nginx_http_requests_total", "Number of HTTP requests", {"host", "status"})
   metric_latency = prometheus:histogram(
   "nginx_http_request_duration_seconds", "HTTP request latency", {"host"})
   metric_connections = prometheus:gauge(
   "nginx_http_connections", "Number of HTTP connections", {"state"})
 }
  log_by_lua_block {
   metric_requests:inc(1, {ngx.var.server_name, ngx.var.status})
   metric_latency:observe(tonumber(ngx.var.request_time), {ngx.var.server_name})
 }

有什麼建議嗎,程式碼有什麼問題嗎?

相關內容