Nginx 設定檔總結

來源:互聯網
上載者:User
# 定義Nginx運行使用者user  root;# Nginx進程數,設定為auto代表nginx會自己匹配,一般為CPU核心數量worker_processes  auto;# 錯誤記錄檔路徑及層級error_log  logs/error.log notice;# pid檔案存放位置pid        logs/nginx.pid;# Nginx最大檔案開啟數worker_rlimit_nofile   40960;events {#參考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本核心中的高效能網路I/O模型,如果跑在FreeBSD上面,就用kqueue模型。    use   epoll; #單個進程最大串連數(最大串連數=串連數*進程數)       worker_connections  10240; #在Nginx接到一個新串連通知後調用accept()來接受盡量多的串連    multi_accept on; }http {# 隱藏nginx版本號碼    server_tokens off;   # 副檔名與檔案類型映射表    include       mime.types;# 預設檔案類型    default_type  application/octet-stream;# nginx 日誌格式log_format  main    '$remote_addr|$time_local|$request|''$status|$body_bytes_sent|$http_referer|''$http_user_agent|$http_x_forwarded_for|''$upstream_addr|$upstream_status|$request_time|$upstream_response_time';# 定義access日誌,並使用上面定義的formataccess_log  logs/access.log  main;# 要求標頭部緩衝大小    client_header_buffer_size    4k;# 請求緩衝大小    large_client_header_buffers  432k;#允許用戶端請求的最大單檔案位元組數      client_max_body_size 500m; #緩衝區代理緩衝使用者端請求的最大位元組數    client_body_buffer_size 1024k;#後端的Web伺服器可以通過X-Forwarded-For擷取使用者真實IP    proxy_headers_hash_max_size 51200;    proxy_headers_hash_bucket_size 6400;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    proxy_set_header request_uri $request_uri;    proxy_set_header Host $host;#nginx跟後端伺服器連線逾時時間(代理連線逾時)    proxy_connect_timeout 90;#後端伺服器資料回傳時間(代理髮送逾時)            proxy_send_timeout 90;#串連成功後,後端伺服器回應時間(代理接收逾時)     proxy_read_timeout 90;#設定Proxy 伺服器(nginx)儲存使用者頭資訊的緩衝區大小    proxy_buffer_size 128k;#proxy_buffers緩衝區,網頁平均在32k以下的設定    proxy_buffers 8128k;#高負荷下緩衝大小(proxy_buffers*2)    proxy_busy_buffers_size 256k;#高負荷下緩衝大小(proxy_buffers*2)    proxy_temp_file_write_size 256k;    proxy_temp_path  /usr/local/nginx/proxy_temp;    proxy_cache_path /usr/local/nginx/proxy_cache levels=1:2 keys_z>100m inactive=1d max_size=10g;#開啟高效檔案傳輸模式,sendfile指令指定nginx是否調用sendfile函數來輸出檔案,對於普通應用設為 on,如果用來進行下載等應用磁碟IO重負載應用,可設定為off,以平衡磁碟與網路I/O處理速度,降低系統的負載。注意:如果圖片顯示不正常把這個改成off。     sendfile        on;  #防止網路阻塞    tcp_nopush      on;  #防止網路阻塞    tcp_nodelay     on;  #長連線逾時時間,單位為秒    keepalive_timeout  30;#gzip模組設定    gzip on;#開啟gzip壓縮輸出    gzip_min_length 1k;#最小壓縮檔大小    gzip_buffers 416k;#壓縮緩衝區    gzip_comp_level 4;#壓縮等級    gzip_proxied any;        gzip_types image/jpeg image/png text/plain application/xml application/x-javascript text/javascript text/css;#壓縮類型,預設就已經包含text/html,所以下面就不用再寫了,寫上去也不會有問題,但是會有一個warn。    gzip_vary on;#限制請求數,除了白名單外的IP每秒最多處理8個請求    limit_req_zone  $binary_remote_addr    z>20m rate=1r/s;#限制串連數    limit_conn_zone $binary_remote_addr    z>20m;#限制串連數,請求數的白名單    geo $white_ip {            ranges;            default0;    #白名單ip-11.1.1.1-1.1.1.21;            1.1.1.1-1.1.1.21;            1.1.1.1-1.1.1.21;            1.1.1.1-1.1.1.21;    #白名單ip-21.1.1.1-1.1.1.21;            1.1.1.1-1.1.1.21;        }    limit_req_whitelist geo_var_name=white_ip geo_var_value=1;#----------------------------------    server {        listen  80;        server_name *.xxx.net xxx.net *.xxx.com xxx.com *.xxx.cn xxx.cn *.xxx.com *.xxx.com.cn xxx.com.cn;        rewrite ^(.*) http://www.xxx.com$1 permanent;    }    server{          listen 80default;          server_name  _;          return444;    }# 載入該目錄下的配置    include       /usr/local/nginx/conf/vhost/*.conf;# 錯誤碼(403、404、50x)頁面    error_page 403             http://file.xxx.com/assets/errorNew.html;    error_page 404             http://cdn1.xxx.com/assets/error.html;    error_page 500 502 503 504 http://cdn1.xxx.com/assets/error.html;}

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介紹了Nginx 設定檔總結,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.