
#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;
    vhost_traffic_status_zone;
		vhost_traffic_status_filter_by_host on;

    #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;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
    gzip_vary on;
    gzip_proxied expired no-cache no-store private auth;
    gzip_disable "MSIE [1-6]\.";

    # 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;
    #    }
    #}
    # DASHBOARD server
    server {
        listen 9000 ssl;  
        server_name sctagv.schaeffler.com; 
  
        # 配置证书  
        ssl_protocols TLSv1.2 TLSv1.3; # 推荐使用的协议  
        ssl_ciphers 'HIGH:!aNULL:!MD5:!kEDH'; # 推荐的密码套件  

        ssl_prefer_server_ciphers on;  
        ssl_certificate     agvfg.pem; 
        ssl_certificate_key agvfg.key;
    
        # 前端静态资源 - 只匹配根路径
        location = / {
            root D:/dashboard/dist;
            index index.html;
            try_files $uri $uri/ /index.html;
        }
        
        # 静态资源文件（CSS, JS, 图片等）
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|json)$ {
            root D:/dashboard/dist;
            # 静态资源不需要 CORS
        }
        
        # api 代理 - 优先级高于 location /
        location /api/ {
            proxy_pass http://127.0.0.1:8080/api/;
            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;
        }
        
        # Script-api 代理
        location /script-api/ {
            proxy_pass http://127.0.0.1:8080/script-api/;
            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;
            
            # # 相同的 CORS 配置
            # add_header Access-Control-Allow-Origin "$http_origin" always;
            # add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE' always;
            # add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
            # add_header Access-Control-Allow-Credentials 'true' always;
            # add_header Access-Control-Expose-Headers 'Content-Length,Content-Range' always;
            
            # if ($request_method = 'OPTIONS') {
            #     add_header Access-Control-Allow-Origin "$http_origin";
            #     add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE';
            #     add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
            #     add_header Access-Control-Max-Age 1728000;
            #     add_header Content-Length 0;
            #     return 204;
            # }
        }
        
        location /orders {
          proxy_pass http://127.0.0.1:8088/orders;  
          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-Original-URI $request_uri;
          
          # 超时设置
          proxy_connect_timeout 60s;
          proxy_read_timeout 60s;
        } 
        
        location /robotsStatus {
          proxy_pass http://127.0.0.1:8088/robotsStatus;  
          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-Original-URI $request_uri;
          
          # 超时设置
          proxy_connect_timeout 60s;
          proxy_read_timeout 60s;
        } 

        # SPA 路由回退 - 放在最后
        location / {
            root D:/dashboard/dist;
            index index.html;
            try_files $uri $uri/ /index.html;
        }
    }

    # MAP server  
    server {  
        listen 9001 ssl;  
        server_name sctagv.schaeffler.com; 
  
        # 配置证书  
        ssl_protocols TLSv1.2 TLSv1.3; # 推荐使用的协议  
        ssl_ciphers 'HIGH:!aNULL:!MD5:!kEDH'; # 推荐的密码套件  

        ssl_prefer_server_ciphers on;  
        ssl_certificate     agvfg.pem; 
        ssl_certificate_key agvfg.key;

        location / {  
            proxy_pass http://127.0.0.1:3000;  
            proxy_set_header Host $host;  
            proxy_set_header X-Real-IP $remote_addr;  
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
        }          
    }  
	server {

        listen       443 ssl;

        server_name  sctagv.schaeffler.com;
 
        ssl_certificate     agvfg.pem;

        ssl_certificate_key agvfg.key;
 
        #access_log  ../logs/access.log  main;

 
        location / {

            proxy_pass http://127.0.0.1:8080;

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr;

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }


 
        location /wsc {

            proxy_pass http://127.0.0.1:8080/wsc;

            proxy_http_version 1.1;

            proxy_set_header Upgrade $http_upgrade;

            proxy_set_header Connection "Upgrade";

        }
 
    }

	server {

        listen       4443 ssl;

        server_name  sctagv.schaeffler.com;
 
        ssl_certificate     agvfg.pem;

        ssl_certificate_key agvfg.key;
 
        #access_log  ../logs/access.log  main;

 
        location / {

            proxy_pass http://127.0.0.1:8088;

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr;

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }


 
    }






}
