error_log /var/log/nginx/error.log warn;
pid /var/log/nginx/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include /etc/nginx/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" "$upstream_addr"';
    access_log /var/log/nginx/access.log main;
    sendfile on;
    client_max_body_size 100M;
    server {
        server_name bkunyun.com www.bkunyun.com;
        listen 20000 ssl http2;
        ssl_certificate /cert/bkunyun.com.pem;
        ssl_certificate_key /cert/bkunyun.com.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        root /var/www;
        index index.html index.htm;
        resolver 127.0.0.11 valid=10s;
        location / {
            try_files $uri /v3/index.html;
            index /v3/index.html;
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        }

        location ^~ /v3/ {
            try_files $uri /v3/index.html
            index /v3/index.html;
        }

        location ^~ /accounts/ {
            set $accountservice "http://account-service:6000";
            proxy_pass $accountservice;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location ^~ /uaa/ {
            set $authservice "http://auth-service:5000";
            proxy_pass $authservice;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location ^~ /intelligroup/ {
            set $intelliservice "http://intelligroup-service:8000";
            proxy_pass $intelliservice;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location ^~ /vps/ {
            set $intellivps "http://intelligroup-vps:10000";
            proxy_pass $intellivps;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location /zhihu-xg/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_pass https://xg.zhihu.com/;
        }
        location ^~ /c3app/ {
            set $c3app "http://c3-app:6600";
            proxy_pass $c3app;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location ^~ /ecc/ {
            set $ecc "http://c3-ecc-app:6700";
            proxy_pass $ecc;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location ^~ /cpp/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $cpp "http://cp-project-app:8801";
            proxy_pass $cpp;
        }
        location ^~ /ip/ {
            set $c3ip "http://c3-ip-app:6800";
            proxy_pass $c3ip;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location ^~ /angelia/ {
            set $angelia "http://angelia:10002";
            proxy_pass $angelia;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
        location ^~ /message/ {
            set $message "http://message-service:10005";
            proxy_pass $message;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }

        location ^~ /intellicost/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $intellicost "http://intellicost-app:10001";
            proxy_pass $intellicost;
        }
        location ^~ /c3oc/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $c3oc "http://c3-oc-app:6602";
            proxy_pass $c3oc;
        }
        location ^~ /c3ce/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $c3ce "http://c3-ce-app:6601";
            proxy_pass $c3ce;
        }

        location ^~ /ceadmin/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $ceadmin "http://c3-ceadmin-app:7701";
            proxy_pass $ceadmin;
        }

        location ^~ /imapp/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_connect_timeout 4s; #配置点1
            proxy_read_timeout 180s; #配置点2，如果没效，可以考虑这个时间配置长一点
            proxy_send_timeout 12s; #配置点3
            set $imapp "http://im-app:8081";
            proxy_pass $imapp;
        }

        location ^~ /dataset/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $dataset "http://dataset-app:7081";
            proxy_pass $dataset;
        }

        location ~ /grafana/(.*) {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            set $grafana "http://grafana:3000";
            proxy_pass $grafana;
        }

        location ^~ /config/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $config "http://config:6666";
            proxy_pass $config;
        }

        location ~ /grafana/(.*) {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            set $grafana "http://grafana:3000";
            proxy_pass $grafana;
        }

        location ^~ /wordpress/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $wordpress "http://cloudam-wordpress";
            #rewrite ^/wordpress/(.*)$ /$1 break;
            proxy_pass $wordpress;
        }
        location ^~ /wp-content/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $wordpress "http://cloudam-wordpress";
            #rewrite ^/wordpress/(.*)$ /$1 break;
            proxy_pass $wordpress;
        }
        location ^~ /wp-admin/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $wordpress "http://cloudam-wordpress";
            #rewrite ^/wordpress/(.*)$ /$1 break;
            proxy_pass $wordpress;
        }
        location ^~ /wp-includes/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $wordpress "http://cloudam-wordpress";
            #rewrite ^/wordpress/(.*)$ /$1 break;
            proxy_pass $wordpress;
        }
        location ^~ /wp-json/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $wordpress "http://cloudam-wordpress";
            #rewrite ^/wordpress/(.*)$ /$1 break;
            proxy_pass $wordpress;
        }
        location ~ .*\.php$ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            set $wordpress "http://cloudam-wordpress";
            #rewrite ^/wordpress/(.*)$ /$1 break;
            proxy_pass $wordpress;
        }
        # Any route containing a file extension (e.g. /devicesfile.js)
        location ~ ^.+\..+$ {
            try_files $uri =404;
        }
    }
}
