Skip to content
bibleforge edited this page Jan 14, 2012 · 10 revisions
# 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  4;

# Change these paths to somewhere that suits you!
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

# Change these paths to somewhere that suits you!
#pid        logs/nginx.pid;

# 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;
}


http {
    # Set the mime-types via the mime.types external file.
    #include       mime.types;
    # And the fallback mime-type
    default_type  application/octet-stream;

    # Format for our log files
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    
    # Click tracking!
    access_log  logs/access.log  main;
    
    # 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
    
    # ~2 seconds is often enough for HTML/CSS, but connections in
    # Nginx are cheap, so generally it's safe to increase it
    #keepalive_timeout  0;
    keepalive_timeout  65;
    
    # Enable Gzip:
    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 5;
    gzip_min_length 512;
    gzip_buffers 4 8k;
    gzip_proxied any;
    gzip_types
        # text/html is always compressed by HttpGzipModule
        text/css
        text/javascript
        text/xml
        text/plain
        text/x-component
        application/javascript
        application/json
        application/xml
        application/rss+xml
        font/truetype
        font/opentype
        application/vnd.ms-fontobject
        image/svg+xml;
    
    # Cache files for one month.
    expires 1M;

    # 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;
    
    gzip_disable        "MSIE [1-6]\.";
    gzip_vary           on;
    
    
    server {
        # or listen 80 default_server;
        listen       80;
        # e.g. "localhost" to accept all connections, or "www.example.com"
        # to handle the requests for "example.com" (and www.example.com)
        server_name  localhost;

        #access_log  logs/host.access.log  main;

        root   /var/www/;
        index  index.html index.htm;
        
        # Make sure all URLs with _escaped_fragment_ are sent to page_creator.php.
        if ($args ~ _escaped_fragment_) {
            rewrite ^ /page_creator.php;
        }
        
        # Redirect queries to page_creator.php which creates the non-JS version and redirects to the full version if applicable.
        #NOTE: The equals sign allows the script to send the proper header (i.e., 200 or 301).
        error_page  404 = /page_creator.php;
        
        # Enable PHP.
        # Suggested steps for setting up fastcgi PHP:
        #     apt-get install libfcgi0ldbl
        #     cd /etc/default/
        #     sudo wget -O php-fastcgi http://www.mensk.com/uploads/php-fastcgi.txt
        #     cd /etc/init.d/
        #     sudo wget -O php-fastcgi http://www.mensk.com/uploads/php-fastcgi.rc.txt
        #     sudo chmod +x php-fastcgi
        #     sudo /usr/sbin/update-rc.d -f php-fastcgi defaults
        #     sudo /etc/init.d/php-fastcgi start
        location ~ \.php$ {
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include         fastcgi_params;
                fastcgi_intercept_errors off;
        }
    }
}
Clone this wiki locally