{% set port=port or 8081 %}
pid {{ working_dir }}/nginx.pid;
error_log {{ working_dir }}/error.log;
worker_processes  1;
daemon off;
events { worker_connections  1024; }
http {
    include /etc/nginx/mime.types;
    include {{ working_dir }}/sites-enabled/*;
    server_names_hash_max_size 512;
    server_names_hash_bucket_size 256;
    client_max_body_size 300M;
    index index.html;
    server_tokens off;
    log_format full '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" $request_time';
    access_log {{ working_dir }}/access.log full;
    error_log {{ working_dir }}/error.log;
    client_body_temp_path {{ working_dir }};
    fastcgi_temp_path {{ working_dir }};

    gzip on;
    gzip_types text/css text/plain application/xml application/json application/javascript;

    proxy_temp_path {{ working_dir }};
    proxy_read_timeout 600;
    proxy_connect_timeout 600;
    proxy_set_header X-Forwarded-Host $host;

    {% for site in sites %}
    server {
        listen 127.0.0.1:{{ port }};
        server_name ~^{{ site.domain }}[-.].*$;
        location / { proxy_pass http://127.0.0.1:{{ site.port }}; }
        location /longpolling { proxy_pass http://127.0.0.1:{{ site.lp_port }}; }
        error_log {{ working_dir }}/error.log;
    }
    {% endfor %}

    server {
        listen 127.0.0.1:{{ port }} default_server;
        server_name "";
        return 404;
    }
}
