Permalink
Browse files

Improved nginx.conf and added comments

Stole some of the comments and configuration from the Nginx example
configuration shipped with "Unicorn". http://unicorn.bogomips.org/
  • Loading branch information...
1 parent 2502c9f commit 46f54a5144339bfb27283dd94f02948160f8c0a0 @sirupsen committed Oct 21, 2010
Showing with 43 additions and 17 deletions.
  1. +43 −17 nginx.conf
View
@@ -1,27 +1,49 @@
+# Default Nginx user for security reasons
user www www;
-worker_processes 5;
-error_log logs/error.log;
-pid logs/nginx.pid;
+
+# You generally only need one worker, unless you're serving
+# large amounts of static files which require blocking disk reads
+worker_processes 1;
+
worker_rlimit_nofile 8192;
events {
- worker_connections 4096;
+ worker_connections 1024; # Increase if you have *a lot* of clients
+ accept_mutex off; # "on" if you have worker_processes > 1
+ # use epoll; # enable for Linux 2.6+
+ # use kqueue; # enable for *BSD (FreeBSD, OS X, ..)
}
+# Change these to somewhere that suits you
+error_log logs/error.log;
+pid logs/nginx.pid;
+
http {
+ # Set the mime-types
include mime.types;
+
+ # 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;
- keepalive_timeout 65;
+ # ~2 seconds is often enough for HTML/CSS, but connections in
+ # Nginx are cheap, so generally it's safe to increase it
+ keepalive_timeout 5;
+ # You usually want to serve static files with Nginx
sendfile on;
- tcp_nopush on;
- tcp_nodelay off;
+ tcp_nopush on; # off may be better for Comet/long-poll stuff
+ tcp_nodelay off; # on may be better for Comet/long-poll stuff
+
+ # Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
@@ -31,38 +53,42 @@ http {
gzip_types text/html text/plain text/xml application/xml application/xml+rss text/css text/javascript application/javascript application/json;
gzip_static on;
-
+
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
server {
- listen 80 default deferred;
- server_name example.com;
- expires 1M;
+ # listen 80 default deferred; # for Linux
+ # listen 80 default accept_filter=httpready; # for FreeBSD
+ listen 80 default;
+
+ server_name _;
+ # Path for static files
root /sites/example.com/public;
- #static assets
- location ~* ^.+\.(manifest)$ {
+ expires 1M;
+
+ # Static assets
+ location ~* ^.+\.(manifest)$ {
expires -1D;
root /sites/example.com/public;
access_log logs/static.log;
}
+
location ~* ^.+\.(ico|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
- # only set expires max IFF the file is a static file and exists
+ # Only set expires max IFF the file is a static file and exists
if (-f $request_filename) {
expires max;
root /sites/example.com/public;
access_log logs/static.log;
}
}
-
}
+
server {
server_name www.example.com;
rewrite ^(.*) http://example.com$1 permanent;
}
-
}
-

0 comments on commit 46f54a5

Please sign in to comment.