Nginx 의 전체 설정 설명 및 인 스 턴 스 코드

3712 단어
Nginx 의 전체 설정 설명
           최근 회사 의 새로운 프로젝트 는 자신 이 소 백 이기 때문에 프로젝트 매니저 를 따라 Nginx 를 배치 하고 인터넷 에서 관련 자 료 를 찾 았 습 니 다. 괜 찮 고 설정 을 완성 할 수 있 습 니 다. 여기에 기록 하 세 요.
인 스 턴 스 코드:

#    
user nobody;
#    ,      cpu     
worker_processes 1;

#       PID  
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid    logs/nginx.pid;

#          
events {
  #epoll     IO(I/O Multiplexing)      ,
  #   linux2.6    ,      nginx   
  use  epoll; 

  #    worker process            
  worker_connections 1024;

  #       worker_processes   worker_connections    
  #   max_clients = worker_processes * worker_connections
  #             ,max_clients = worker_processes * worker_connections / 4    
  #             4,         
  #       ,      Nginx Server           :4 * 8000 = 32000
  # worker_connections              
  #      IO  ,max_clients                 
  #                      ,  1GB                 10   
  #      360M   VPS             :
  # $ cat /proc/sys/fs/file-max
  #    34336
  # 32000 < 34336,                      ,                 
  #   ,worker_connections       worker_processes                            
  #                        
  #              CPU       
  #   ,                  ,                     。
  # ulimit -SHn 65535

}


http {
  #  mime  ,   mime.type    
  include  mime.types;
  default_type application/octet-stream;
  #      
  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';

  access_log logs/access.log main;

  #sendfile      nginx      sendfile   (zero copy   )     ,
  #      ,     on,
  #             IO     ,     off,
  #        I/O    ,     uptime.
  sendfile   on;
  #tcp_nopush   on;

  #      
  #keepalive_timeout 0;
  keepalive_timeout 65;
  tcp_nodelay   on;

  #  gzip  
  gzip on;
  gzip_disable "MSIE [1-6].";

  #      
  client_header_buffer_size  128k;
  large_client_header_buffers 4 128k;


  #        
  server {
    #  80  
    listen  80;
    #     www.nginx.cn  
    server_name www.nginx.cn;

    #               
    root html;

    #            
    access_log logs/nginx.access.log main;

    #    
    location / {

      #           
      index index.php index.html index.htm;  

    }

    #         
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
    }

    #    ,nginx    
    location ~ ^/(images|javascript|js|css|flash|media|static)/ {

      #  30 ,         ,        ,
      #      ,         。
      expires 30d;
    }

    #PHP           FastCGI  .   FastCGI    .
    location ~ .php$ {
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }

    #     .htxxx   
      location ~ /.ht {
      deny all;
    }

  }
}

읽 어 주 셔 서 감사합니다. 여러분 에 게 도움 이 되 기 를 바 랍 니 다. 본 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기