Skip to content

Instantly share code, notes, and snippets.

@markizano
Last active February 3, 2024 18:49
Show Gist options
  • Save markizano/b4ab4d9038a2ccdf84faf35573bca594 to your computer and use it in GitHub Desktop.
Save markizano/b4ab4d9038a2ccdf84faf35573bca594 to your computer and use it in GitHub Desktop.
Nginx Configuration File Sample (even logs in JSON format)
user nginx apps;
worker_processes 2;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
multi_accept on;
}
http {
#log_format extended "$http_host $remote_user@$remote_addr/$remote_port($proxy_add_x_forwarded_for, proxy=$http_proxy) $status($body_bytes_sent) \"$request\" \"$http_referer\" \"$http_user_agent\"";
log_format extended "JSON: {\"time\": \"$time_iso8601\", \"host\": \"$http_host\", \"user\": \"$remote_user\", \"remote\": \"$remote_addr:$remote_port\", \"proxy\": \"$proxy_add_x_forwarded_for\", \"status\": $status, \"response\": $body_bytes_sent, \"request\": \"$request\", \"upstream\": \"$upstream_addr\", \"t_req\": $request_time, \"t_upconn\": \"$upstream_connect_time\", \"t_upheaders\": \"$upstream_header_time\", \"t_upresponse\": \"$upstream_response_time\", \"referer\": \"$http_referer\", \"agent\": \"$http_user_agent\"}";
log_format debuged "$http_host $remote_user@$remote_addr/$remote_port($proxy_add_x_forwarded_for) $status($body_bytes_sent) \"$request\" \"$http_referer\" \"$http_user_agent\" | r=$document_root, rf=$request_filename, fsn=$fastcgi_script_name";
server_tokens off;
access_log syslog:server=127.0.0.1:514,facility=local1,severity=debug extended;
error_log syslog:server=127.0.0.1:514,facility=local1,severity=debug;
server_names_hash_bucket_size 64;
client_max_body_size 2g;
large_client_header_buffers 4 8k;
default_type application/octet-stream;
types_hash_max_size 2048;
sendfile off;
keepalive_timeout 5;
map $scheme $fastcgi_https {
default off;
https on;
}
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;
gzip_types image/png image/jpg image/jpeg image/tiff image/gif image/svg+xml;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_http_version 1.1;
send_timeout 600;
ssl_ciphers AES128+EECDH:AES128+EDH;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
add_header Strict-Transport-Security "max-age=0; includeSubdomains";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
resolver_timeout 5s;
index index.html index.htm;
include mime.types;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment