Nginx 配置优化

来源:互联网 发布:gsm是什么网络 编辑:程序博客网 时间:2024/06/10 13:34

nginx.conf

#user  nobody;#进程数量,建议值 <= 服务器cpu核心数量worker_processes  4;#每个进程最大可打开的文件描述符数量worker_rlimit_nofile 65535;events {    #并发响应能力关键配置值    #每个进程允许的最大同时连接数,maxConnection = worker_connections * worker_processes    #一个用户浏览器一般会同时开两条链接,如果反向代理,nginx到后端服务器的链接也要占用连接数    #So,静态服务器理论上,maxCliient = worker_connections * worker_processes / 2    #反向代理服务器理论上,maxCliient = worker_connections * worker_processes / 4    #做压力测试时,最大并发量可参考上述公式    worker_connections  10240;}http {    include       mime.types;    default_type  application/octet-stream;    #关闭用户访问日志,减少IO开销    access_log   off;    #access_log  logs/access.log  main;    #只记录严重的错误日志,crit以上    error_log logs/error.log  crit;    sendfile        on;    #tcp_nopush     on;    #降低每个链接的alive时间可在一定程度上提高可响应连接数量    #keepalive_timeout  0;    keepalive_timeout  45;    #是否启动内容压缩,降低网络流量    #gzip  on;        #如果开启,需要配合以下参数达到更好的效果    #超过1k的内容才压缩,过短的内容压缩效果不佳,还会浪费系统资源    #gzip_min_length 2048;    #压缩级别,可选1~9,级别越高压缩率越高,系统性能要求越高    #gzip_comp_level 4;    #压缩文件类型    #gzip_types text/plain text/css application/json application/xml application/x-javascript image/jpg image/jpeg image/gif image/png;    #静态文件缓存    #为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件数一致(worker_rlimit_nofile)    #inactive指经过多长时间文件没被请求后删除缓存    open_file_cache          max=65535 inactive=20s;    #验证缓存有效期时间间隔    open_file_cache_valid    30s;    #inactive参数时间内文件的最少使用次数,如超过这个数字,文件描述符一直是在缓存中打开的    #如下设置表示,如一个文件在inactive时间内没被使用超过2次,它将被移除    open_file_cache_min_uses 2;    server {        listen       80;        server_name  localhost;        charset utf-8;        #location表达式        #匹配前缀:=|~|~*|^~|@|, 或直接连接字符串 /uri        #字符匹配:/uri或=开头,/uri为前缀匹配,=为精确匹配(必须完全相等)        #正则匹配:~或~*开头,~*表示不区分大小写        #匹配顺序与规则:        #1、首先匹配=开头的精确匹配        #2、/uri开头的字符匹配        #3、普通匹配到后,将暂存结果,继续匹配正则模式        #4、正则匹配以第一个成功匹配项为最终结果,所以正则匹配受顺序影响,字符匹配不会        #5、如果未匹配到正则项目,则以3中缓存的结果为最终结果        #6、没有一个匹配,则返回404        #^~开头,表示匹配到此模式后不再匹配正则        #@开头,表示定义变量        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;        }    }


0 0
原创粉丝点击