1. #Nginx用户及组:用户 组。window下不指定
  2. #user nobody;
  3. #错误日志:存放路径。
  4. worker_processes 1;
  5. #error_log logs/error.log;
  6. #error_log logs/error.log notice;
  7. #error_log logs/error.log info;
  8. #pid(进程标识符):存放路径
  9. #pid logs/nginx.pid;
  10. events {
  11. #单个进程最大连接数(最大连接数=连接数*进程数)
  12. worker_connections 1024;
  13. }
  14. http {
  15. #设定mime类型,类型由mime.type文件定义
  16. include mime.types;
  17. default_type application/octet-stream;
  18. #日志格式设置
  19. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  20. # '$status $body_bytes_sent "$http_referer" '
  21. # '"$http_user_agent" "$http_x_forwarded_for"';
  22. #用了log_format指令设置了日志格式之后,需要用access_log指令指定日志文件的存放路径
  23. #记录了哪些用户,哪些页面以及用户浏览器、ip和其他的访问信息
  24. #access_log logs/access.log main;
  25. #开启文件传输,一般应用都应设置为on;若是有下载的应用,则可以设置成off来平衡网络I/O和磁盘的I/O来降低系统负载
  26. sendfile on;
  27. #告诉nginx在一个数据包里发送所有头文件,而不一个接一个的发送。
  28. #tcp_nopush on;
  29. #长连接超时时间,单位是秒
  30. #keepalive_timeout 0;
  31. keepalive_timeout 65;
  32. #gzip模块设置,使用 gzip 压缩可以降低网站带宽消耗,同时提升访问速度。
  33. #gzip on;
  34. server {
  35. listen 80;
  36. # #IP/域名可以有多个,用空格隔开
  37. server_name localhost;
  38. #charset koi8-r;
  39. #access_log logs/host.access.log main;
  40. location / {
  41. root html;
  42. index index.html index.htm;
  43. }
  44. #error_page 404 /404.html;
  45. # redirect server error pages to the static page /50x.html
  46. #
  47. error_page 500 502 503 504 /50x.html;
  48. location = /50x.html {
  49. root html;
  50. }
  51. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  52. #
  53. #location ~ \.php$ {
  54. # proxy_pass http://127.0.0.1;
  55. #}
  56. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  57. #
  58. #location ~ \.php$ {
  59. # root html;
  60. # fastcgi_pass 127.0.0.1:9000;
  61. # fastcgi_index index.php;
  62. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  63. # include fastcgi_params;
  64. #}
  65. # deny access to .htaccess files, if Apache's document root
  66. # concurs with nginx's one
  67. #
  68. #location ~ /\.ht {
  69. # deny all;
  70. #}
  71. }
  72. # another virtual host using mix of IP-, name-, and port-based configuration
  73. #
  74. #server {
  75. # listen 8000;
  76. # listen somename:8080;
  77. # server_name somename alias another.alias;
  78. # location / {
  79. # root html;
  80. # index index.html index.htm;
  81. # }
  82. #}
  83. # HTTPS server
  84. #
  85. #server {
  86. # listen 443 ssl;
  87. # server_name localhost;
  88. # ssl_certificate cert.pem;
  89. # ssl_certificate_key cert.key;
  90. # ssl_session_cache shared:SSL:1m;
  91. # ssl_session_timeout 5m;
  92. # ssl_ciphers HIGH:!aNULL:!MD5;
  93. # ssl_prefer_server_ciphers on;
  94. # location / {
  95. # root html;
  96. # index index.html index.htm;
  97. # }
  98. #}
  99. }

nginx.conf配置文件有三个部分组成

第一部分 全局块

从配置文件开始到events块之前的内容,主要会设置一些影响 nginx服务器整体运行的配置指令。
比如默认配置中的 worker_processes 1; 工作进程:数目 。根据硬件调整,通常等于CPU数量或者2倍于CPU

第二部分 events块

events块 涉及的指令主要影响 Nginx 服务器与用户的网络连接
比如 worker_connections 1024; 单个进程最大连接数(最大连接数=连接数*进程数)

第三部分 http块

Nginx 服务器配置中修改最频繁的部分
http块也可以包括 http全局块、server块