nginx 설정정리
1. nginx 설정(universal drective)
위치 : /etc/nginx/nginx.conf
| 
user  nginx; 
#몇개의 thread가 사용될지 정의한다. cpu cores 수를 넣어주면 된다. 
worker_processes  6;   
error_log  /var/log/nginx/error.log warn; 
pid        /var/run/nginx.pid; 
events {  
   # worker process 하나당 몇개의 connection을 처리할지 뜻한다. (최대처리량 = worker process * worker connection) 
    worker_connections  1024;  
} 
http { 
    include       /etc/nginx/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  /var/log/nginx/access.log  main; 
    sendfile        on; 
    #tcp_nopush     on; 
    keepalive_timeout  65; 
    #gzip  on; 
   #http 설정 경로 
    include /etc/nginx/conf.d/*.conf;  
} | 
2. nginx http 설정
위치 : /etc/nginx/conf.d/*.conf
정적파일 caching 
아래 같을대 정적파일 경로는 root field에 지정하는데 경로는 접근할 주소의 uri를 제외한 서버 절대경로를 입력하면 된다.
| 
    location ~* ^.+.(data)$ 
    { 
        #expire 기간설정(1달) 
        expires 1M;  
        access_log off; 
        add_header Cache-Control "public"; 
       #정적파일 경로 설정(http 경로에서 uri를 제외한 서버 절대경로 
        root /www/seastory/file/;  
    } 
    #확장자 구분(정규식을 이용하여 설정) 
    location ~* ^.+.(?:jpg|jpeg|gif|png|ico)$ {  
        #expire 기간설정(1년) 
        expires 1y;   
        access_log off; 
        add_header Cache-Control "public"; 
    } 
    #경로를 이용하여 설정 
    location /static/ {  
        expires 1y; 
        access_log off; 
        add_header Cache-Control "public"; 
    } | 
was 연동
| 
    location / { 
        proxy_cache sf_zone; 
        proxy_cache_bypass $http_cache_control; 
        add_header X-Proxy-Cache $upstream_cache_status; 
        #임의로 생성한 설정파일 /etc/nginx/proxy_params 파일을 include 한다. 
        include proxy_params;  
        #was 주소를 입력 
        proxy_pass http://127.0.0.1:3000/;  
    } | 
* proxy_params
| 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header Host $http_host; 
proxy_set_header X-NginX-Proxy true; 
client_max_body_size 100M; 
client_body_buffer_size 1m; 
proxy_intercept_errors on; 
proxy_buffering on; 
proxy_buffer_size 128k; 
proxy_buffers 256 16k; 
proxy_busy_buffers_size 256k; 
proxy_temp_file_write_size 256k; 
proxy_max_temp_file_size 0; 
proxy_read_timeout 300; 
proxy_redirect off; | 
가상호스트(Vertual Host) - 참조(http://www.programkr.com/blog/MYTN5ADMwYT4.html)
| 
http 
{ 
    #첫 번째 가상 호스트 
    server 
    { 
        #감청 포트 
        listen       80; 
        #호스트 이름 
        server_name      aaa.domain.com; 
        #접근 로그 파일 저장 경로 
        access_log logs/aaa.domain.com.access.log combined; 
        location  / 
        { 
             #기본 홈 페이지 파일 순서 오른쪽에서 만약 찾지 않으면 일을 ndex.html 파일 찾기 index.htm 파일 로서 홈 페이지 파일 
             index  index.html  index.htm; 
            #웹 파일 저장 HTML 디렉터리 
            root   /data0/htdocs/aaa. domain. com; 
        } 
    } 
    #두 번째 가상 호스트 
    server 
    { 
        #감청 IP, 포트 
        listen      80; 
        #호스트 이름 
        server_name       bbb.otherdomain.com; 
        #접근 로그 파일 저장 경로 
        access_log  logs/bbb.otherdomain.com.access.log.combined; 
        location  / 
        { 
            #기본 홈 페이지 파일 순서 오른쪽에서 만약 찾지 않으면 index.html 파일 찾기 index.htm 파일 로서 홈 페이지 파일 
            index    index.html    index.htm; 
            #웹 파일 저장 HTML 디렉터리 
            root  /data0/htdocs/bbb.otherdomain.com; 
         } 
     } 
    #세 번째 가상 호스트 
    server 
    { 
        #감청 IP, 포트 
        listen      80; 
        #호스트 이름 
        server_name     www.domain.com domain.com   *.domain.com; 
        #접근 로그 파일 저장 경로 
        access_log logs/bbb.domain.com.access.log  combined; 
        location  / 
        { 
            #기본 홈 페이지 파일 순서 오른쪽에서 만약 찾지 않으면 index.html 파일 찾기 index.htm 파일 로서 홈 페이지 파일 
            index  index.html  index.htm; 
            #웹 파일 저장 HTML 디렉터리 
            root /data0/htdocs/domain.com; 
         } 
    } 
} | 
댓글
댓글 쓰기