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

    server {
            listen                          8888;
            server_name                     dev-platform-proxy;
            
            #set $allowOriginSite http://127.0.0.1:3000;
            set  $allowOriginSite *;

            gzip                            on;
            gzip_min_length                 1000;
            gzip_proxied                    expired no-cache no-store private auth;
            underscores_in_headers          on;
            proxy_pass_request_headers      on;
            proxy_pass_header  Set-Cookie;

            location /alfresco/ {
                proxy_pass  http://localhost:8080/;
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass_header  Set-Cookie;

                if ($request_method = 'OPTIONS') {
                    more_set_headers 'Access-Control-Allow-Origin: $allowOriginSite';
                    #
                    # Om nom nom cookies
                    #
                    more_set_headers 'Access-Control-Allow-Credentials: true';
                    more_set_headers 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS';
                    #
                    # Custom headers and headers various browsers *should* be OK with but aren't
                    #
                    more_set_headers 'Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Content-Range, Content-Disposition, Content-Description, X-CSRF-TOKEN, Authorization';
                    #
                    # Tell client that this pre-flight info is valid for 20 days
                    #
                    more_set_headers 'Access-Control-Max-Age: 1728000';
                    more_set_headers 'Content-Type: text/plain charset=UTF-8';
                    more_set_headers 'Content-Length 0';
                    return 204;
                 }
            }

            location /activiti/ {
                proxy_pass  http://localhost:9999/;
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass_header  Set-Cookie;
                proxy_pass_request_headers      on;

                if ($request_method = 'OPTIONS') {
                    more_set_headers 'Access-Control-Allow-Origin: $allowOriginSite';
                    #
                    # Om nom nom cookies
                    #
                    more_set_headers 'Access-Control-Allow-Credentials: true';
                    more_set_headers 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS';
                    #
                    # Custom headers and headers various browsers *should* be OK with but aren't
                    #
                    more_set_headers 'Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Content-Range, Content-Disposition, Content-Description, X-CSRF-TOKEN, Authorization';
                    #
                    # Tell client that this pre-flight info is valid for 20 days
                    #
                    more_set_headers 'Access-Control-Max-Age: 1728000';
                    more_set_headers 'Content-Type: text/plain charset=UTF-8';
                    more_set_headers 'Content-Length 0';
                    return 204;
                 }

                 if ($request_method = 'POST') {
                    more_set_headers 'Access-Control-Allow-Origin: $allowOriginSite';
                    more_set_headers 'Access-Control-Allow-Credentials: true';
                    more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE';
                    more_set_headers 'Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Content-Range, Content-Disposition, Content-Description, X-CSRF-TOKEN, Authorization';
                 }
            }

            location / {
                proxy_pass  http://localhost:3000/;
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header        Host             $host;
                proxy_set_header        X-Real-IP        $remote_addr;
                proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header        X-NginX-Proxy    true;
                proxy_pass_header  Set-Cookie;
                proxy_pass_request_headers      on;
            }
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    #include servers/*;
}
