nginx配置文件详解(优化)

来源:互联网 发布:$.each数组变化 编辑:程序博客网 时间:2024/06/06 03:36
  1. #user nobody; #运行nginx的用户
  2. worker_processes1;#于服务器核心数相同
  3. worker_rlimit_nofile100000;#nginx进程打开的最多文件描述符数目,ulimit -n相同
  4. #error_log logs/error.log; #各种日志放哪里
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. pid logs/nginx.pid;#pid文件
  8. events{ #Nginx事件处理模型
  9. worker_connections10000;#单个worker进程允许客户端最大连接数
  10. multi_accepton;#一次accept一个新连接,or 一次accept所有的新连接
  11. useepoll;#nginx采用epoll事件模型,处理效率高
  12. }
  13. http{
  14. include mime.types;#媒体类型,include 只是一个在当前文件中包含另一个文件内容的指令
  15. default_type application/octet-stream;
  16. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  17. # '$status $body_bytes_sent "$http_referer" '
  18. # '"$http_user_agent" "$http_x_forwarded_for"';
  19. #access_log logs/access.log main;
  20. server_tokensoff;
  21. error_logerror.logcrit;
  22. sendfileon;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。如果图片显示不正常把这个改成off
  23. tcp_nopushon;#必须在sendfile开启模式才有效,防止网路阻塞,积极的减少网络报文段的数量(将响应头和正文的开始部分一起发送,而不一个接一个的发送。)
  24. tcp_nodelayon;#必须在sendfile开启模式才有效,防止网路阻塞,积极的减少网络报文段的数量(将响应头和正文的开始部分一起发送,而不一个接一个的发送。)
  25. keepalive_timeout60;#客户端连接保持会话超时时间,超过这个时间,服务器断开这个链接
  26. client_header_timeout10;#设置请求头的超时时间。我们也可以把这个设置低些,如果超过这个时间没有发送任何数据,nginx将返回request time out的错误
  27. client_body_timeout10;#设置请求体的超时时间。我们也可以把这个设置低些,超过这个时间没有发送任何数据,和上面一样的错误提示
  28. reset_timedout_connectionon;#告诉nginx关闭不响应的客户端连接。这将会释放那个客户端所占有的内存空间。
  29. send_timeout10;#响应客户端超时时间,这个超时时间仅限于两个活动之间的时间,如果超过这个时间,客户端没有任何活动,nginx关闭连接
  30. #include mime.types;
  31. #default_type text/html;
  32. charset UTF-8;
  33. gzipon;#开启页面压缩
  34. gzip_disable"msie6";
  35. gzip_proxied any;
  36. gzip_min_length1000;
  37. gzip_comp_level6;
  38. gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  39. open_file_cache max=100000 inactive=20s;#这个将为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件
  40. 数一致,inactive是指经过多长时间文件没被请求后删除缓存。
  41. open_file_cache_valid30s;#这个是指多长时间检查一次缓存的有效信息。
  42. open_file_cache_min_uses2;#open_file_cache指令中的inactive 参数时间内文件的最少使用次数,如果超过这个数字,文
  43. 件描述符一直是在缓存中打开的,如上例,如果有一个文件在inactive时间内一次没被使用,它将被移除。
  44. open_file_cache_errorsoff;
  45. server{ #主机字段
  46. listen80;#监听端口
  47. server_namewww.zjswdlt.cn;#域名
  48. #charset koi8-r;
  49. #access_log logs/host.access.log main;
  50. location/ {
  51. root html; #页面所在目录
  52. indexindex.htmlindex.htmindex.php;#首页文件
  53. }
  54. #error_page 404 /404.html; #404页面
  55. # redirect server error pages to the static page /50x.html
  56. #
  57. error_page500502503504/50x.html;
  58. location= /50x.html{
  59. root html;
  60. }
  61. #proxy the PHP scripts to Apache listening on 127.0.0.1:80
  62. #
  63. #location ~ \.php$ {
  64. # proxy_pass http://127.0.0.1;
  65. #}
  66. #passthe PHP scripts to FastCGI server listening on 127.0.0.1:9000
  67. location~ \.php${ #打开php解析
  68. root html/bbs;#php页面地址
  69. fastcgi_pass127.0.0.1:9000;#启用端口
  70. fastcgi_indexindex.php;
  71. fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
  72. include fastcgi_params;
  73. }
  74. # deny access to .htaccess files, if Apache's document root
  75. # concurs with nginx's one
  76. #
  77. #location ~ /\.ht {
  78. # deny all;
  79. #}
  80. }
  81. # another virtual host using mix of IP-, name-, and port-based configuration
  82. #
  83. #server {
  84. # listen 8000;
  85. # listen somename:8080;
  86. # server_name somename alias another.alias;
  87. # location / {
  88. # root html;
  89. #index index.html index.htm;
  90. # }
  91. #}
  92. # HTTPS server
  93. #
  94. #server {
  95. # listen 443 ssl;
  96. # server_name localhost;
  97. # ssl_certificate cert.pem;
  98. # ssl_certificate_key cert.key;
  99. #ssl_session_cache shared:SSL:1m;
  100. # ssl_session_timeout 5m;
  101. # ssl_ciphers HIGH:!aNULL:!MD5;
  102. # ssl_prefer_server_ciphers on;
  103. # location / {
  104. # root html;
  105. #index index.html index.htm;
  106. # }
  107. #}
  108. }
原创粉丝点击