user  app;
worker_processes  auto;

error_log  /var/log/ngnix_error.log info;
#error_log /dev/stdout info;

pid        /var/run/nginx.pid;
#daemon off;

events {
    worker_connections  1024;
    multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_tokens off;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /dev/stdout main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    reset_timedout_connection on;

    proxy_connect_timeout  300s;
    proxy_send_timeout  300s;
    proxy_read_timeout  300s;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300;

    resolver 127.0.0.11;

    upstream backend {
        server phraseanet:9000;
    }

    server {
        listen       80;
        server_name  localhost;
        error_log    on;
        access_log   on;
        root         /var/alchemy/Phraseanet/www;

        index        index.php;

        location /api {
            rewrite ^(.*)$ /api.php/$1 last;
        }

        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ @rewriteapp;
        }

        location @rewriteapp {
            rewrite ^(.*)$ /index.php/$1 last;
        }

        # PHP scripts -> PHP-FPM server listening on 127.0.0.1:9000
        location ~ ^/(index|index_dev|api)\.php(/|$) {
            fastcgi_pass   backend;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ ^/(status|ping)$ {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_pass backend;
        }
    }
}
