http – Nginx服务器内容gzip压缩无法正常工作

前端之家收集整理的这篇文章主要介绍了http – Nginx服务器内容gzip压缩无法正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这是我的Nginx.conf中的部分,但我不知道为什么当我用gzip压缩检查器或http头检查时,内容不是压缩.

https://pasify.com

  1. user Nginx;
  2. worker_processes 1;
  3. error_log /var/log/Nginx/error.log;
  4. #error_log /var/log/Nginx/error.log notice;
  5. #error_log /var/log/Nginx/error.log info;
  6. pid /var/run/Nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include /etc/Nginx/mime.types;
  12. default_type application/octet-stream;
  13. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. '$status $body_bytes_sent "$http_referer" '
  15. '"$http_user_agent" "$http_x_forwarded_for"';
  16. access_log /var/log/Nginx/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. keepalive_timeout 0;
  20. #keepalive_requests 5;
  21. #keepalive_timeout 65;
  22. send_timeout 10m;
  23. # output compression saves bandwidth
  24. gzip on;
  25. gzip_http_version 1.1;
  26. gzip_vary on;
  27. gzip_comp_level 6;
  28. gzip_proxied any;
  29. gzip_types text/plain text/html text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/RSS+xml application/atom+xml application/rdf+xml;
  30. gzip_buffers 16 8k;
  31. # Disable gzip for certain browsers.
  32. gzip_disable MSIE [1-6].(?!.*SV1);
  33. # Load config files from the /etc/Nginx/conf.d directory
  34. # The default server is in conf.d/default.conf
  35. include /etc/Nginx/conf.d/*.conf;
  36. ## Detect when HTTPS is used
  37. map $scheme $fastcgi_https {
  38. default off;
  39. https on;
  40. }
  41. client_max_body_size 20M;
  42. }

我可以知道这是什么问题吗?

最佳答案
通过

gzip_disable MSIE [1-6].(?!.*SV1);

你已经为几乎任何有User-Agent数字的浏览器禁用了gzip,因为有两个独立的正则表达式:“MSIE”和“[1-6].(?!.* SV1)”.添加引号或更好地使用它:

gzip_disable msie6;

有关详情,请参见docs.

猜你在找的Nginx相关文章