access_log  /data/logs/customs/tsf-access.log  main;
error_log  /data/logs/customs/tsf-error.log  notice;

gzip_static on;
gzip on;
gzip_proxied expired no-cache no-store private auth; #启用压缩的响应头
gzip_min_length 1k; #文件大于1k压缩
gzip_buffers 4 16k; #设置压缩所需要的缓冲区大小
gzip_http_version 1.1; #http协议版本
gzip_comp_level 2; #压缩级别 1-9
gzip_types text/plain application/javascript text/css #文件类型
gzip_vary on; #是否在http  header 中添加 Vary: Accept-Encoding 建议开启

server {
  	listen	8080;

	# html类 不缓存
    location ~ \.(html|htm)$ {
        root	/usr/share/nginx/html;
        add_header Cache-Control no-cache;
    }

    # css、js 缓存，仅客户端缓存
    location ~ \.(css|js)$ {
        root	/usr/share/nginx/html;
        add_header Cache-Control private,max-age=28800;
    }

    # 图片类 缓存，仅客户端缓存
    location ~ \.(gif|jpg|jpeg|png|bmp|ico)$ {
        root	/usr/share/nginx/html;
        add_header Cache-Control private,max-age=28800;
    }

    # 字体类 缓存，仅客户端缓存
    location ~ \.(ttf|woff|woff2|otf|ttc|eot|svg)$ {
        root	/usr/share/nginx/html;
        add_header Cache-Control private,max-age=28800;
    }

  	location / {
		try_files $uri $uri/ @router;
		root	/usr/share/nginx/html;
		index	index.html index.htm;
 	}

	location /api/ {
		proxy_set_header	Host	$host;
		proxy_set_header	X-Real-IP	$remote_addr;
		proxy_set_header	X-Forwarded-for	$remote_addr;
		proxy_connect_timeout	300;
		port_in_redirect off;

		rewrite ^/api/(.*) /$1 break;
    	proxy_pass	http://apigw:11000/;
	}

	location /static-resource/ {
		proxy_set_header	Host	$host;
		proxy_set_header	X-Real-IP	$remote_addr;
		proxy_set_header	X-Forwarded-for	$remote_addr;
		proxy_connect_timeout	300;
		port_in_redirect off;

		rewrite ^/static-resource/(.*) /$1 break;
    	proxy_pass	http://static-resource-web:8080/;
	}

	location @router {
		rewrite ^.*$ /index.html last;
	}
}

