user nginx;
worker_processes 2;

events {
    use epoll;
    worker_connections 1024;
}

http {
    include conf/mime.types;
    default_type application/octet-stream;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;

    keepalive_timeout  65;

    # mongrel proxy
    upstream mongrel {
        server 127.0.0.1:8000;
        server 127.0.0.1:8001;
    }

    # rails server
    server {
        listen 80;
        server_name eveel.kicks-ass.org;
        charset off;
       
        location / {
            root /srv/www/nginx/kopa.info;
            index index.html index.htm;
        }

        # serve the /files/ catalog as static
        location ~ /public/* {
            root /srv/www/nginx;
            autoindex on;
        }
   
        # / -> first search for local index.html then go to mongrel
        location ~ ^/$ {
            if (-f /index.html) {
                rewrite (.*) /index.html last;
            }
            proxy_pass http://mongrel;
        }
    
        # rails caching: searching first for $action.html local pages
        location / {
            if (!-f $request_filename.html) {
                proxy_pass http://mongrel;
            }
            rewrite (.*) $1.html last;
        }
    
        # serve static files directly
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|html|xhtml|js|mov)$ {
            root /srv/www/nginx/kopa.info/public;
        }
    
        # resend everything else to mongrel
        location / {
            proxy_pass  http://mongrel;
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

    # php-fastcgi upstream
    upstream php {
        server unix:/tmp/php-fcgi.sock;
    }

    # php server
    server {
        listen 8080;
        server_name eveel.kicks-ass.org;
        charset off;

        # serve the /files/ catalog as static
        location ~ /public/* {
            root /srv/www/nginx;
            autoindex on;
        }

        set $_document_root /srv/www/nginx/spectrum;
        # redirect to php
        location ~ \.php$ {
                fastcgi_index index.php;
                include /etc/nginx/conf/fastcgi_params;
                root $_document_root;
                fastcgi_pass php;
        } 
    }
}
