Skip to content

Instantly share code, notes, and snippets.

@ZachOrr
Last active December 27, 2015 13:29
Show Gist options
  • Save ZachOrr/7334217 to your computer and use it in GitHub Desktop.
Save ZachOrr/7334217 to your computer and use it in GitHub Desktop.
user www-data;
# number of single-threaded process Nginx will spawn
# Set to # of CPU cores - Nginx won't benefit from anything more than that
worker_processes 4;
pid /var/run/nginx.pid;
# Number of file descriptors used for Nginx. This is set in the OS with 'ulimit -n 200000'
# or using /etc/security/limits.conf
worker_rlimit_nofile 200000;
events {
# How many clients can be served per worker process
# max clients = worker_connections * worker_processes
# max clients is limited by the number of socket connections available on the system (~64k)
worker_connections 2048;
# Try to accept as many connections as possible after nginx gets notification about a new connection
# Warning: may flood worker connections if set too low
multi_accept on;
# Optimized to serve many clients with each thread
use epoll;
}
http {
# Copy data between one file descriptor to another from within the kernel
# Faster than doing a read() and a write(), so it's better for performance
sendfile on;
# Nginx will send all the headers in one packet
# Faster than sending them one by one
tcp_nopush on;
# Nginx won't buffer the data sent - this is good for small data bursts in real time
tcp_nodelay on;
# Disable access logs to increase speed by reducing disk IO
# AKA, yolo
access_log off;
# only log critical errors
error_log /var/log/nginx/error.log crit;
# Our timeout for connections in seconds
keepalive_timeout 10;
# Number of requests client can make over keep-alive
keepalive_requests 100000;
# Allow the server to close connection on non responding client - this will free up memory
reset_timedout_connection on;
# Sets the read timeout for the request body from client (seconds)
client_body_timeout 10;
# If a client stops responding, free up memory -- default 60
send_timeout 2;
# Include possible MIME types for Nginx
include /etc/nginx/mime.types;
# Set our default MIME type to be HTML
default_type text/html;
# Set the default charset to be UTF-8 in our header
charset UTF-8;
# Performance improvements for the previous two explained here http://webmasters.stackexchange.com/questions/18504/character-set-not-specified-in-http-headers-error
# gzip our data so we reduce the amount of data we need to send
gzip on;
# disable for IE6 or less
gzip_disable "msie6";
# enable compression for all requests
gzip_proxied any;
# shorter than 1000 bytes won't be compressed
gzip_min_length 1000;
# gzip compression level (1-9, 9 being the slowest but most compressed)
# 6 is a good middle ground for us
gzip_comp_level 6;
# set the types of data to gzip - feel free to add more
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# cache informations about file descriptors, frequently accessed files
# can boost performance, but you need to test those values
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
##
# Virtual Host Configs
# aka our settings for specific servers
##
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