Nginx配置檔案解析

weixin_34321977發表於2016-04-06

Nginx配置檔案解析

 (2015-11-25 10:45:22)
標籤: 

it

分類: WebServer
一. 配置檔案結構
 
Nginx配置檔案解析


二. 全域性塊詳解
 
#定義nginx執行的使用者和使用者組
user www www;
 
#定義nginx程式數(建議設定為CPU數)
worker_processes 8;
 
#全域性錯誤日誌定義型別(錯誤日誌型別:[debug|info|notice|warn|error|crit],從左到右錯誤資訊越來越少;此指令可以在全域性、http、server、location塊中配置)
error_log /var/log/nginx/error.log info;
 
#定義程式檔案
pid /var/run/nginx.pid; 
 
 
三. events塊詳解
#定義工作模式
use epoll
 
#連線數上限(單個程式的最大連線數,web伺服器的最大訪問使用者數 max clients = worker_processes * worker_connections)
worker_connections 1024
 
#網路連線序列化(為了避免喚醒太多的程式數,會影響系統效能)
accept_mutex  on
 
#工作程式是否允許同時接收多個網路連線
multi_accept  on
 
 
四. http塊詳解
 
#設定mime型別(MIME-Type型別由mime.type檔案定義)
include /etc/nginx/mime.types;
default_type application/octet-stream;
 
#預設編碼
charset utf-8;
 
#定義伺服器日誌(此處的日誌與常規的不同,它記錄的是nginx伺服器提供服務過程中應答前端請求的日誌)
access_log /var/log/nginx/access.log combined;
log_format combined  '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
 
#連線超時時間(單位:秒,可在http、server、location中配置)
keepalive_timeout 120;
reset_timeout_connection on;
 
#單連線請求數上限 (限制使用者通過某一連線項伺服器傳送請求的次數,可在http、server、location中配置)
keepalive_requests 100;
 
#是否允許sendfile方式傳輸檔案(可在http、server、location中配置)
sendfile on;
sendfile_max_chunk 128k   (#如果設定為0,則無限制)
 
#
tcp_nopush on;
 
 
#開啟gzip壓縮

gzip  on;

gzip_disable "MSIE [1-6]\.(?!.*SV1)";

gzip _min_length  1000;

gzip_buffers  168k

 

#設定負載均衡伺服器列表

upstream mysvr {

     server 192.168.1:80 weight=5;

     server 192.168.1:80 weight=2;

     server 192.168.1:80 weight=8;

}

 

 #shorten the timeout period, original one is 300

        fastcgi_connect_timeout 30;

        fastcgi_send_timeout 300;

        fastcgi_read_timeout 300;

        fastcgi_buffer_size 128k;

        fastcgi_buffers 8 128k;

        fastcgi_busy_buffers_size 256k;

        fastcgi_temp_file_write_size 256k;

        fastcgi_intercept_errors on;

        fastcgi_hide_header Pragma;

        # fastcgi cache

        fastcgi_cache_path temp/fastcgi_cache levels=1:2 keys_zone=cache_voice:128m inactive=30m max_size=4G;

 
五. server塊詳解
 
#監聽埠
listen 80;
 
#服務域名
server_name www.xxx.com;
 
#虛擬主機的訪問日誌
access_log /var/log/nginx/www.xxx.com_access.log main;
 

#如果指定http錯誤狀態碼,則返回客戶端指定的url地址

error_page 500 502 503 504 /50x.html;

location = 50x.html {

    root /home/xiaoju/webroot;

}

 

六. location塊詳解
#定義網站根目錄
root /home/xiaoju/webr

相關文章