Nginx配置文件经典教程分析

开发 前端
Nginx配置文件需要广大程序员认真的学习,接下来我们就看看在关键的地方如何进行Nginx配置文件的学习,希望大家有所收获。

Nginx配置文件需要我们学习的东西有很多,但是要想一下子学会这么多东西是不可能的,那么我们就来重点的学习有关Nginx配置文件的经典教程,希望大家在学习中掌握技巧。

  1. user www www;  
  2. worker_processes 2;  
  3. pid /var/run/nginx.pid;  
  4. # [ debug | info | notice | warn | error | crit ]   
  5. error_log /var/log/nginx.error_log info;  
  6. events {  
  7. worker_connections 2000;  
  8. # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ] ;  
  9. use kqueue;  
  10. }  
  11. http {  
  12. include conf/mime.types;  
  13. default_type application/octet-stream;  
  14. log_format main '$remote_addr - $remote_user [$time_local] '  
  15. '"$request" $status $bytes_sent '  
  16. '"$http_referer" "$http_user_agent" '  
  17. '"$gzip_ratio"';  
  18. log_format download '$remote_addr - $remote_user [$time_local] '  
  19. '"$request" $status $bytes_sent '  
  20. '"$http_referer" "$http_user_agent" '  
  21. '"$http_range" "$sent_http_content_range"';  
  22. client_header_timeout 3m;  
  23. client_body_timeout 3m;  
  24. send_timeout 3m;  
  25. client_header_buffer_size 1k;  
  26. large_client_header_buffers 4 4k;  
  27. gzip on;  
  28. gzip_min_length 1100;  
  29. gzip_buffers 4 8k;  
  30. gzip_types text/plain;  
  31. output_buffers 1 32k;  
  32. postpone_output 1460;  
  33. sendfile on;  
  34. tcp_nopush on;  
  35. tcp_nodelay on;  
  36. send_lowat 12000;  
  37. keepalive_timeout 75 20;  
  38. # lingering_time 30;  
  39. # lingering_timeout 10;  
  40. # reset_timedout_connection on;  
  41. server {  
  42. listen one.example.com;  
  43. server_name one.example.com www.one.example.com;  
  44. access_log /var/log/nginx.access_log main;  
  45. location / {  
  46. proxy_pass http://127.0.0.1/;  
  47. proxy_redirect off;  
  48. proxy_set_header Host $host;  
  49. proxy_set_header X-Real-IP $remote_addr;  
  50. # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  51. client_max_body_size 10m;  
  52. client_body_buffer_size 128k;  
  53. client_body_temp_path /var/nginx/client_body_temp;  
  54. proxy_connect_timeout 90;  
  55. proxy_send_timeout 90;  
  56. proxy_read_timeout 90;  
  57. proxy_send_lowat 12000;  
  58. proxy_buffer_size 4k;  
  59. proxy_buffers 4 32k;  
  60. proxy_busy_buffers_size 64k;  
  61. proxy_temp_file_write_size 64k;  
  62. proxy_temp_path /var/nginx/proxy_temp;  
  63. charset koi8-r;  
  64. }  
  65. error_page 404 /404.html;  
  66.  
  67. location /404.html {  
  68. root /spool/www;  
  69. charset on;  
  70. source_charset koi8-r;  
  71. }  
  72. location /old_stuff/ {  
  73. rewrite ^/old_stuff/(.*)$ /new_stuff/$1 permanent;  
  74. }  
  75. location /download/ {  
  76. valid_referers none blocked server_names *.example.com;  
  77. if ($invalid_referer) {  
  78. #rewrite ^/ http://www.example.com/;  
  79. return 403;  
  80. }  
  81. # rewrite_log on;  
  82. # rewrite /download/*/mp3/*.any_ext to /download/*/mp3/*.mp3  
  83. rewrite ^/(download/.*)/mp3/(.*)\..*$ /$1/mp3/$2.mp3 break;  
  84. root /spool/www;  
  85. # autoindex on;  
  86. access_log /var/log/nginx-download.access_log download;  
  87. }  
  88. location ~* ^.+\.(jpg|jpeg|gif)$ {  
  89. root /spool/www;  
  90. access_log off;  
  91. expires 30d;  
  92. }  
  93. }  
  94. }  

以上就是对Nginx配置文件的详细介绍,希望大家在使用中有所收获。

【编辑推荐】

  1. nginx服务器如何处理相关的图片
  2. nginx服务器的性能依然强劲
  3. nginx缓存的缺点和优点专家评价
  4. nginx配置相关结构划分的技巧
  5. nginx配置文件实现AWStats静态页面
责任编辑:张浩 来源: 互联网
相关推荐

2020-04-09 13:23:29

Nginx配置文件模板

2014-06-09 10:36:00

2011-02-25 13:34:33

Proftpd结构

2010-03-29 09:23:00

2010-03-25 17:46:27

nginx配置文件

2010-03-25 18:09:23

Nginx配置文件

2010-03-30 18:04:45

Nginx http服

2010-03-30 10:12:41

Nginx php.i

2010-02-06 14:00:05

Linux Nginx

2010-03-29 10:26:06

Nginx配置文件

2022-04-28 09:46:20

Nginx文件Linux

2011-01-13 16:27:26

Linux配置文件

2011-01-19 14:00:21

2010-12-28 16:35:32

Outlook 配置文

2010-12-27 14:59:31

Outlook 配置文

2009-06-17 14:10:30

Spring配置文件

2009-09-22 10:23:15

Hibernate配置

2010-08-05 14:36:07

NFS服务

2011-02-25 16:39:34

proftpd配置文件

2010-05-05 16:14:09

Unix管理
点赞
收藏

51CTO技术栈公众号