nginx开启gzip压缩,再将动态api数据请求通过nginx反向代理转发到tomcat.

    配置示例:

    1. #user nobody;
    2. worker_processes 4;
    3. error_log logs/error.log;
    4. pid logs/nginx.pid;
    5. events {
    6. worker_connections 1024;
    7. }
    8. http {
    9. include mime.types;
    10. default_type application/octet-stream;
    11. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    12. '$status $body_bytes_sent "$http_referer" '
    13. '"$http_user_agent" "$http_x_forwarded_for"';
    14. access_log logs/access.log main;
    15. sendfile on;
    16. tcp_nopush on;
    17. tcp_nodelay on;
    18. keepalive_timeout 65;
    19. types_hash_max_size 2048;
    20. gzip on;
    21. gzip_http_version 1.0;
    22. gzip_min_length 1024;
    23. gzip_buffers 4 16k;
    24. gzip_comp_level 3;
    25. gzip_proxied any;
    26. gzip_disable "MSIE [1-6].";
    27. gzip_types text/plain application/json application/x-javascript text/css text/javascript application/octet-stream application/javascript application/xml application/x-httpd-php image/jpeg image/gif image/png;
    28. server {
    29. listen 9090;
    30. server_name 10.47.58.89:9090;
    31. root /data/apps/tomcat/webapps/ROOT/WEB-INF/classes/static/;
    32. location = / {
    33. expires -1;
    34. rewrite / /index.html break;
    35. }
    36. location ~ ^/(lib)/ {
    37. expires 30d;
    38. }
    39. location = /page/index.html {
    40. expires -1;
    41. }
    42. location = /page/blog.html {
    43. expires -1;
    44. }
    45. location = /page/gantt/index.html {
    46. expires -1;
    47. }
    48. location ~ ^/(admin/(js|css|img|md)|img|landing|page|scripts|themes|swipebox)/ {
    49. expires 12h;
    50. }
    51. location / {
    52. proxy_set_header Upgrade $http_upgrade;
    53. proxy_set_header Connection "upgrade";
    54. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    55. proxy_set_header Host $host;
    56. proxy_http_version 1.1;
    57. proxy_headers_hash_max_size 51200;
    58. proxy_headers_hash_bucket_size 6400;
    59. #proxy_redirect off;
    60. proxy_set_header Host $host:$server_port;
    61. proxy_set_header X-Real-IP $remote_addr;
    62. proxy_set_header REMOTE-HOST $remote_addr;
    63. proxy_set_header X-Forwarded-Host $host;
    64. proxy_set_header X-Forwarded-Server $host;
    65. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    66. client_max_body_size 50m;
    67. proxy_pass http://localhost:8080/;
    68. }
    69. }
    70. }