nginx 의 기본 설정 과 가상 호스트 설정

5033 단어 nginx
【 nginx.conf 】

#    
user www-data;

#    ,       cpu     ;  cat /proc/cpuinfo  cpu  , cpu cores       
worker_processes  1;

#       PID  (/usr/local/nginx/logs/error.log)
error_log  /var/log/nginx/error.log;
#  id    (/usr/local/nginx/logs/nginx.pid)
pid           /var/run/nginx.pid;
#          
events {
    use   epoll;                            #epoll     IO(I/O Multiplexing)      ,     linux2.6    ,      nginx   
    worker_connections  1024;     #    worker process          
    # multi_accept on;                # nginx           ,         ,   worker_connections      ,         
}
#  http   ,                  
http {
    #  mime  ,   mime.type    ,    mime.type  (/usr/local/nginx/conf/mime.types)
    #MIME(Multipurpose Internet Mail Extensions)            .
    include       /etc/nginx/mime.types;
    #              
    default_type  application/octet-stream;
    #      (/usr/local/nginx/logs/access.log)
    access_log    /var/log/nginx/access.log;
   
    #         nginx    ,            。
    server_tokens off;

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

    #      keep-alive      
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #  nginx      ,         ;          ,            ,                      
    tcp_nodelay        on;
    
    #  gzip  
    gzip  on;
    #        gzip  。     IE6                   。
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    #      
 、、   client_header_buffer_size    1k;
   、、 large_client_header_buffers  4 4k;

    open_file_cache max=100000 inactive=20s;     #                 ,       ;                 ,              20     。
    open_file_cace_valid 30s;                                # open_file_cache              
    open_file_cache_min_uses 2;                           #   open_file_cache                   
    open_file_cache_errors on;                              #                   ,             。           ,            。               ,                。


    #         
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
   
    #            
    upstream mysvr {
         #weigth      ,             
         #    Squid  3128  
         server 192.168.8.1:3128 weight=5;
         server 192.168.8.2:80  weight=1;
         server 192.168.8.3:80  weight=6;
    }

    server {
        #  80  
        listen       80;
        #    www.xx.com  
        server_name  www.xx.com;
        #            
        access_log  logs/www.xx.com.access.log  main;
       
        #    
        location / {
            root   /root;      #               
            index index.php index.html index.htm;   #           
            fastcgi_pass  www.xx.com;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name; 
            include /etc/nginx/fastcgi_params;
        }
       
        #         
        error_page   500 502 503 504 /50x.html;  
             location = /50x.html {
             root   /root;
        }

        #    ,nginx    
        location ~ ^/(images|javascript|js|css|flash|media|static)/ {
             root /var/www/virtual/htdocs;
             #  30 ,         ,        ,      ,         。
             expires 30d;
        }

        #PHP           FastCGI  .   FastCGI    .
        location ~ \.php$ {
             root /root;
             fastcgi_pass 127.0.0.1:9000;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;
             include fastcgi_params;
        }

        #    Nginx     
        location /NginxStatus {
             stub_status            on;
             access_log              on;
             auth_basic              "NginxStatus";
             auth_basic_user_file  conf/htpasswd;
        }

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


"               "
  : 
1.  nginx.conf  http  ,   server          ,          ,     server   ; 
2.                   ,     http    include  ,  : include vhost/dog.farwish.conf; 
3.   dog.farwish.conf   server      ,  :


server {
    listen       80;
    server_name  dog.farwish.com;

    location / {
        index  index.html index.htm index.php;
        root   /home/www/dog;
        if (!-e $request_filename){   
            rewrite ^(.*)$ /index.php/?s=$1 last; # TP rewrite  
            break;
        }
 
        autoindex on;
    }   

    location ~ \.php {
        root           /home/www/dog;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }   
}
#       nginx1.6.2             .







좋은 웹페이지 즐겨찾기