window nginx 启动gzip

首先进行安装

http://www.nginx.cn/nginx-download 进行下载window nginx 安装

直接解压缩到目录下 然后cmd命令


C:\Users\redhat>F:
F:\>cd nginx
F:\nginx>cd nginx-1.5.7
F:\nginx\nginx-1.5.7>start nginx
开启nginx

nginx gzip参数介绍

gzip是GNU zip的缩写,它是一个GNU自由软件的文件压缩程序,可以极大的加速网站.有时压缩比率高到80%,近来测试了一下,最少都有40%以上,还是相当不错的。大道至简,知易行难,悟者大成。
gzip
决定是否开启gzip模块
example:gzip on;
gzip_buffers
设置gzip申请内存的大小,其作用是按块大小的倍数申请内存空间
param2:int(k) 后面单位是k
example: gzip_buffers 4 8k;
gzip_comp_level
设置gzip压缩等级,等级越底压缩速度越快文件压缩比越小,反之速度越慢文件压缩比越大
param:1-9
example:gzip_com_level 1;
gzip_min_length
当返回内容大于此值时才会使用gzip进行压缩,以K为单位,当值为0时,所有页面都进行压缩
param:int
example:gzip_min_length 1000;
gzip_http_version
用于识别http协议的版本,早期的浏览器不支持gzip压缩,用户会看到乱码,所以为了支持前期版本加了此选项,目前此项基本可以忽略
param: 1.0|1.1
example:gzip_http_version 1.0
gzip_proxied
Nginx做为反向代理的时候启用,
param:off|expired|no-cache|no-sotre|private|no_last_modified|no_etag|auth|any]
expample:gzip_proxied no-cache;
off �C 关闭所有的代理结果数据压缩
expired �C 启用压缩,如果header中包含”Expires”头信息
no-cache �C 启用压缩,如果header中包含”Cache-Control:no-cache”头信息
no-store �C 启用压缩,如果header中包含”Cache-Control:no-store”头信息
private �C 启用压缩,如果header中包含”Cache-Control:private”头信息
no_last_modified �C 启用压缩,如果header中包含”Last_Modified”头信息
no_etag �C 启用压缩,如果header中包含“ETag”头信息
auth �C 启用压缩,如果header中包含“Authorization”头信息
any �C 无条件压缩所有结果数据
gzip_types
设置需要压缩的MIME类型,非设置值不进行压缩
param:text/html|application/x-javascript|text/css|application/xml
example:gzip_types text/html;


修改nginx.conf

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
  #添加这一段话
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 9;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
#到这结束
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}


这是没安装gzip

100631906.jpg

100634756.jpg


修改完配置文件重启nginx 进行测试

100702381.png


发现 content-encoding:gzip 压缩已经启动了

最后附上 nginx启动脚本

nginx在Window下运行的时候,如果想重新启动,必须杀进程,点来的去很烦。写个脚本用批处理处理。
restart.bat
@echo off
tskill nginx
nginx.exe -t
nginx.exe -v
start nginx.exe
echo nginx已启动。
pause
start.bat
@echo off
nginx.exe -t
nginx.exe -v
start nginx.exe
echo nginx已启动。
shutdown.bat
@echo off
tskill nginx
echo 已终止所有ginx进程


你可能感兴趣的:(nginx,window,example,start,文件压缩,users)