리눅스

Reverse Proxy nginx.conf 설정하기

macro 2012. 4. 2. 16:51
반응형


/etc/nginx/nginx.conf

  • proxy_buffer_size 및 proxy_buffers 가 작을때에는 이미지처럼 파일 사이즈가 큰 것들이 잘릴 수 있다.
user  ilocal;
worker_processes 4;

#error_log  /var/log/nginx/error.log warn;
error_log  /home/ilocal/nginx/logs/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
    use epoll;
    accept_mutex        off;
}


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  /home/ilocal/nginx/logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  65;
    keepalive_timeout  30;

    tcp_nodelay        on;

    # reverse proxy setting
    proxy_redirect off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

    client_max_body_size    10m;
    client_body_buffer_size 128k;

    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;

    proxy_buffer_size          16k;
    proxy_buffers              16 128k;
#    proxy_busy_buffers_size    32k;
#    proxy_temp_file_write_size 32k;


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


    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

upstream dynamic_balance {
        server 192.168.11.40;
}


server {
    listen       80;
    server_name  localhost;

    location /images/uc {

                # pass to c_img web server
                #proxy_pass http://image_balance$request_uri;
                proxy_pass http://192.168.10.231;
    }
        location ~* \.(jpeg|jpg|png|gif)$ {
                access_log   off;
                expires      max;
       #         add_header   Last-Modified "Thu, 26 Mar 2000 17:35:45 GMT";
                set $memcached_key $uri;
                memcached_pass     192.168.11.43:11211;
                error_page         404 = @cache_miss;
        }
        location @cache_miss {
                #proxy_pass http://dynamic_balance$request_uri;
                root    /home/ilocal/www;
        }

        location /static/js {
                root    /home/ilocal/www;
        }
        location /static/css {
                root    /home/ilocal/www;
        }

        location / {
                proxy_pass http://dynamic_balance$request_uri;
         }


    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ /\.ht {
        deny  all;
    }

반응형