ngnix 实践配置

ngnix.conf文件

user  root;
worker_processes  1;

error_log  logs/error.log crit;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
        use epoll;
    worker_connections  1024;
}


http {
    include       mime.types;
    include                ccproxy.conf;
    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;
        
        server_names_hash_bucket_size     256;
        client_body_buffer_size      128k;
        client_header_buffer_size    8k;
        client_max_body_size            50m;
        client_header_timeout        1m;
        client_body_timeout                1m;
        large_client_header_buffers 4 8k;
        
        
        send_timeout        3m;
    
    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  120;
        tcp_nodelay                    on;
    
    gzip  on;
    gzip_min_length        1k;
    gzip_buffers            4 16k;
    gzip_http_version    1.1;
    gzip_comp_level        2;
    gzip_types    text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

        upstream cctest1.com {
            server 127.0.0.1:8080 weight=5;
            server 127.0.0.1:9080 weight=5;
        }


    server {
        listen       80;
        server_name  ccserver1;

        #charset koi8-r;

        access_log  logs/host.access.log  main;

                index index.html index.htm index.jsp;
                root /usr/common/apache-tomcat-7.0.78_1/webapps/ROOT/;
                
                
                location ~* ^/arch1/.*\.(jpg|jpeg|gif|png|swf|ico)$ {
                    root /usr/common/apache-tomcat-7.0.78_1/webapps;
                }
                
                location ~* ^/arch1/.*\.(html|htm|js|css)$ {
                    root /usr/common/apache-tomcat-7.0.78_1/webapps;
                }
                
                location ~* .*\.(jpg|jpeg|gif|png|swf|ico)$ {
                    if (-f $request_filename) {
                        #expires   15d;
                        break;
                    }
                }
                
                location ~* .*\.(html|htm|js|css)$ {
                    if (-f $request_filename) {
                        #expires   1d;
                    }
                }
                
        location / {
                proxy_pass    http://cctest1.com;
        
        }

        #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 {
            internal;
            root errors/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}


mime.types文件
types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.ms-excel              xls;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              eot;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

ccproxy.conf文件

#!proxy.conf
proxy_redirect  off;
proxy_set_header  Host $host;
proxy_set_header    X-Real-IP $remote_addr; #获取真实ip
proxy_set_header  X-Forward-For $Proxy_add_x_forwarded_for;#获取代理者的真实IP
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_connect_timeout 90;
proxy_send_timeout        90;
proxy_read_timeout        90;
proxy_buffer_size            4k;
proxy_buffers                    4 64k;
proxy_busy_buffers_size     128k;
proxy_temp_file_write_size    64k;

猜你喜欢

转载自www.cnblogs.com/xiaoliangup/p/9175964.html