
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

	#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  logs/access.log  main;

    sendfile        on;
	#tcp_nopush     on;

	#keepalive_timeout  0;
	keepalive_timeout  65;

	#gzip  on;
<#list services.keySet() as key>

    server {
        listen       ${key};
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

<#list services[key] as mapping>
<#if mapping.type="HTTP">
		location ${mapping.context} {
			proxy_pass              ${mapping.location};
			proxy_set_header        Host $remote_addr:$server_port;
			proxy_set_header        X-Real-IP $remote_addr;
			proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header        request_uri $scheme://$remote_addr:$server_port$request_uri;
			proxy_set_header        proxy_context ${mapping.context};
			index  index.html index.htm index.jsp index.do;
		}
<#elseif mapping.type="FILE">
		location ${mapping.context} {
			root ${mapping.location};
			index index.html index.htm;
			autoindex on;
		}
</#if>
</#list>

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
</#list>
}
