nginx. conf 설정 예제

3806 단어
설정 상세 설명
# https://www.iteye.com/blog/aokunsang-2058787

#    
user  nginx;
#    ,       cpu      
worker_processes auto;

#        PID   
error_log /var/nginx/logs/error.log;
pid  /var/nginx/logs/nginx.pid;
#     
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';

# $remote_addr  $http_x_forwarded_for          ip   ;
# $remote_user :           ;
# $time_local :            ;
# $request :         url   http   ;
# $status :         ;    200,
# $body_bytes_s ent :                ;
# $http_referer :                ;
# $http_user_agent :              ;


#           
events {
	multi_accept on; #  nginx                   
	worker_connections 1024; #     worker process           
	use epoll; #epoll       IO(I/O Multiplexing)      ,      linux2.6     ,       nginx    
}

#   http    ,                  
http {
    charset utf-8;
    include /etx/nginx/mine.types; #   mime   ,    mime.type     
	sendfile on; #     nginx      sendfile   (zero copy  )     ,      ,     on,              IO     ,     off,         I/O     ,      uptime
	tcp_nopush on; #  nginx              ,          
	tcp_nodelay on; #  nginx      ,         --          ,            ,                      
	#server_tokens off; #            nginx    ,            
	log_not_found off;
	types_hash_max_size 2048;
	#       
	client_max_body_size 16M;
	
	#         (  )     。            。  
    client_header_timeout 10;  
    client_body_timeout 10;  
	keepalive_timeout  65; #      keep-alive      。                 。           ngnix         
	gzip on; #   gzip   

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log warn;


    #            
    upstream mysvr {
        #weigth       ,             
        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 {
    	listen 80; #   80   
        server_name www.xx.com; #     www.xx.com   
        access_log logs/www.xx.com.access.log access; #            
        
    	root /app;

        gzip on;
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;

        error_page 500 502 503 504 /50x.html; #         

    	#    
        location / {
            proxy_pass http://tomcat:8080/index #   
            root /root; #               
            index index.php index.html index.htm; #           
        }

        location = /favicon.ico {
        	log_not_found off;
        	access_log off;
        }

        location = /robots.txt {
        	log_not_found off;
        	access_log off;
        }

        #    ,nginx     
        location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
        	expires 30d; #  30 ,         ,        ,      ,         
        	access_log off;
        }

        location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
        	add_header Access-Control-Allow-Origin "*";
        	expires 30d;
        	access_log off;
        }
    }
}


location 문법
    : location [=|~|~*|^~] /uri/ { … }
=         
^~      uri           ,      url     。nginx    url   
 ,     /static/20%/aa,     ^~ /static/ /aa    (     )。
~               
~*                
!~ !~*                         
/     ,         。
   location            
     =,    ^~,               ,      /     。 
       ,    ,           。

좋은 웹페이지 즐겨찾기