nginx配置實例

user nobody nobody;  //以普通身份運行nginxworker_processes  4;  //打開的進程數worker_rlimit_nofile  51200;  //所可以同時打開的文件數error_log  logs/error.log notice;  //錯誤日誌文件pid  /var/run/nginx.pid;  //pid文件event {  use epoll;  //使用epoll事件驅動  worker_connections 51200;  //每個進程所可以承受的鏈接數}http {  server_tokens  off;  //關閉信息詳細顯示,防止信息泄露  include  mime.types;  proxy_redirect   off;  //是否proxy作重定向  proxy_set_header  Host  $host;  //若是有虛擬主機,後端也能轉發  proxy_set_header  X-Real-IP $remote_addr;  //將真正請求的客戶端IP發日後端  proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;  //日誌中記錄轉發的每一級代理服務器      client_max_body_size  20m;  //所可以接受的客戶端最大的請求主體部分的大小  client_body_buffer_size  256k;  //內存中緩存  proxy_connect_timeout  90;  //向後端服務器發起鏈接請求的超時時間  proxy_send_timeout  90;  //向後端服務器發送請求報文的超時時間   proxy_read_timeout  90;  //讀取後端服務器響應報文的超時時間  proxy_buffer_size  128k;  //代理服務器的buffer大小  proxy_buffers  4 64k;  //有多少個buffer,表示4段緩存空間,每段64k  proxy_busy_buffers_size  128k;    proxy_temp_file_write_size  128k;    default_type  application/octet-stream;  charset  utf-8;  client_body_temp_path  /var/tmp/client_body_temp 1 2;  proxy_temp_path  /var/temp/proxy_temp  1 2;  fastcgi_temp_path  /var/tmp/fastcgi_temp  1 2;  uwsgi_temp_path  /var/tmp/uwsgi_temp 1 2;  scgi_temp_path  /var/tmp/scgi_temp 1 2;  ignore_invalid_headers  on;  //忽略不合法的不理解的首部信息  server_names_hash_max_size  256;  //將每一個server的名字放到內存中進行hash,用戶請求的時候根據內存中hash的值進行比較  server_names_hash_bucket_size  64;  client_header_buffer_size  8k;  //客戶端請求首部用多大內存緩存下來進行分析  large_client_header_buffers   4 32k;    connection_pool_sie  256;  request_pool_size  64k;  output_buffers  2  128k;  postpone_output  1460;    client_header_timeout  1m;  client_body_timeout  3m;  send_timeout  3m;    log_format main '$server_addr $remote_addr [$time_local] $msec+$connection'  //服務器端地址 客戶端地址 日誌本地時間 毫秒級的解析度獲取的當前時間加上鍊接創建所通過的時間            '"$request" $status $connection $request_time $body_bytes_sent "$http_referer"'  //用戶請求的url 響應碼             '"$http_user_agent" "$http_x_forwarded_for"';    open_log_file_cache  max=1000 inactive=20s min_users=1 valid=1m;  //打開日誌文件緩存  access_log  logs/access.log  main;  log_not_found  on;  sendfile  on;  tcp_nodelay  on;  tcp_nopush  off;    reset_timedout_connection  on;  keepalive_timeout  10  5;  keepalive_requests  100;  gzip  on;  gzip_http_version  1.1;  gzip_vary  on;  gzip_proxied  any;  gzip_comp_level  6;  gzip_buffers  16  8k;  gzip_proxied expired no-cache no-store private auth  no_last_modified no_etag;  gzip_types  text/plain application/x-javascript text/css application/xml application/json;  gzip_disable  "MISE[1-6]\.(?!.*SV1)";  upstream tomcat8080 {    ip_hash;  //session保持    server  172.16.100.103:8080 weight=1 max_fails=2;    server   172.16.100.104:8080 weight=1 max_fails=2;    server    172.16.100.105:8080 weight=1 max_fails=2;  }  server{    listen 80;    server_name www.magedu.com;    #config_apps_begin    root  /data/webapps/htdocs;    access_log  /var/logs/webapp.access.log  main;    error_log  /var/logs/webapp.error.log  notice;  }  location  / {    location ~* ^.*/favicon.ico$ {      root /data/webapps;      expires  180d;      break;    }    if(!-f $request_filename){      proxy_pass  http://tomcat8080;      break;    }  }    error_page  500 502 503 504 /50x.html;    location=/50x.html {      root  html;    }}  server{  listen 8080;  server_name nginx_status;  location / {    access_log  off;    deny  all;    return 503;  }  location /status {    stub_status  on;    access_log  off;    allow  127.0.0.1;    allow  172.16.100.71;    deny  all;  }  }}
相關文章
相關標籤/搜索