server {
	server_name ema.local 10.9.8.254;
	listen 10.9.8.254:443 ssl;
	ssl_certificate /opt/homebrew/etc/nginx/ca/ema.local/ema.local.crt;
	ssl_certificate_key /opt/homebrew/etc/nginx/ca/ema.local/ema.local.pem; 

	root /opt/vision/app/smt/smt_js/www;

	add_header X-Frame-Options "SAMEORIGIN";
	add_header X-XSS-Protection "1; mode=block";
	add_header X-Content-Type-Options "nosniff";

	access_log /var/log/nginx/smt.access.log;
	error_log /var/log/nginx/smt.error.log;
	
	tcp_nodelay on;
	gzip off;

	include /opt/homebrew/etc/nginx/ca/options-ssl-nginx.conf;
	ssl_dhparam /opt/homebrew/etc/nginx/ca/ssl-dhparams.pem;
	
	index index.html index.htm;

	location / {
		limit_rate 0;
		try_files $uri $uri/ /index.html;
	}

	location = /favicon.ico { access_log off; log_not_found off; }
	location = /robots.txt  { access_log off; log_not_found off; }





# SMT

	location /mes {
		alias  /opt/z1/app/www/mes;
		index  index.html index.htm;
	}

	location /smt {
		alias  /opt/z1/app/www/mes;
		index  index.html index.htm;
	}
	

	location /kanban {
                alias  /opt/z1/app/www/kanban;
                index  index.html index.htm;
        }

	location /mes/rest {
		limit_rate 0;
#		if ($request_method = 'OPTIONS') {
#			add_header 'Access-Control-Allow-Origin' '*' always;
#			add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE' always;
#			add_header 'Access-Control-Allow-Headers' '*' always;
#			add_header 'Access-Control-Max-Age' 1728000 always;
#			add_header 'Content-Length' 0;
#			add_header 'Content-Type' 'text/plain; charset=utf-8';
#			return 204;
#		}
		if ($request_method ~* '(GET|POST|DELETE|PUT)') {
			add_header 'Access-Control-Allow-Origin' '*' always;
		}
		proxy_http_version 1.1;
#		proxy_set_header X-Real-IP $remote_addr;
#		proxy_set_header Upgrade $http_upgrade;
#		proxy_set_header Connection "upgrade";
#		proxy_set_header Origin "";

		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-Forwarded-Proto $scheme;

		rewrite ^/mes/rest(.*)$ $1 break;
		proxy_pass http://localhost:5210;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}

	
	location /mes/ws {
		limit_rate 0;

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/mes/ws(/.*)$ $1 break;
		proxy_pass http://127.0.0.1:5211/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}


	location /smt/ws {
		limit_rate 0;

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/mes/ws(/.*)$ $1 break;
		proxy_pass http://127.0.0.1:5211/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}




	location /mes/ws/session {
		limit_rate 0;

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/smt/ws/session(/.*)$ $1 break;
		proxy_pass http://127.0.0.1:5212/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;

	}
	location /smt/ws/session {
		limit_rate 0;

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/smt/ws/session(/.*)$ $1 break;
		proxy_pass http://127.0.0.1:5212/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;

	}


#	location /smt/ws/err {
#		limit_rate 0;
#
#		proxy_http_version 1.1;
#		proxy_set_header X-Real-IP $remote_addr;
#		proxy_set_header Upgrade $http_upgrade;
#		proxy_set_header Connection "upgrade";
#		proxy_set_header Origin "";
#
#		rewrite ^/smt/ws/err(/.*)$ $1 break;
#
#		proxy_pass http://127.0.0.1:7913/;
#		proxy_send_timeout 300s;
#		proxy_read_timeout 300s;
#	}













# Rack



# Client

	location /client {
		alias  /opt/waixing/cloud/client/www;
		index  index.html index.htm;
	}
	
	location /client/rest {
		limit_rate 0;
		if ($request_method ~* '(GET|POST|DELETE|PUT)') {
			add_header 'Access-Control-Allow-Origin' '*' always;
		}
		proxy_http_version 1.1;

		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-Forwarded-Proto $scheme;

		rewrite ^/client/rest(.*)$ $1 break;
		proxy_pass http://localhost:7810;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}

	
	location /client/ws/api {
		limit_rate 0;

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/client/ws/api(/.*)$ $1 break;
		proxy_pass http://127.0.0.1:7811/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}



# Stencil

	location /stencil {
		alias  /opt/waixing/app/stencil/www;
		index  index.html index.htm;
	}

	location /stencil/rest {
		limit_rate 0;
		if ($request_method ~* '(GET|POST|DELETE|PUT)') {
			add_header 'Access-Control-Allow-Origin' '*' always;
		}
		proxy_http_version 1.1;

		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-Forwarded-Proto $scheme;

		rewrite ^/stencil/rest(.*)$ $1 break;
		proxy_pass http://localhost:7710;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}


	location /stencil/ws/api {
		limit_rate 0;

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/client/ws/api(/.*)$ $1 break;
		proxy_pass http://127.0.0.1:7711/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}


	location /cpp/ws/api {
		limit_rate 0;

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/api(/.*)$ $1 break;
		proxy_pass http://10.9.8.13:6211/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}


# OCR
	location /entity/ocr/ws/api {
		limit_rate 0;
		
		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";

		rewrite ^/entity/ocr/ws/api(/.*)$ $1 break;

		proxy_pass http://localhost:7121/;
		#proxy_pass http://10.9.8.11:7121/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}





	location /printer {
		limit_rate 0;
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' '*' always;
			add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE' always;
			add_header 'Access-Control-Allow-Headers' '*' always;
			add_header 'Access-Control-Max-Age' 1728000 always;
			add_header 'Content-Length' 0;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			return 204;
		}
		if ($request_method ~* '(GET|POST|DELETE|PUT)') {
			add_header 'Access-Control-Allow-Origin' '*' always;
		}

		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Origin "";
		proxy_pass http://localhost:5905/;
		proxy_send_timeout 300s;
		proxy_read_timeout 300s;
	}


	


	location ~ /.well-known {
		allow all;
	}

	
	location ~ /\.ht {
		deny all;
	}

}
