[轉載]Nginx完整配置說明

  1. #用戶 用戶組      
  2. user       www www;      
  3. #工作進程,根據硬件調整,有人說幾核cpu,就配幾個,我覺得可以多一點      
  4. worker_processes  5;      
  5. #錯誤日誌      
  6. error_log  logs/error.log;      
  7. #pid文件位置      
  8. pid        logs/nginx.pid;      
  9. worker_rlimit_nofile 8192;      
  10.      
  11. events {      
  12. #工作進程的最大連接數量,根據硬件調整,和前面工作進程配合起來用,儘量大,但是別把cpu跑到100%就行      
  13.     worker_connections  4096;      
  14. }      
  15.      
  16. http {      
  17.     include    conf/mime.types;      
  18.     #反向代理配置,可以打開proxy.conf看看      
  19.     include    /etc/nginx/proxy.conf;      
  20.     #fastcgi配置,可以打開fastcgi.conf看看      
  21.     include    /etc/nginx/fastcgi.conf;      
  22.      
  23.     default_type application/octet-stream;      
  24.     #日誌的格式      
  25.     log_format   main '$remote_addr - $remote_user [$time_local] $status '     
  26.                       '"$request" $body_bytes_sent "$http_referer" '     
  27.                       '"$http_user_agent" "$http_x_forwarded_for"';      
  28.     #訪問日誌      
  29.     access_log   logs/access.log  main;      
  30.     sendfile     on;      
  31.     tcp_nopush   on;      
  32.     #根據實際情況調整,如果server很多,就調大一點      
  33.     server_names_hash_bucket_size 128; # this seems to be required for some vhosts      
  34.      
  35.     #這個例子是fastcgi的例子,如果用fastcgi就要仔細看      
  36.     server { # php/fastcgi      
  37.         listen       80;      
  38.         #域名,可以有多個      
  39.         server_name  domain1.com www.domain1.com;      
  40.         #訪問日誌,和上面的級別不一樣,應該是下級的覆蓋上級的      
  41.         access_log   logs/domain1.access.log  main;      
  42.         root         html;      
  43.      
  44.         location / {      
  45.             index    index.html index.htm index.php;      
  46.         }      
  47.      
  48.         #所有php後綴的,都通過fastcgi發送到1025端口上      
  49.          #上面include的fastcgi.conf在此應該是有作用,如果你不include,那麼就把fastcgi.conf的配置項放在這個下面。      
  50.         location ~ /.php$ {      
  51.             fastcgi_pass   127.0.0.1:1025;      
  52.         }      
  53.     }      
  54.      
  55.     #這個是反向代理的例子      
  56.     server { # simple reverse-proxy      
  57.         listen       80;      
  58.         server_name  domain2.com www.domain2.com;      
  59.         access_log   logs/domain2.access.log  main;      
  60.      
  61.         #靜態文件,nginx自己處理      
  62.         location ~ ^/(images|javascript|js|css|flash|media|static)/  {      
  63.                 root    /var/www/virtual/big.server.com/htdocs;      
  64.                 #過期30天,靜態文件不怎麼更新,過期可以設大一點,如果頻繁更新,則可以設置得小一點。      
  65.                 expires 30d;      
  66.         }      
  67.      
  68.         #把請求轉發給後臺web服務器,反向代理和fastcgi的區別是,反向代理後面是web服務器,fastcgi後臺是fasstcgi監聽進程,當然,協議也不一樣。      
  69.         location / {      
  70.             proxy_pass      http://127.0.0.1:8080;      
  71.         }      
  72.     }      
  73.      
  74.     #upstream的負載均衡,weight是權重,可以根據機器配置定義權重。據說nginx可以根據後臺響應時間調整。後臺需要多個web服務器。      
  75.     upstream big_server_com {      
  76.         server 127.0.0.3:8000 weight=5;      
  77.         server 127.0.0.3:8001 weight=5;      
  78.         server 192.168.0.1:8000;      
  79.         server 192.168.0.1:8001;      
  80.     }      
  81.      
  82.     server {      
  83.         listen          80;      
  84.         server_name     big.server.com;      
  85.         access_log      logs/big.server.access.log main;      
  86.      
  87.         location / {      
  88.                 proxy_pass      http://big_server_com;      
  89.         }      
  90.     }      
  91. }   

