2010-12-15 06:12:17 +01:00
|
|
|
# Set another default user than root for security reasons
|
|
|
|
user www www;
|
|
|
|
|
|
|
|
# As a thumb rule: One per CPU. If you are serving a large amount
|
|
|
|
# of static files, which requires blocking disk reads, you may want
|
|
|
|
# to increase this from the number of cpu_cores available on your
|
|
|
|
# system.
|
|
|
|
#
|
|
|
|
# The maximum number of connections for Nginx is calculated by:
|
|
|
|
# max_clients = worker_processes * worker_connections
|
|
|
|
worker_processes 1;
|
|
|
|
|
|
|
|
# Maximum file descriptors that can be opened per process
|
|
|
|
# This should be > worker_connections
|
|
|
|
worker_rlimit_nofile 8192;
|
|
|
|
|
|
|
|
events {
|
|
|
|
# When you need > 8000 * cpu_cores connections, you start optimizing
|
|
|
|
# your OS, and this is probably the point at where you hire people
|
|
|
|
# who are smarter than you, this is *a lot* of requests.
|
|
|
|
worker_connections 8000;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Change these paths to somewhere that suits you!
|
|
|
|
error_log logs/error.log;
|
|
|
|
pid logs/nginx.pid;
|
|
|
|
|
|
|
|
http {
|
|
|
|
# Set the mime-types via the mime.types external file
|
2011-02-01 02:06:10 +01:00
|
|
|
include nginx-mime.types;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
|
|
|
# And the fallback mime-type
|
|
|
|
default_type application/octet-stream;
|
|
|
|
|
|
|
|
# Format for our log files
|
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] $status '
|
|
|
|
'"$request" $body_bytes_sent "$http_referer" '
|
|
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
|
|
|
|
|
|
# Click tracking!
|
|
|
|
access_log logs/access.log main;
|
|
|
|
|
|
|
|
# ~2 seconds is often enough for HTML/CSS, but connections in
|
|
|
|
# Nginx are cheap, so generally it's safe to increase it
|
2011-07-07 02:11:50 +02:00
|
|
|
keepalive_timeout 20;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
|
|
|
# You usually want to serve static files with Nginx
|
|
|
|
sendfile on;
|
|
|
|
|
|
|
|
tcp_nopush on; # off may be better for Comet/long-poll stuff
|
|
|
|
tcp_nodelay off; # on may be better for Comet/long-poll stuff
|
|
|
|
|
2011-07-07 02:11:50 +02:00
|
|
|
# Enable Gzip:
|
|
|
|
gzip on;
|
2010-12-15 06:12:17 +01:00
|
|
|
gzip_http_version 1.0;
|
2011-07-07 02:11:50 +02:00
|
|
|
gzip_comp_level 5;
|
|
|
|
gzip_min_length 512;
|
|
|
|
gzip_buffers 4 8k;
|
2010-12-15 06:12:17 +01:00
|
|
|
gzip_proxied any;
|
2011-02-02 00:21:18 +01:00
|
|
|
gzip_types
|
|
|
|
# text/html is always compressed by HttpGzipModule
|
|
|
|
text/css
|
|
|
|
text/javascript
|
|
|
|
text/xml
|
|
|
|
text/plain
|
|
|
|
text/x-component
|
|
|
|
application/javascript
|
2011-08-05 15:52:04 +02:00
|
|
|
application/x-javascript
|
2011-02-02 00:21:18 +01:00
|
|
|
application/json
|
|
|
|
application/xml
|
|
|
|
application/rss+xml
|
|
|
|
font/truetype
|
|
|
|
font/opentype
|
|
|
|
application/vnd.ms-fontobject
|
|
|
|
image/svg+xml;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
2011-07-07 02:11:50 +02:00
|
|
|
# This should be turned on if you are going to have pre-compressed copies (.gz) of
|
|
|
|
# static files available. If not it should be left off as it will cause extra I/O
|
|
|
|
# for the check. It would be better to enable this in a location {} block for
|
|
|
|
# a specific directory:
|
|
|
|
# gzip_static on;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
|
|
|
gzip_disable "MSIE [1-6]\.";
|
|
|
|
gzip_vary on;
|
|
|
|
|
|
|
|
server {
|
2011-07-07 02:11:50 +02:00
|
|
|
# listen 80 default_server deferred; # for Linux
|
|
|
|
# listen 80 default_server accept_filter=httpready; # for FreeBSD
|
|
|
|
listen 80 default_server;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
|
|
|
# e.g. "localhost" to accept all connections, or "www.example.com"
|
|
|
|
# to handle the requests for "example.com" (and www.example.com)
|
2011-07-07 02:11:50 +02:00
|
|
|
# server_name www.example.com;
|
2010-12-15 06:12:17 +01:00
|
|
|
|
|
|
|
# Path for static files
|
|
|
|
root /sites/example.com/public;
|
|
|
|
|
2011-04-13 22:23:10 +02:00
|
|
|
# Custom 404 page
|
|
|
|
error_page 404 /404.html;
|
|
|
|
|
2011-05-29 03:31:20 +02:00
|
|
|
# This is pretty long expiry and assume your using
|
|
|
|
# cachebusting with query params like
|
|
|
|
# <script src="application.js?20110529">
|
|
|
|
#
|
|
|
|
# Just be careful if your using this on a frequently
|
|
|
|
# updated static site. You may want to crank this back
|
|
|
|
# to 5m which is 5 minutes.
|
|
|
|
expires 1M; # yes one month
|
2010-12-15 06:12:17 +01:00
|
|
|
|
|
|
|
# Static assets
|
2011-02-01 01:55:29 +01:00
|
|
|
location ~* ^.+\.(manifest|appcache)$ {
|
2010-12-15 06:12:17 +01:00
|
|
|
expires -1;
|
|
|
|
access_log logs/static.log;
|
|
|
|
}
|
|
|
|
|
2011-07-07 02:11:50 +02:00
|
|
|
# Set expires max on static file types (make sure you are using cache busting filenames or query params):
|
2010-12-15 06:12:17 +01:00
|
|
|
location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {
|
|
|
|
expires max;
|
2011-02-04 11:05:54 +01:00
|
|
|
access_log off;
|
2010-12-15 06:12:17 +01:00
|
|
|
}
|
2011-01-31 19:35:18 +01:00
|
|
|
|
|
|
|
# opt-in to the future
|
|
|
|
add_header "X-UA-Compatible" "IE=Edge,chrome=1";
|
|
|
|
|
2010-12-15 06:12:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|