Gzip不适用于仅用于域的Nginx安装,但适用于index.html

时间:2019-03-15 20:38:35

标签: nginx gzip

我正在尝试在Nginx配置上启用gzip压缩。我已成功将以下内容添加到/etc/nginx/nginx.conf

gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

我正在使用https://gtmetrix.com/检查以确保gzip压缩功能已打开。我也得到了与https://developers.google.com/speed/pagespeed/insights/

相同的结果

如果我检查我的域“ https://www.hometownapparel.com”,则表明gzip没有显示为已启用。

但是,如果我用定义的index.html检查网址,则确实将“ https://www.hometownapparel.com/index.html” gzip列为已启用。

我犯了什么配置错误,导致gzip无法仅在我的域名上运行?

此致

1 个答案:

答案 0 :(得分:0)

在启用站点的文件中有以下代码:

public class ExceptionHandler extends MainActivity implements java.lang.Thread.UncaughtExceptionHandler {

    private final Context myContext;

    private SharedPreferences prefs;

    private StringBuilder errorReport;

    public ExceptionHandler(Context context) {
        myContext = context;
    }

    public void uncaughtException(Thread thread, Throwable exception) {



        StringWriter stackTrace = new StringWriter();
        exception.printStackTrace(new PrintWriter(stackTrace));
        System.err.println(stackTrace);

        exception.printStackTrace(new PrintWriter(stackTrace));
        errorReport = new StringBuilder();
        errorReport.append("************ CAUSE OF ERROR ************\n\n");
        errorReport.append(stackTrace.toString());

        errorReport.append("\n************ DEVICE INFORMATION ***********\n");

        errorReport.append(LINE_SEPARATOR);
        errorReport.append("Product: ");
        errorReport.append(Build.PRODUCT);
        errorReport.append(LINE_SEPARATOR);
        errorReport.append("\n************ FIRMWARE ************\n");
        errorReport.append("SDK: ");
        errorReport.append(Build.VERSION.SDK);
        errorReport.append(LINE_SEPARATOR);
        errorReport.append("Release: ");
        errorReport.append(Build.VERSION.RELEASE);
        errorReport.append(LINE_SEPARATOR);
        errorReport.append("Incremental: ");
        errorReport.append(Build.VERSION.INCREMENTAL);
        errorReport.append(LINE_SEPARATOR);


        errorReport.append("App Version: ");
        try {
            errorReport.append(myContext.getApplicationContext().getPackageManager().getPackageInfo(myContext.getPackageName(), 0).versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        errorReport.append(LINE_SEPARATOR);


        prefs = myContext.getSharedPreferences("MyPrefsFile", MODE_PRIVATE);

        if (prefs.contains("access_token"))
        {
            errorReport.append(prefs.getString("fname","")+" "+prefs.getString("lname",""));
        }


        Intent intent = new Intent(myContext, sag.class);
        intent.putExtra("error", errorReport.toString());
        myContext.startActivity(intent);

        Process.killProcess(Process.myPid());
        System.exit(10);

    }


}

我切换了index.html,index.php和gzip压缩的顺序就可以正常工作了...

location / {
        index   index.php index.html;
    }

谢谢。