nginx簡單配置

user  www www;
worker_processes  2;

error_log  logs/error.log;
pid        logs/nginx.pid;

worker_rlimit_nofile 1024;

events {
    use epoll;
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    charset  utf-8;
    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;


  

    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    tcp_nodelay on;

  server_names_hash_bucket_size 128; #保存服務器名字的hash表
  client_header_buffer_size 4k; #客戶端請求頭部的緩衝區大小
  large_client_header_buffers 4 32k; #如果header過大,它會使用large_client_header_buffers來讀取
  client_max_body_size 300m;     #允許客戶端請求的最大單文件字節數
  client_body_buffer_size  512k; #緩衝區代理緩衝用戶端請求的最大字節數,
  proxy_connect_timeout    5; #nginx跟後端服務器連接超時時間(代理連接超時)
  proxy_read_timeout       60; #連接成功後,後端服務器響應時間(代理接收超時)
  proxy_send_timeout       5; #後端服務器數據回傳時間(代理髮送超時)
  proxy_buffer_size        16k;   #設置代理服務器(nginx)保存用戶頭信息的緩衝區大小
  proxy_buffers            4 64k; #proxy_buffers緩衝區,網頁平均在32k以下的話,這樣設置
  proxy_busy_buffers_size 128k; #高負荷下緩衝大小(proxy_buffers*2)
  proxy_temp_file_write_size 128k; #設定緩存文件夾大小,大於這個值,將從upstream服務器傳

        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;

  proxy_temp_path   /usr/local/nginx/proxy_temp_dir;#proxy_temp_path和proxy_cache_path指定的路徑必須在同一分區
  proxy_cache_path  /usr/local/nginx/proxy_cache_dir  levels=1:2   keys_zone=cache_one:200m inactive=1d max_size=30g;
 #設置內存緩存空間大小爲200MB,1天沒有被訪問的內容自動清除,硬盤緩存空間大小爲30GB
upstream local_pool {
      server 192.168.2.139:8080 weight=1 max_fails=2 fail_timeout=30s;
      server 192.168.2.128:8080 weight=1 max_fails=2 fail_timeout=30s;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
         root   html;          
index  index.html index.html;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid  200 304 12h;
proxy_cache_key $host$uri$is_args$args;
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
         proxy_pass http://local_pool;
         expires      1d;
           
        }

location ~ .*\.(php|jsp|cgi)?$
    {
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
         proxy_pass http://local_pool;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章