Nginx 配置文件 nginx.conf 配置项说明

nginx.conf配置项说明

  1. #创建进程的用户和用户组
  2. user liuyazhuang liuyazhuang;
  3. #服务进程数量,一般等于CPU数量
  4. worker_processes 2;
  5. #全局错误日志定义,建议开启error级别日志.[ debug | info | notice | warn | error | crit ]
  6. error_log logs/error.log error;
  7. #error_log logs/error.log notice;
  8. #error_log logs/error.log info;
  9. #记录进程ID的文件
  10. #pid logs/nginx.pid;
  11. events {
  12. #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能.Linux建议使用epoll,FreeBSD建议使用kqueue.
  13. use epoll;
  14. #一个worker_processe允许的最近并发连接数量
  15. worker_connections 1024;
  16. }
  17. http {
  18. include mime.types;
  19. default_type application/octet-stream;
  20. client_max_body_size 16m;
  21. client_body_buffer_size 256k;
  22. proxy_connect_timeout 1200;
  23. proxy_read_timeout 1200;
  24. proxy_send_timeout 6000;
  25. proxy_buffer_size 32k;
  26. proxy_buffers 4 64k;
  27. proxy_busy_buffers_size 128k;
  28. proxy_temp_file_write_size 128k;
  29. #log_format main '$remote_addr - $remote_user [$time_local]"$request" '
  30. # '$status $body_bytes_sent"$http_referer" '
  31. # '"$http_user_agent""$http_x_forwarded_for"';
  32. #access_log logs/access.log main;
  33. sendfile on;
  34. #tcp_nopush on;
  35. #http连接的持续时间
  36. keepalive_timeout 65;
  37. #gzip压缩设置
  38. gzip on; #开启gzip
  39. gzip_min_length 1k; #最小压缩文件大小
  40. gzip_buffers 4 16k; #压缩缓冲区
  41. #http的协议版本(1.0/1.1),默认1.1,前端如果是squid2.5请使用1.0
  42. gzip_http_version 1.1;
  43. #gzip压缩比,1压缩比最小处理速度最快,9压缩比最大但处理速度最慢(传输快但比较消耗cpu)
  44. gzip_comp_level 2;
  45. #和http头有关系,加个vary头,给代理服务器用的,有的浏览器支持压缩,有的不支持,所以避免浪费不支持的也压缩,所以根据客户端的HTTP头来判断,是否需要压缩
  46. gzip_vary on;
  47. #gzip压缩类型,不用添加text/html,否则会有警告信息
  48. gzip_types text/plain text/javascript text/css application/xmlapplication/x-javascript application/json;
  49. #设定负载均衡的服务器列表,可以设置多个upstream,但mysvr名字要区分
  50. upstream myClusterServer1 {
  51. #weigth参数表示权值,权值越高被分配到的几率越大
  52. #本机上的Squid开启3128端口
  53. server 127.0 .0 .1: 8081 weight= 5;
  54. server 127.0 .0 .1: 8082 weight= 5;
  55. server 127.0 .0 .1: 8083 weight= 5;
  56. }
  57. server {
  58. #nginx监听的端口号
  59. listen 80;
  60. #域名可以有多个,用空格隔开
  61. server_name 127.0 .0 .1;
  62. #字符编码方式
  63. charset utf -8;
  64. #设定本虚拟主机的访问日志。关闭日志可以减少IO,提高性能。
  65. #access_log logs/host.access.log main;
  66. #默认请求
  67. location / {
  68. #定义服务器的默认网站根目录位置
  69. root html;
  70. #定义首页索引文件的名称
  71. index index.html index.htmindex.jsp;
  72. #请求转向mysvr 定义的服务器列表
  73. proxy_pass http: //myClusterServer1;
  74. proxy_redirect default;
  75. #跟代理服务器连接的超时时间,必须留意这个time out时间不能超过75秒,当一台服务器当掉时,过10秒转发到另外一台服务器。
  76. proxy_connect_timeout 10;
  77. }
  78. #error_page 404 /404.html;
  79. #redirect server error pages to the static page /50x.html
  80. #
  81. error_page 500 502 503 504 / 50x.html;
  82. location = / 50x.html {
  83. root html;
  84. }
  85. #proxy the PHP scripts to Apache listening on 127.0.0.1:80
  86. #
  87. #location ~ \.php$ {
  88. # proxy_pass http://127.0.0.1;
  89. #}
  90. #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  91. #
  92. #location ~ \.php$ {
  93. # root html;
  94. # fastcgi_pass 127.0.0.1:9000;
  95. # fastcgi_index index.php;
  96. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  97. # include fastcgi_params;
  98. #}
  99. #deny access to .htaccess files, if Apache's document root
  100. #concurs with nginx's one
  101. #
  102. #location ~ /\.ht {
  103. # deny all;
  104. #}
  105. }
  106. # anothervirtual host using mix of IP-, name-, and port-based configuration
  107. #
  108. #server {
  109. # listen 8000;
  110. # listen somename:8080;
  111. # server_name somename alias another.alias;
  112. # location / {
  113. # root html;
  114. # index index.html index.htm;
  115. # }
  116. #}
  117. # HTTPS server
  118. #
  119. #server {
  120. # listen 443 ssl;
  121. # server_name localhost;
  122. # ssl_certificate cert.pem;
  123. # ssl_certificate_key cert.key;
  124. # ssl_session_cache shared:SSL:1m;
  125. # ssl_session_timeout 5m;
  126. # ssl_ciphers HIGH:!aNULL:!MD5;
  127. # ssl_prefer_server_ciphers on;
  128. # location / {
  129. # root html;
  130. # index index.html index.htm;
  131. # }
  132. #}
  133. }





猜你喜欢

转载自blog.csdn.net/wangmx1993328/article/details/80941870