현상 을 통 해 본질 보기 - Nginx 프로필 상세 설명
                                            
 14293 단어  Nginxnginx. conf 파일 설명
                    
머리말
앞의 글 은 Nginx 프로 세 스 모델 과 비동기 비 차단 체 제 를 바탕 으로 Nginx 가 높 은 병행 을 지원 하 는 내용 을 담 고 있다.본 고 는 Nginx 의 프로필 (메 인 프로필 nginx. conf 파일) 과 Nginx 의 시스템 구 조 를 상세 하 게 설명 할 것 입 니 다.
Nginx 프로필 개요
압축 을 푼 Nginx 디 렉 터 리 의 conf 디 렉 터 리 아래 는 Nginx 와 관련 된 프로필 입 니 다. 물론 일반적으로 우 리 는 Nginx 의 프로필 이 많 고 다른 프로필 은 모두 텍스트 파일 입 니 다.그러면 이 소절 은 그 중의 주요 설정 에 대해 설명 하고 소개 합 니 다.
물론 소개 하기 전에 개념 을 말 할 필요 가 있다.
1. 명령 과 명령 파라미터
명령 과 명령 매개 변 수 는 Nginx 의 설정 항목 을 구성 하고 Nginx 의 주 설정 파일 에는 몇 가지 설정 항목 이 포함 되 어 있 습 니 다.명령 은 문자열 입 니 다. 예 를 들 어 errorpage。명령 매개 변 수 는 하나 이상 의 TOKEN 문자열 로 구성 되 어 있 으 며, TOKEN 문자열 사이 에 TAB 또는 빈 칸 이 있 습 니 다.
예: 500 502 503 504 / 50x. html
물론 TOKEN 문자열 도 큰 괄호 ({}) 로 묶 은 내용 일 수 있 습 니 다. 우 리 는 복합 구성 블록 이 라 고 부 르 고 명령 과 결합 하면 복합 구성 항목 이 라 고 부 릅 니 다.
예:
location / {
            root   /home/lokott/build/html;
            index  index.html index.htm;
        }2. 명령 컨 텍스트
