百度云服务器Nginx gzip不生效_nginx -t排查
百度云服务器服务器用Nginx或Apache遇到Nginx gzip不生效,先做配置语法检测。Nginx用nginx -t,Apache用apachectl configtest,语法通过再重载。Nginx gzip不生效时80% 是配置语法错或路径错,检测工具能直接指出错误行号。
Nginx配置结构:main(全局)→ http(HTTP全局)→ server(虚拟主机)→ location(URL匹配)。每个块用花括号包裹,指令以分号结尾。include可以引入子配置。nginx -t检测语法,nginx -s reload重载。配置文件在 /etc/nginx/nginx.conf或宝塔的 /www/server/panel/vhost/nginx/。
参考(Apache配置与排查): ``` # 语法检测 apachectl configtest httpd -t
# 重载与重启 systemctl reload httpd systemctl restart httpd
# 查看模块 httpd -M | grep rewrite httpd -M | grep ssl
# 错误日志 tail -50 /var/log/httpd/error_log tail -50 /var/log/apache2/error.log
# .htaccess示例
# 虚拟主机配置
排查完用netstat端口检测确认。nginx -t返回syntax is ok,systemctl status显示active (running),curl -I返回200,浏览器访问正常。错误日志没有新的error记录。所有location和rewrite规则测试通过。
Nginx与Apache区别:Nginx事件驱动异步非阻塞,高并发性能好,配置简洁,不支持 .htaccess;Apache进程/线程驱动,稳定,支持 .htaccess和丰富模块,高并发内存占用大。静态资源和高并发选Nginx,需要 .htaccess和复杂模块选Apache,也可以Nginx反代Apache。

更新时间:2026-09-01 13:04:28