1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| cat > /data/openresty/nginx/nginx.conf << 'EOF' user nobody; worker_processes auto;
pcre_jit on;
error_log logs/error.log;
events { worker_connections 4096; }
http { include mime.types; default_type application/octet-stream;
lua_package_path "/usr/local/openresty/lualib/skywalking-nginx-lua/?.lua;/usr/local/openresty/lualib/nginx-lua-prometheus/?.lua;;";
lua_shared_dict tracing_buffer 100M; lua_shared_dict prometheus_metrics 100M;
init_worker_by_lua_block { local metadata_buffer = ngx.shared.tracing_buffer metadata_buffer:set('serviceName', 'Openresty-test') metadata_buffer:set('serviceInstanceName', 'ccms-credit-front01-test') metadata_buffer:set('includeHostInEntrySpan', false) require("skywalking.util").set_randomseed() require("skywalking.client"):startBackendTimer("http://3.1.101.39:12800") skywalking_tracer = require("skywalking.tracer");
prometheus = require("prometheus").init("prometheus_metrics") metric_requests = prometheus:counter("nginx_http_requests_total", "Number of HTTP requests", {"server_name", "status"}) metric_latency = prometheus:histogram("nginx_http_request_duration_seconds", "HTTP request latency", {"server_name"}) metric_connections = prometheus:gauge("nginx_http_connections", "Number of HTTP connections", {"state"}) metric_requests_uri = prometheus:counter("nginx_http_requests_uri_total", "Number of HTTP requests_uri", {"server_name", "port", "uri", "status", "method"}) }
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}) metric_requests_uri:inc(1, {ngx.var.server_name,ngx.var.server_port,ngx.var.document_uri, ngx.var.status, ngx.var.request_method}) }
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
log_format json '{"@timestamp":"$time_iso8601",' '"host":"$hostname",' '"server_ip":"$server_addr",' '"client_ip":"$remote_addr",' '"xff":"$http_x_forwarded_for",' '"domain":"$host",' '"url":"$uri",' '"referer":"$http_referer",' '"args":"$args",' '"upstreamtime":"$upstream_response_time",' '"responsetime":"$request_time",' '"request_method":"$request_method",' '"status":"$status",' '"size":"$body_bytes_sent",' '"request_length":"$request_length",' '"protocol":"$server_protocol",' '"upstreamhost":"$upstream_addr",' '"file_dir":"$request_filename",' '"http_user_agent":"$http_user_agent"' '}';
access_log logs/access.log json;
client_body_temp_path /var/run/openresty/nginx-client-body; proxy_temp_path /var/run/openresty/nginx-proxy; fastcgi_temp_path /var/run/openresty/nginx-fastcgi; uwsgi_temp_path /var/run/openresty/nginx-uwsgi; scgi_temp_path /var/run/openresty/nginx-scgi;
sendfile on;
keepalive_timeout 65;
fastcgi_buffer_size 128k; fastcgi_buffers 8 128k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k;
client_header_buffer_size 128k; client_body_buffer_size 1m;
underscores_in_headers on; include /etc/nginx/conf.d/*.conf;
} include /etc/nginx/upstream/*.conf; EOF
|