• 完整例子2

    完整例子2

    这是来自 Nginx官方网站 的一个例子。

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

    原文: https://wizardforcel.gitbooks.io/nginx-doc/content/Text/7.2_fullexample2.html