인위적으로 nginx. conf 파일 을 논리 적 으로 분류 하 는 것 으로 이해 할 수 있 습 니 다. 문맥 은 분 단 된 역할 영역 으로 이해 되 고 여러 가지 가 있 습 니 다.서로 다른 역할 영역 에는 하나 이상 의 설정 항목 이 포함 되 어 있 습 니 다.
Nginx 가 지원 하 는 명령 어 컨 텍스트 를 열거 합 니 다.
물론 지령 상하 문 에 포 함 된 상황 이 발생 할 수 있다.예 를 들 어 http 에 여러 개의 server 세그먼트 가 포함 되 어 있 습 니 다.잘 풀 린 프로필 을 대조 해서 볼 수 있 습 니 다. (여기 서 일부분 을 캡 처 합 니 다)
#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    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        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    }
}
Nginx 메 인 프로필 설명
#  Nginx         
user nginx nginx;
#nginx   ,       CPU    。
worker_processes 8;
#          ,[ debug | info | notice | warn | error | crit ]
error_log /usr/local/nginx/logs/error.log info;
#  pid  
pid /usr/local/nginx/logs/nginx.pid;
#              :  
#          
#         nginx              ,             (ulimit -n) nginx     ,  nginx           ,     ulimit -n       。
#   linux 2.6           65535,worker_rlimit_nofile       65535。
#    nginx                  ,      10240,      3-4          10240 ,     502  。
worker_rlimit_nofile 65535;
events
{
    #      ,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll  
    # Linux 2.6             I/O  ,linux  epoll,    FreeBSD  ,  kqueue  。
    #    :
    # apache  ,nginx         ,        
    #A)      
    #Select、poll        ,               ,nginx   select poll
    #B)      
    #Kqueue:   FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0   MacOS X.       MacOS X    kqueue         。
    #Epoll:   Linux  2.6        。
    #/dev/poll:   Solaris 7 11/99+,HP/UX 11.22+ (eventport),IRIX 6.5.15+   Tru64 UNIX 5.1A+。
    #Eventport:   Solaris 10。              ,          。
    use epoll;
    #         (     =   *   )
    #      ,            ,   ,    cpu  100%  。            ,     nginx          。
    worker_connections 65535;
    #keepalive    。
    keepalive_timeout 60;
    #             。                 ,              1k,              1k,           。
    #         getconf PAGESIZE   。
    #  [root@lokott ~]# getconf PAGESIZE
    #4096
    #   client_header_buffer_size  4k   ,  client_header_buffer_size       “      ”    。
    client_header_buffer_size 4k;
    #            ,        ,max      ,          ,inactive                   。
    open_file_cache max=65535 inactive=60s;
    #                   。
    #  :open_file_cache_valid time    :open_file_cache_valid 60     :http, server, location              open_file_cache          .
    open_file_cache_valid 80s;
    #open_file_cache    inactive              ,        ,               ,   ,        inactive         ,     。
    #  :open_file_cache_min_uses number    :open_file_cache_min_uses 1     :http, server, location          open_file_cache                          ,        ,      cache       .
    open_file_cache_min_uses 1;
    #  :open_file_cache_errors on | off    :open_file_cache_errors off     :http, server, location                   cache  .
    open_file_cache_errors on;
}
#  http   ,                  
http
{
    #             
    include mime.types;
    #      
    default_type application/octet-stream;
    #    
    #charset utf-8;
    #      hash   
    #        hash     server_names_hash_max_size  server_names_hash_bucket_size    。  hash bucket size    hash    ,               。              ,          hash       。  hash bucket size            ,         ,                2。             ,               。  ,  Nginx      hash max size   hash bucket size   ,                .
    server_names_hash_bucket_size 128;
    #             。                 ,               1k,              1k,           。         getconf PAGESIZE  。
    client_header_buffer_size 32k;
    #         。nginx    client_header_buffer_size  buffer   header ,  header  ,    large_client_header_buffers   。
    large_client_header_buffers 4 64k;
    #    nginx       
    client_max_body_size 8m;
    #          ,sendfile    nginx    sendfile       ,         on,             IO     ,    off,        I/O    ,       。  :              off。
    #sendfile     nginx     sendfile   (zero copy   )     ,      ,    on。             IO     ,    off,        IO    ,    uptime。
    sendfile on;
    #        ,       ,    。
    autoindex on;
    #          socke TCP_CORK   ,       sendfile     
    tcp_nopush on;
    tcp_nodelay on;
    #       ,    
    keepalive_timeout 120;
    #FastCGI              :      ,      。             。
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    #gzip    
    gzip on; #  gzip    
    gzip_min_length 1k;    #        
    gzip_buffers 4 16k;    #     
    gzip_http_version 1.0;    #    (  1.1,     squid2.5   1.0)
    gzip_comp_level 2;    #    
    gzip_types text/plain application/x-javascript text/css application/xml;    #    ,       textml,          ,         ,      warn。
    gzip_vary on;
    #    IP          
    #limit_zone crawler $binary_remote_addr 10m;
    #      
    upstream lokott.chses.cn {
        #upstream     ,weight   ,            。weigth      ,             。
        server 192.168.80.121:80 weight=3;
        server 192.168.80.122:80 weight=2;
        server 192.168.80.123:80 weight=3;
        #nginx upstream    4      
        #1、  (  )
        #                      ,       down ,     。
        #2、weight
        #      ,weight        ,              。
        #  :
        #upstream bakend {
        #    server 192.168.0.14 weight=10;
        #    server 192.168.0.15 weight=10;
        #}
        #3、ip_hash
        #       ip hash    ,                 ,    session   。
        #  :
        #upstream bakend {
        #    ip_hash;
        #    server 192.168.0.14:88;
        #    server 192.168.0.15:80;
        #}
        #4、fair(   )
        #                ,          。
        #upstream backend {
        #    server server1;
        #    server server2;
        #    fair;
        #}
        #4、url_hash(   )
        #   url hash       ,   url           ,             。
        # : upstream   hash  ,server       weight      ,hash_method    hash  
        #upstream backend {
        #    server squid1:3128;
        #    server squid2:3128;
        #    hash $request_uri;
        #    hash_method crc32;
        #}
        #tips:
        #upstream bakend{#         Ip     }{
        #    ip_hash;
        #    server 127.0.0.1:9090 down;
        #    server 127.0.0.1:8080 weight=2;
        #    server 127.0.0.1:6060;
        #    server 127.0.0.1:7070 backup;
        #}
        #          server    proxy_pass http://bakend/;
        #          :
        #1.down     server       
        #2.weight weight  ,        。
        #3.max_fails:            1.        ,  proxy_next_upstream       
        #4.fail_timeout:max_fails    ,     。
        #5.backup:       backup  down      ,  backup  。           。
        #nginx             ,      server   。
        #client_body_in_file_only   On    client post              debug
        #client_body_temp_path                3   
        #location URL    .                    
    }
    #       
    server
    {
        #    
        listen 80;
        #       ,     
        server_name www.lokott.cn lokott.cn;
        index index.html index.htm index.php;
        root /data/www/lokott;
        # ******      
        location ~ .*.(php|php5)?$
        {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
        #        
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires 10d;
        }
        #JS CSS      
        location ~ .*.(js|css)?$
        {
            expires 1h;
        }
        #      
        #$remote_addr $http_x_forwarded_for        ip  ;
        #$remote_user:           ;
        #$time_local:            ;
        #$request:        url http  ;
        #$status:         ;   200,
        #$body_bytes_sent :                ;
        #$http_referer:                ;
        #$http_user_agent:            ;
        #  web            ,           IP   ,  $remote_add   IP           iP  。             http    ,    x_forwarded_for  ,          IP                 。
        log_format access '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" $http_x_forwarded_for';
        #            
        access_log  /usr/local/nginx/logs/host.access.log  main;
        access_log  /usr/local/nginx/logs/host.access.404.log  log404;
        #  "/"       
        location / {
            proxy_pass http://127.0.0.1:88;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            #   Web       X-Forwarded-For      IP
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #            ,  。
            proxy_set_header Host $host;
            #                
            client_max_body_size 10m;
            #                  ,
            #             ,  256k,  ,    firefox  IE   ,       256k   ,    。       ,     client_body_buffer_size  ,              ,8k  16k,      。
            #    firefox4.0  IE8.0,       ,200k     ,   500 Internal Server Error  
            client_body_buffer_size 128k;
            #   nginx  HTTP     400       。
            proxy_intercept_errors on;
            #            _            
            #nginx            (      )
            proxy_connect_timeout 90;
            #           (      )
            #           _                       
            proxy_send_timeout 90;
            #     ,         (      )
            #     _           _                 (                 )
            proxy_read_timeout 90;
            #       (nginx)             
            #                        ,                    ,              proxy_buffers            ,           
            proxy_buffer_size 4k;
            #proxy_buffers   ,     32k     
            #        (        )         ,          ,            4k  8k
            proxy_buffers 4 32k;
            #        (proxy_buffers*2)
            proxy_busy_buffers_size 64k;
            #     proxy_temp_path      ,                  
            #         ,     ,  upstream    
            proxy_temp_file_write_size 64k;
        }
        #    Nginx     
        location /NginxStatus {
            stub_status on;
            access_log on;
            auth_basic "NginxStatus";
            auth_basic_user_file confpasswd;
            #htpasswd        apache   htpasswd     。
        }
        #            
        #  jsp      tomcat resin  
        location ~ .(jsp|jspx|do)?$ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8080;
        }
        #       nginx       tomcat resin
        location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|
        pdf|xls|mp3|wma)$
        {
            expires 15d; 
        }
        location ~ .*.(js|css)?$
        {
            expires 1h;
        }
    }
}이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
linux2에 nginx 설치설치 가능한 nginx를 확인하고, 해당 nginx를 설치한다. localhost 혹은 해당 ip로 접속을 하면 nginx 화면을 볼 수 있다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.