
#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;
    
    # Change the upload max request body size to 20M at global
    client_max_body_size 20m;

    #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       3000;
        server_name  0.0.0.0;
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 16 64k;
        gzip_http_version 1.1;
        gzip_comp_level 6;
        gzip_types text/plain application/javascript text/css application/xml;
        gzip_vary on;

        #root /Users/ouka/cloudops;
        #error_page  404    /index.html;

        # Change the upload max request body size to 20M at this range
        client_max_body_size 20m;

        #charset koi8-r;

        add_header X-XSS-Protection "1";
        add_header X-Frame-Options "SAMEORIGIN";
        #add_header Content-Security-Policy "default-src self; script-src unsafe-inline";
        add_header X-Content-Type-Options "nosniff";

        #access_log  logs/host.access.log  main;

        location / {
          #root /Users/ouka/cloudops;
          #index index.html index.htm;
          proxy_pass http://localhost:4200;
          proxy_cookie_path / "/; secure; SameSite=Lax";
        }

        location /security/login {
          proxy_pass http://localhost:7000;
        }

        location /security/logout {
          proxy_pass http://localhost:7000;
        }

        location /token/check {
          proxy_pass http://localhost:7000;
        }

        location /v1/relational/assets {
          proxy_pass http://localhost:7030;
        }

        location /platform/version {
          proxy_pass http://localhost:7000;
        }

        location /v1/patrolrecords {
          proxy_pass http://localhost:7010;
        }

        location /v1/standingbook {
          proxy_pass http://localhost:7010;
        }

        location /v1/resource {
          proxy_pass http://localhost:7010;
        }

        location /themes {
          proxy_pass http://localhost:9980;
        }

        location ^~ /v1/config {
          proxy_pass http://localhost:5433;
        }
       
        location ^~ /v1/workflow {
          proxy_pass http://localhost:5433;
        }

        location ^~ /v1/messages {
          proxy_pass http://localhost:5433;
        }

       location /cloudops-state/ {
         # /socket.io/ is the default socket.io server serving path
         # so only proxy socket.io request, without expose mbus:/v1/... pages
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_read_timeout 600s;
         proxy_pass http://localhost:7012;
         #proxy_pass http://192.168.12.205:7012;
       }

       location /socket.io/ { 
         # /socket.io/ is the default socket.io server serving path
         # so only proxy socket.io request, without expose mbus:/v1/... pages
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_pass http://localhost:39092;
         #proxy_pass http://192.168.12.205:39092;
       }

       location /sockjs-node/ {
         # /socket.io/ is the default socket.io server serving path
         # so only proxy socket.io request, without expose mbus:/v1/... pages
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_pass http://localhost:4200;
       }
       
       location /ws {
         # /socket.io/ is the default socket.io server serving path
         # so only proxy socket.io request, without expose mbus:/v1/... pages
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_pass http://localhost:4200;
       }

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

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    server {
        listen      3201;
        server_name 0.0.0.0;

        # Change the upload max request body size to 20M at this range
        client_max_body_size 20m;

        location / {
          proxy_pass http://localhost:4201;
        }

        location /v1/relational/assets {
          proxy_pass http://localhost:7030;
        }

       location /socket.io/ { 
         # /socket.io/ is the default socket.io server serving path
         # so only proxy socket.io request, without expose mbus:/v1/... pages
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_pass http://localhost:39092;
       }

       location /cloudops-state/ {
         # /socket.io/ is the default socket.io server serving path
         # so only proxy socket.io request, without expose mbus:/v1/... pages
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_pass http://localhost:7012;
       }

       location /sockjs-node/ {
         # /socket.io/ is the default socket.io server serving path
         # so only proxy socket.io request, without expose mbus:/v1/... pages
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_pass http://localhost:4200;
       }
    }
}
