配置文件的位置nginx/conf/nginx.conf

最小配置文件解读

  1. # 代表注释
  2. worker_processes: 1 # 开启的进程数 1个CPU内核对应一个worker_processes
  3. events { # 事件驱动模块
  4. worker_connections 1024; # 每一个worker_processes能创建的连接
  5. }
  6. http {
  7. include mime.types; # 可以引用其他的配置文件
  8. default_type application/octet-stream;
  9. sendfile on; # 数据流拷贝
  10. keepalive_timeout 65; # 保持连接超时时间
  11. server { # 一个虚拟主机-vhost,可以开启多个
  12. listen 80; # 监听的端口号,不能重复
  13. server_name localhost; # 主机名或者域名
  14. # 域名后面跟的路径
  15. # url=https://www.xiumubai.com/xxx/index.html
  16. # uri=xxx/index.html(资源)
  17. location / { # 匹配的uri,可以有好多个
  18. root html; # 资源放置主目录,在nginx目录下的
  19. index index.html index.htm; # 访问的默认页面
  20. }
  21. error_page 500 502 503 504 /50x.html; # 发生服务端错误展示的页面
  22. location = /50x.html { # 指定50x.html的访问目录
  23. root html;
  24. }
  25. }
  26. }

mime.types

文件指定了浏览器解析的文件类型

  1. types {
  2. text/html html htm shtml;
  3. text/css css;
  4. text/xml xml;
  5. image/gif gif;
  6. image/jpeg jpeg jpg;
  7. application/javascript js;
  8. application/atom+xml atom;
  9. application/rss+xml rss;
  10. text/mathml mml;
  11. text/plain txt;
  12. text/vnd.sun.j2me.app-descriptor jad;
  13. text/vnd.wap.wml wml;
  14. text/x-component htc;
  15. image/png png;
  16. image/svg+xml svg svgz;
  17. image/tiff tif tiff;
  18. image/vnd.wap.wbmp wbmp;
  19. image/webp webp;
  20. image/x-icon ico;
  21. image/x-jng jng;
  22. image/x-ms-bmp bmp;
  23. font/woff woff;
  24. font/woff2 woff2;
  25. application/java-archive jar war ear;
  26. application/json json;
  27. application/mac-binhex40 hqx;
  28. application/msword doc;
  29. application/pdf pdf;
  30. application/postscript ps eps ai;
  31. application/rtf rtf;
  32. application/vnd.apple.mpegurl m3u8;
  33. application/vnd.google-earth.kml+xml kml;
  34. application/vnd.google-earth.kmz kmz;
  35. application/vnd.ms-excel xls;
  36. application/vnd.ms-fontobject eot;
  37. application/vnd.ms-powerpoint ppt;
  38. application/vnd.oasis.opendocument.graphics odg;
  39. application/vnd.oasis.opendocument.presentation odp;
  40. application/vnd.oasis.opendocument.spreadsheet ods;
  41. application/vnd.oasis.opendocument.text odt;
  42. application/vnd.openxmlformats-officedocument.presentationml.presentation
  43. pptx;
  44. application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  45. xlsx;
  46. application/vnd.openxmlformats-officedocument.wordprocessingml.document
  47. docx;
  48. application/vnd.wap.wmlc wmlc;
  49. application/wasm wasm;
  50. application/x-7z-compressed 7z;
  51. application/x-cocoa cco;
  52. application/x-java-archive-diff jardiff;
  53. application/x-java-jnlp-file jnlp;
  54. application/x-makeself run;
  55. application/x-perl pl pm;
  56. application/x-pilot prc pdb;
  57. application/x-rar-compressed rar;
  58. application/x-redhat-package-manager rpm;
  59. application/x-sea sea;
  60. application/x-shockwave-flash swf;
  61. application/x-stuffit sit;
  62. application/x-tcl tcl tk;
  63. application/x-x509-ca-cert der pem crt;
  64. application/x-xpinstall xpi;
  65. application/xhtml+xml xhtml;
  66. application/xspf+xml xspf;
  67. application/zip zip;
  68. application/octet-stream bin exe dll;
  69. application/octet-stream deb;
  70. application/octet-stream dmg;
  71. application/octet-stream iso img;
  72. application/octet-stream msi msp msm;
  73. audio/midi mid midi kar;
  74. audio/mpeg mp3;
  75. audio/ogg ogg;
  76. audio/x-m4a m4a;
  77. audio/x-realaudio ra;
  78. video/3gpp 3gpp 3gp;
  79. video/mp2t ts;
  80. video/mp4 mp4;
  81. video/mpeg mpeg mpg;
  82. video/quicktime mov;
  83. video/webm webm;
  84. video/x-flv flv;
  85. video/x-m4v m4v;
  86. video/x-mng mng;
  87. video/x-ms-asf asx asf;
  88. video/x-ms-wmv wmv;
  89. video/x-msvideo avi;
  90. }

sendfile

没有sendfile
image.png
有sendfile,少了数据拷贝的过程
image.png

nginx原始文件备份

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. server {
  23. listen 80;
  24. server_name localhost;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. location / {
  28. root html;
  29. index index.html index.htm;
  30. }
  31. #error_page 404 /404.html;
  32. # redirect server error pages to the static page /50x.html
  33. #
  34. error_page 500 502 503 504 /50x.html;
  35. location = /50x.html {
  36. root html;
  37. }
  38. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  39. #
  40. #location ~ \.php$ {
  41. # proxy_pass http://127.0.0.1;
  42. #}
  43. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  44. #
  45. #location ~ \.php$ {
  46. # root html;
  47. # fastcgi_pass 127.0.0.1:9000;
  48. # fastcgi_index index.php;
  49. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  50. # include fastcgi_params;
  51. #}
  52. # deny access to .htaccess files, if Apache's document root
  53. # concurs with nginx's one
  54. #
  55. #location ~ /\.ht {
  56. # deny all;
  57. #}
  58. }
  59. # another virtual host using mix of IP-, name-, and port-based configuration
  60. #
  61. #server {
  62. # listen 8000;
  63. # listen somename:8080;
  64. # server_name somename alias another.alias;
  65. # location / {
  66. # root html;
  67. # index index.html index.htm;
  68. # }
  69. #}
  70. # HTTPS server
  71. #
  72. #server {
  73. # listen 443 ssl;
  74. # server_name localhost;
  75. # ssl_certificate cert.pem;
  76. # ssl_certificate_key cert.key;
  77. # ssl_session_cache shared:SSL:1m;
  78. # ssl_session_timeout 5m;
  79. # ssl_ciphers HIGH:!aNULL:!MD5;
  80. # ssl_prefer_server_ciphers on;
  81. # location / {
  82. # root html;
  83. # index index.html index.htm;
  84. # }
  85. #}
  86. }