nginx 실전 - 프로필 상세 설명

nginx 프로필 상세 설명
A 파일 경로: yum 설치 시 / etc / nginx / nginx. conf 에 있 습 니 다.컴 파일 설치 가 보통 / usr / local / nginx / conf / nginx. conf 에 있 습 니 다.
B 컴 파일 설치 후 프로필 상세 설명
1) 프로필 구조
전역 설정 (user, worker processes, error log, pid)
이벤트 (네트워크 연결 관련, worker connections)
http (가장 중요 한 부분, 대부분의 기능 을 여기에 놓 습 니 다)
server (가상 호스트 관련)
위치 (서버 내)
2) 전역 설정 항목 구조
user nobody;
    nginx     ,      ,  user nobody nobody;
worker_processes 2;
  nginx     ,          ,        cpu      。
         ,      auto,         。

    CPU  
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

    CPU   
cat /proc/cpuinfo| grep "processor"| wc -l
error_log logs/error.log
         ,       (  prefix   ),        。
          ,      http、server、location 
error_log logs/error.log notice
              .
      :          [debug|info|notice|warn|error|crit|alert|emerg],           。
        crit
pid logs/nginx.pid;
  nginx  pid      ,       ,        。
worker_rlimit_nofile 100000;
  nginx         。       ,        (ulimit -n)       。
      ,nginx    “too many open files”   。

3) 이벤트 설정 항목 구조
worker_connections 1024;
    work_process          ,             。       1W  
accept_mutex on;
                    ,                  ,             。
Nginx  accept_mutex   onNginxworker processer)          ,          。
    on
multi_accept on;
nginx worker processer                  ,          on
   off,   worker process
use epoll;
Nginx                      。
       :select、poll、kqueue、epoll、rtsing、/dev/poll  eventport。

* select:   Windows   ,                  

* poll:Nginx    ,            

* kqueue:     FreeBSD 4.1+, OpenBSD2.9+, NetBSD 2.0,   MacOS X        

* epoll:       Linux 2.6+         

* rtsig:    ,   Linux 2.2.19    ,            

* /dev/poll: Solaris 7 11/99+,HP/UX 11.22+, IRIX 6.5.15+, and Tru64 UNIX 5.1A+          

* eventport: Solaris 10        

       epoll  

4) http 설정 항목
공식 문서http://nginx.org/en/docs/ 참조 링크:https://segmentfault.com/a/1190000012672431 참조 링크:https://segmentfault.com/a/1190000002797601 참조 링크: http 의 headerhttps://kb.cnblogs.com/page/92320/
MIME-Type
include       mime.types;  //cat conf/mime.types
  nginx            ( ,  、html、js、css、    )

default_type  application/octet-stream;
     type,       ,   text/plain.   

#       : 
cat /usr/local/nginx/conf/mime.types
log_format

log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

  main        ,    nginx             。
access_log logs/access.log main;

                ,      server      。 
       main,       .>>>>     ,     log_format    zcy,    access_log logs/access.log zcy;  
sendfile on;

    sendfile      ,   off,  sendfile    ,    user mode kernel mode   ,         。
         onIOoffI/O

    
sendfile_max_chunk 128k;

     Nginx worker process    sendfile()          ,    00     

  sendfile        
tcp_nopush on; 

 tcp_nopush   ontcp_cork
             :          ,         ,                 ,    。             。
    on。  :      、   ,           ,      
keepalive_timeout 65 60;

       ,      nginx                       ,    ,   75s。
        ,               ,    curl -I  header      Keep-Alive: timeout=60,           。
        ,                     ,Nginx        。             。
send_timeout

                , Nginx             ,                。
        send_timeout       ,  Nginx        。
client_max_body_size 10m;

          HTTP      ,       Content-Length  ,client_max_body_size     Content-Length       。
            Nginx      HTTP  ,               。   413   。
  ,        1GB   ,Nginx      ,  Content-Length  client_max_body_size    ,
     413(Request Entity Too Large)      。
gzip on
    gzip  。
gzip_min_length 1k;

              ,      header  content-length201k    ,  1k       。
gzip_buffers 4 16k; 

           buffer    gzip        。4 16k    4 16k buffer
gzip_http_version 1.1;

     http      ,          Gzip   ,       ,                 。
     Nginx          Gzip    ,       http/1.1,      1.1。
gzip_comp_level 6;

gzip   ,1           ,9            (        cpu)
gzip_types mime-type ... ;

  mime      ,      ,”text/html”         。
 conf/mime.conf      type。

  :gzip_types       text/plain application/x-javascript text/css text/html application/xml;
gzip_proxied any;

Nginx           ,                      ,                  ”Via”  header 。

       :
off -               
expired -header     "Expires"    
no-cache -header     "Cache-Control:no-cache"    
no-store -header     "Cache-Control:no-store"    
private -header     "Cache-Control:private"    
no_last_modified -     ,  header      "Last-Modified"    
no_etag -      ,  header      "ETag"    
auth -      ,   header     "Authorization"    
any -        
gzip_vary on

 http    ,        Vary: Accept-Encoding ,               gzip     ,  , Squid    Nginx     。

5) 서버 설정 항목
  • ngix. conf 서버 부분 설정
  • server{}    http{}server{}        (  )。

    2) 다음은 nginx. conf 설정 파일 의 server {} 부분 내용 입 니 다.
    server {
        listen       80;  //     80,         ,     IP  , ,listen 127.0.0.1:8080;
        server_name  localhost; //      ,     ,     。
        #charset koi8-r; //        ,     ,          。
        #access_log  logs/host.access.log  main; //      ,       server(      )           。
    
        ## server{}    location   
        location / {
            root   html;  //       ,                 。
            index  index.html index.htm; //        (   )。
        }
    
        #error_page  404              /404.html;  //  404  
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;  //     500、502、503、504 ,   50x.html
        location = /50x.html {
            root   html;  //  50x.html    
        }
    
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #    php   ,     location{}    
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;  //proxy_pass        url  , proxy_pass    。
        #}
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;  //  FastCGI          ,      ,1 IP:Port, 2 unix:/path/to/sockt
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  //  SCRIPT_FILENAME  ,     /scripts    root     
        #    include        fastcgi_params; //  prefix/conf/fastcgi_params  ,      fastcgi     
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        # 
        #location ~ /\.ht {   //   url , /.ht   , ,www.example.com/.htaccess,    ,  403   。
        #    deny  all;  //   all        。
        #}
    }
    
    
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;  //  8000  
    #    listen       somename:8080;  //  ip:port
    #    server_name  somename  alias  another.alias;  //    server_name
    
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    
    
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;  //  443  , ssl
    #    server_name  localhost;
    
    ###    ssl    
    #    ssl_certificate      cert.pem;    //  pem    
    #    ssl_certificate_key  cert.key;  //  key    
    
    #    ssl_session_cache    shared:SSL:1m;  //  session cache  
    #    ssl_session_timeout  5m;  //  session    
    #    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   //  ssl  
    #    ssl_ciphers  HIGH:!aNULL:!MD5;  //  ssl  
    #    ssl_prefer_server_ciphers  on;  //         
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    좋은 웹페이지 즐겨찾기