nginx的一份参考配置文件

使用了nginx的编译安装后,或者只要安装的nginx中带有 zlib | pcre | ssl 三个库,按照如下的配置文件,就可用了。
查看nginx带有的模块,可用使用 nginx -V ,如:

nginx.png

以下配置供参考:

#user  nobody;
worker_processes auto;

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

#pid        logs/nginx.pid;
error_log   /usr/local/nginx/logs/nginx_error.log error;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;


events {
    use epoll;
    worker_connections 65535;
    multi_accept on; 
}


http {
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 64k;
    large_client_header_buffers 4 64k;
    request_pool_size 32k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 1000m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    fastcgi_buffers      8 4K;
    fastcgi_buffer_size  4K;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml text/xml application/xml+rss text/javascript;
    server_tokens off;
    access_log off; 
    reset_timedout_connection on;
    open_file_cache max=65535 inactive=20s; 
    open_file_cache_valid 30s; 
    open_file_cache_min_uses 2;     
    open_file_cache_errors on; 

    #wcm
    upstream wcm{
        server 10.11.4.12:8080;
        #ip_hash;
    }

#   把http访问重定向到https
#   server {
#       listen 80;
#       server_name 10.11.4.12;
#       rewrite ^(.*) https://$server_name$1 permanent;
#   }
    
    server {
        #http和https共存
        listen       80;
        listen  443 ssl;
        server_name  localhost;
        ssl_certificate /usr/local/nginx/conf/server.crt;
        ssl_certificate_key /usr/local/nginx/conf/server.key;

        #定义服务器的默认网站根目录位置
        root    html;
        index   index.shtml index.html index.htm; 
         
        #开启ssi    
        ssi on;  
        ssi_silent_errors on;  
        ssi_types text/shtml;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        
        #开启gzip压缩,如果没被压缩,注意查看下面的gzip_types是否包含了该类型
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_comp_level 2;
        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript;
        gzip_vary off;
        #IE上gzip表现不好,干脆禁用掉
        gzip_disable "MSIE [1-6]\.";

        #静态文件的过期时间设置
        location ~ ^/(images|pages|JavaScript|js|css|flash|media|static)/  {  
            expires 30d;
        }
  
        # 根路径 虚拟目录代理
        location / {  
            root  /home/trs/mediacube;
            proxy_set_header Host  $Host;
            proxy_set_header X-Forwarded-For  $remote_addr;
            client_max_body_size 30M;

            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|json)$ {
                expires 30d;
            }

            location ~ .*\.(html|htm)$ {
                expires -1;
            }
        }  
        
        # 虚拟目录代理
        location /mediacube{
                root  /home/trs;
                proxy_set_header Host  $Host;
                proxy_set_header X-Forwarded-For  $remote_addr;
                client_max_body_size 30M;

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|json)$ {
                        expires 30d;
                }

                location ~ .*\.(html|htm)$ {
                        expires -1;
                }
             }

        # 负载均衡的配置,对应上面的upstream
        location /wcm{
            proxy_pass http://wcm;
            # 把被tomcat改掉的https重定向回来
            proxy_redirect ~^http://([^:]+)(:\d+)?(.*)$  https://$1$3;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header   Cookie $http_cookie; 
            #client_max_body_size 300M;
        }

        # 反向代理配置
        location /mas{
            proxy_pass http://10.11.3.16/mas;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header   Cookie $http_cookie; 
            #client_max_body_size 300M;
        } 

        # 虚拟目录的别名配置
        location /map{
            alias  /home/trs/map_nc;

            proxy_set_header X-Forwarded-For  $remote_addr;
            client_max_body_size 30M;

            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|json)$ {
                expires 30d;
            }   

            location ~ .*\.(html|htm|json)$ {
                expires -1; 
            }   
        } 
    # 包含另外的配置文件,这是个相对位置
    include vhost/moreport.conf;
}

你可能感兴趣的:(nginx的一份参考配置文件)