Nginx設定檔詳細說明

來源:互聯網
上載者:User

Nginx設定檔詳細說明 在此記錄下Nginx伺服器nginx.conf的設定檔說明, 部分注釋收集與網路. #運行使用者user www-data;    #啟動進程,通常設定成和cpu的數量相等worker_processes  1; #全域錯誤記錄檔及PID檔案error_log  /var/log/nginx/error.log;pid        /var/run/nginx.pid; #工作模式及串連數上限events {    use   epoll;             #epoll是多工IO(I/O Multiplexing)中的一種方式,但是僅用於linux2.6以上核心,可以大大提高nginx的效能    worker_connections  1024;#單個後台worker process進程的最大並發連結數    # multi_accept on; } #設定http伺服器,利用它的反向 Proxy功能提供負載平衡支援http {     #設定mime類型,類型由mime.type檔案定義    include       /etc/nginx/mime.types;    default_type  application/octet-stream;    #設定日誌格式    access_log    /var/log/nginx/access.log;     #sendfile 指令指定 nginx 是否調用 sendfile 函數(zero copy 方式)來輸出檔案,對於普通應用,    #必須設為 on,如果用來進行下載等應用磁碟IO重負載應用,可設定為 off,以平衡磁碟與網路I/O處理速度,降低系統的uptime.    sendfile        on;    #tcp_nopush     on;     #連線逾時時間    #keepalive_timeout  0;    keepalive_timeout  65;    tcp_nodelay        on;        #開啟gzip壓縮    gzip  on;    gzip_disable "MSIE [1-6]\.(?!.*SV1)";     #設定請求緩衝    client_header_buffer_size    1k;    large_client_header_buffers  4 4k;     include /etc/nginx/conf.d/*.conf;    include /etc/nginx/sites-enabled/*;     #設定負載平衡的伺服器列表     upstream mysvr {    #weigth參數表示權值,權值越高被分配到的幾率越大    #本機上的Squid開啟3128連接埠    server 192.168.8.1:3128 weight=5;    server 192.168.8.2:80  weight=1;    server 192.168.8.3:80  weight=6;    }     server {    #偵聽80連接埠        listen       80;        #定義使用www.xx.com訪問        server_name  www.xx.com;         #設定本虛擬機器主機的訪問日誌        access_log  logs/www.xx.com.access.log  main;     #預設請求    location / {          root   /root;      #定義伺服器的預設網站根目錄位置          index index.php index.html index.htm;   #定義首頁索引檔案的名稱           fastcgi_pass  www.xx.com;         fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;           include /etc/nginx/fastcgi_params;        }     # 定義錯誤提示頁面    error_page   500 502 503 504 /50x.html;          location = /50x.html {        root   /root;    }     #靜態檔案,nginx自己處理    location ~ ^/(images|javascript|js|css|flash|media|static)/ {        root /var/www/virtual/htdocs;        #到期30天,靜態檔案不怎麼更新,到期可以設大一點,如果頻繁更新,則可以設定得小一點。        expires 30d;    }    #PHP 指令碼請求全部轉寄到 FastCGI處理. 使用FastCGI預設配置.    location ~ \.php$ {        root /root;        fastcgi_pass 127.0.0.1:9000;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;        include fastcgi_params;    }    #設定查看Nginx狀態的地址    location /NginxStatus {        stub_status            on;        access_log              on;        auth_basic              "NginxStatus";        auth_basic_user_file  conf/htpasswd;    }    #禁止訪問 .htxxx 檔案    location ~ /\.ht {        deny all;    }          }} 以上是一些基本的配置,使用Nginx最大的好處就是負載平衡 如果要使用負載平衡的話,可以修改配置http節點如下: #設定http伺服器,利用它的反向 Proxy功能提供負載平衡支援http {     #設定mime類型,類型由mime.type檔案定義    include       /etc/nginx/mime.types;    default_type  application/octet-stream;    #設定日誌格式    access_log    /var/log/nginx/access.log;     #省略上文有的一些配置節點     #。。。。。。。。。。     #設定負載平衡的伺服器列表     upstream mysvr {    #weigth參數表示權值,權值越高被分配到的幾率越大    server 192.168.8.1x:3128 weight=5;#本機上的Squid開啟3128連接埠    server 192.168.8.2x:80  weight=1;    server 192.168.8.3x:80  weight=6;    }    upstream mysvr2 {    #weigth參數表示權值,權值越高被分配到的幾率越大     server 192.168.8.x:80  weight=1;    server 192.168.8.x:80  weight=6;    }    #第一個虛擬伺服器   server {    #偵聽192.168.8.x的80連接埠        listen       80;        server_name  192.168.8.x;       #對aspx尾碼的進行負載平衡請求    location ~ .*\.aspx$ {          root   /root;      #定義伺服器的預設網站根目錄位置          index index.php index.html index.htm;   #定義首頁索引檔案的名稱           proxy_pass  http://mysvr ;#請求轉向mysvr 定義的伺服器列表           #以下是一些反向 Proxy的配置可刪除.           proxy_redirect off;           #後端的Web伺服器可以通過X-Forwarded-For擷取使用者真實IP          proxy_set_header Host $host;          proxy_set_header X-Real-IP $remote_addr;          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;          client_max_body_size 10m;    #允許用戶端請求的最大單檔案位元組數          client_body_buffer_size 128k;  #緩衝區代理緩衝使用者端請求的最大位元組數,          proxy_connect_timeout 90;  #nginx跟後端伺服器連線逾時時間(代理連線逾時)          proxy_send_timeout 90;        #後端伺服器資料回傳時間(代理髮送逾時)          proxy_read_timeout 90;         #串連成功後,後端伺服器回應時間(代理接收逾時)          proxy_buffer_size 4k;             #設定Proxy 伺服器(nginx)儲存使用者頭資訊的緩衝區大小          proxy_buffers 4 32k;               #proxy_buffers緩衝區,網頁平均在32k以下的話,這樣設定          proxy_busy_buffers_size 64k;    #高負荷下緩衝大小(proxy_buffers*2)          proxy_temp_file_write_size 64k;  #設定快取檔案夾大小,大於這個值,將從upstream伺服器傳        }      }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.