上面說的include的幾個文件,都沒有必要改,用的時候include一下就可以。

fastcgi.conf

  1. # fastcgi.conf      
  2. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;      
  3. fastcgi_param  QUERY_STRING       $query_string;      
  4. fastcgi_param  REQUEST_METHOD     $request_method;      
  5. fastcgi_param  CONTENT_TYPE       $content_type;      
  6. fastcgi_param  CONTENT_LENGTH     $content_length;      
  7. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;      
  8. fastcgi_param  REQUEST_URI        $request_uri;      
  9. fastcgi_param  DOCUMENT_URI       $document_uri;      
  10. fastcgi_param  DOCUMENT_ROOT      $document_root;      
  11. fastcgi_param  SERVER_PROTOCOL    $server_protocol;      
  12. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;      
  13. fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;      
  14. fastcgi_param  REMOTE_ADDR        $remote_addr;      
  15. fastcgi_param  REMOTE_PORT        $remote_port;      
  16. fastcgi_param  SERVER_ADDR        $server_addr;      
  17. fastcgi_param  SERVER_PORT        $server_port;      
  18. fastcgi_param  SERVER_NAME        $server_name;      
  19.      
  20. fastcgi_index  index.php;     
  21.     
  22. # PHP only, required if PHP was built with --enable-force-cgi-redirect      
  23. fastcgi_param  REDIRECT_STATUS    200;   

proxy.conf

  1. # proxy.conf      
  2. proxy_redirect          off;      
  3. proxy_set_header        Host            $host;      
  4. proxy_set_header        X-Real-IP       $remote_addr;      
  5. proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;      
  6. client_max_body_size    10m;      
  7. client_body_buffer_size 128k;      
  8. proxy_connect_timeout   90;      
  9. proxy_send_timeout      90;      
  10. proxy_read_timeout      90;      
  11. proxy_buffers           32 4k;    

mine.types

  1. # mime.types      
  2. types {      
  3.     text/html                             html htm shtml;      
  4.     text/css                              css;      
  5.     text/xml                              xml rss;      
  6.     image/gif                             gif;      
  7.     image/jpeg                            jpeg jpg;      
  8.     application/x-javascript              js;      
  9.     text/plain                            txt;      
  10.     text/x-component                      htc;      
  11.     text/mathml                           mml;      
  12.     image/png                             png;      
  13.     image/x-icon                          ico;      
  14.     image/x-jng                           jng;      
  15.     image/vnd.wap.wbmp                    wbmp;      
  16.     application/java-archive              jar war ear;      
  17.     application/mac-binhex40              hqx;      
  18.     application/pdf                       pdf;      
  19.     application/x-cocoa                   cco;      
  20.     application/x-java-archive-diff       jardiff;      
  21.     application/x-java-jnlp-file          jnlp;      
  22.     application/x-makeself                run;      
  23.     application/x-perl                    pl pm;      
  24.     application/x-pilot                   prc pdb;      
  25.     application/x-rar-compressed          rar;      
  26.     application/x-redhat-package-manager  rpm;      
  27.     application/x-sea                     sea;      
  28.     application/x-shockwave-flash         swf;      
  29.     application/x-stuffit                 sit;      
  30.     application/x-tcl                     tcl tk;      
  31.     application/x-x509-ca-cert            der pem crt;      
  32.     application/x-xpinstall               xpi;      
  33.     application/zip                       zip;      
  34.     application/octet-stream              deb;      
  35.     application/octet-stream              bin exe dll;      
  36.     application/octet-stream              dmg;      
  37.     application/octet-stream              eot;      
  38.     application/octet-stream              iso img;      
  39.     application/octet-stream              msi msp msm;      
  40.     audio/mpeg                            mp3;      
  41.     audio/x-realaudio                     ra;      
  42.     video/mpeg                            mpeg mpg;      
  43.     video/quicktime                       mov;      
  44.     video/x-flv                           flv;      
  45.     video/x-msvideo                       avi;      
  46.     video/x-ms-wmv                        wmv;      
  47.     video/x-ms-asf                        asx asf;      
  48.     video/x-mng                           mng;      
  49. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章