nginx 开启GZIP、域名指向index.html

nginx 虽然默认开启了gzip压缩,但是有关压缩文件、压缩效率没有开启,在建设我的(个人博客)[www.fayinme.cn]中,直观的感受到gzip带来的访问速度提升的快感。

如何开启GZIP

我使用的是阿里云服务器,登陆后执行:

cd /etc/nginx

sudo vi nginx.conf

在 nginx.conf 文件中找到 gzip setting,更改为如下配置:

        ##
        # Gzip Settings
        ##

        gzip on;    // 开启gzip
        gzip_disable "msie6";    // 禁止在ie6 中开启

        gzip_vary on;
        # gzip_proxied any;
        gzip_comp_level 2;    // 压缩效率 1-10 越大压缩的越小
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;    // 指定可压缩文件


项目部署到服务器后,初次访问 www.fayinme.cn,会返回502,访问 www.fayinme.cn/index.html 才返回了正确的页面,显然这不是我们想要的结果。

nginx 域名访问指向 index.html

进入当前域名nginx配置文件:

cd /etc/nginx/conf.d

cd www-fayinme-cn.conf

编辑 www-fayinme-cn.conf, 配置如下:

server {
        listen 80;
        server_name www.fayinme.cn;
        autoindex on;

        location = / {
                index index.html;
        }

        location / {

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;

                proxy_set_header X-Nginx-Proxy true;

                proxy_pass http://blogfront;
                proxy_redirect off;

        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt|html) {
                root /www/blogfront/production/current;
        }
}


posted @ 2017-06-04 11:48  Liaofy  阅读(3770)  评论(0编辑  收藏  举报