<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] * * * * * nginx配置文件是一個純文本的文件,一般都是位于nginx的安裝目錄下,在我的文檔nginx的配置文件處于/app/nginx/conf/nginx.conf,默認的安裝路徑的配置文件在/usr/local/nginx/conf/nginx.conf。它的**配置文件都是以block的形式組織**的,每個block一般都是以括號“{}”來表示的。**主要包括全局,event,http,server等設置,event主要定義nginx的工作模式,http提供web功能,server用來設置虛擬主機,**server可以存在多個 Nginx配置文件結構: * * * * * ![](https://box.kancloud.cn/2016-08-12_57ad79e78a017.png) * * * * * ###1. 配置main模塊 下面說明main模塊中的幾個關鍵參數。 1.1 error_log: * * * * * 用于配置錯誤的日志,以及日志級別。可使用于main,http,server以及location上下文中; 語法格式: error_log file | stderr [debug | info |notice | warn | error | crit | alert | emerg ] 禁用錯誤日志: error_log /dev/null crit; * * * * * 1.2 timer_resolution: * * * * * 用于降低gettimeofday()系統調用的次數,默認情況下每次從kevent(),epoll,/dev/poll,select()或者poll()返回時都會執行此系統調用。 語法格式為: timer_resolution interval; example: timer_resolution 100ms; * * * * * 1.3 worker_cpu_affinity: * * * * * 通過sched_setaffinity()將worker綁定至cpu上,只能適用于main上下文。 語法格式 : worker_cpu_affinity cpumask ... example1:worker_process 4; worker_cpu_affinity 0001 0010 0100 1000; 上面是指4核cpu開啟4個進程 example2:worker_process 2; woker_cpu_affinity 01 10 01 10; 上面是指2核cpu開啟4個進程 * * * * * **上面的例子2可以理解為4個進程,第一個進程對應的cpu的01(即第一個cpu內核),第二個進程對應cpu的10(即的第二個cpu內核)... * * * * * 1.4 worker_processes: * * * * * worker進程是單線程進程。如果Nginx用于CPU密集型的場景中,如SSL或gzip,且主機上的CPU個數至少有2個,那么應該將此參數值設定為與CPU核心數相同;如果Nginx用于大量靜態文件訪問的場景中,且所有文件的總大小大于可用內存時,應該將此參數的值設定得足夠大以充分利用磁盤帶寬。 此參數與Events上下文中的work_connections變量一起決定了maxclient的值: maxclients = work_processes * work_connections * * * * * 1.5 worker_rlimit_nofile: * * * * * 設定worker進程所能夠打開的文件描述的最大數值。 語法格式:woker_rlimit_nofile number * * * * * ###2. 配置Event模塊 這個模塊是用來設定nginx的工作模式以及連接數上限的。 * * * * * 2.1 worker_connections: * * * * * 設定每個worker所能夠處理的最大連接數,他與來自main上下文的worker——processes一起決定了maxclients的值; max clients = worker_processes * worker_connections 而在反向代理場景中,其計算方法與上述公式不同,因為默認情況下瀏覽器將打開2個連接,而nginx會為每一個連接打開2個文件描述符; max clients = worker_processes * worker_connections/4 * * * * * 2.2 use * * * * * 在有著多余一個事件模型IO的應用場景中,可使用此設置nginx的工作模式,默認為./configure腳本所選定的最適合當年主機的版本。 語法格式: use [ select| poll| kqueuw | rtsig |/dev/poll] select/poll是標準模式,kqueue/epoll是高效模式。kqueue僅僅適合BSD系統。linux首選是epoll * * * * * 2.3 一個配置事例 ~~~ user nginx nginx; worker_processes 2; woker_set_afinity 01 10 01 10; error_log /app/nginx/log/error.log; pid /var/run/nginx/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 2048; } ~~~ ###3. HTTP服務的相關配置 * * * * * http上下文專用于配置用于http的各模塊,此類指令非常的多,每個模塊都有其專用指定,具體請參數nginx官方wiki關于模塊部分的說明。大體上來講,這些模塊所提供的配置指令還可以分為如下幾個類別。 客戶端類指令:如client_body_buffer_size、client_header_buffer_size、client_header_timeout和keepalive_timeout等; 文件IO類指令:如aio、directio、open_file_cache、open_file_cache_min_uses、open_file_cache_valid和sendfile等; hash類指令:用于定義Nginx為某特定的變量分配多大的內存空間,如types_hash_bucket_size、server_names_hash_bucket_size和variables_hash_bucket_size等; 套接字類指令:用于定義Nginx如何處理tcp套接字相關的功能,如tcp_nodelay(用于keepalive功能啟用時)和tcp_nopush(用于sendfile啟用時)等; * * * * * example: ~~~ http{ include /app/nginx/conf/mime.types; default application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" "$gzip_ratio"'; access_log log/access_http.log main; client_max_boby_size 20m; client_header_buffer_size 32k; large_client_header_buffers 4 32k; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_time 65; gzip on; client_header_timeout 10; client_boby_timeout 10; send_timeout 10; } ~~~ 基本的http的相關配置以上內容即可。 ###4. 虛擬主機的相關配置 4.1基本語法: ~~~ server { <directive> <parameters>; } ~~~ * * * * * ~~~ server{ listen 8080; #監聽端口 server_name www.smyking.com; access_log log/host。access.log main; index index.htm index.jsp; root /var/www/html/ charset utf-8; # error_page 404 @(404.html) # localtion @404.html { # root html; #} } ~~~ * * * * * 4.2 url匹配規則 urld地址匹配是nginx配置最為靈活的的部分,location支持正則表達式匹配,也支持條件判斷,用戶可以通過location指令實現nginx對動態靜態網頁的過濾處理。 * * * * * ~~~ location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${ root /var/www/smyking/; expires 30d; } ~~~ 將gif,jpg,jpeg,png,swf的靜態文件都交給nginx處理,expires是指靜態文件的過期時間是30天 * * * * * * * * * * ~~~ localtion ~ ^/(upload|html)/{ root /var/www/smyking; expires 30d; } ~~~ 將upload和html下的所有文件都交給nginx來處理。 * * * * * * * * * * ~~~ localtion ~ .*.jsp${ index index.jsp; proxy http://localhost:9080; } ~~~ 將所有的jsp為后綴的文件都交給本機的9080端口處理 * * * * *
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看