目錄
Nginx配置
基本配置參數說明
nginx文檔
介紹
如何
發展
子產品參考
Nginx配置
基本配置與參數說明
原文位址:http://www.nginx.cn/76.html
深入了解Nginx就是弄清楚參數配置的具體含義,進而可以改造結合自己的需求配置相應的Nginx服務。
#運作使用者
user nobody;
#啟動程序,通常設定成和cpu的數量相等
worker_processes 1;
#全局錯誤日志及PID檔案
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#工作模式及連接配接數上限
events {
#epoll是多路複用IO(I/O Multiplexing)中的一種方式,
#僅用于linux2.6以上核心,可以大大提高nginx的性能
use epoll;
#單個背景worker process程序的最大并發連結數
worker_connections 1024;
# 并發總數是 worker_processes 和 worker_connections 的乘積
# 即 max_clients = worker_processes * worker_connections
# 在設定了反向代理的情況下,max_clients = worker_processes * worker_connections / 4 為什麼
# 為什麼上面反向代理要除以4,應該說是一個經驗值
# 根據以上條件,正常情況下的Nginx Server可以應付的最大連接配接數為:4 * 8000 = 32000
# worker_connections 值的設定跟實體記憶體大小有關
# 因為并發受IO限制,max_clients的值須小于系統可以打開的最大檔案數
# 而系統可以打開的最大檔案數和記憶體大小成正比,一般1GB記憶體的機器上可以打開的檔案數大約是10萬左右
# 我們來看看360M記憶體的VPS可以打開的檔案句柄數是多少:
# $ cat /proc/sys/fs/file-max
# 輸出 34336
# 32000 < 34336,即并發連接配接總數小于系統可以打開的檔案句柄總數,這樣就在作業系統可以承受的範圍之内
# 是以,worker_connections 的值需根據 worker_processes 程序數目和系統可以打開的最大檔案總數進行适當地進行設定
# 使得并發總數小于作業系統可以打開的最大檔案數目
# 其實質也就是根據主機的實體CPU和記憶體進行配置
# 當然,理論上的并發總數可能會和實際有所偏差,因為主機還有其他的工作程序需要消耗系統資源。
# ulimit -SHn 65535
}
http {
#設定mime類型,類型由mime.type檔案定義
include mime.types;
default_type application/octet-stream;
#設定日志格式
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 指令指定 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].";
#設定請求緩沖
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
#設定虛拟主機配置
server {
#偵聽80端口
listen 80;
#定義使用 www.nginx.cn通路
server_name www.nginx.cn;
#定義伺服器的預設網站根目錄位置
root html;
#設定本虛拟主機的通路日志
access_log logs/nginx.access.log main;
#預設請求
location / {
#定義首頁索引檔案的名稱
index index.php index.html index.htm;
}
# 定義錯誤提示頁面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
#靜态檔案,nginx自己處理
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
#過期30天,靜态檔案不怎麼更新,過期可以設大一點,
#如果頻繁更新,則可以設定得小一點。
expires 30d;
}
#PHP 腳本請求全部轉發到 FastCGI處理. 使用FastCGI預設配置.
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#禁止通路 .htxxx 檔案
location ~ /.ht {
deny all;
}
}
}
nginx文檔
介紹
- 安裝nginx
- 從Sources建構nginx
- 初學者指南
- 管理者指南
- 控制nginx
- 連接配接處理方法
- 設定哈希值
- 調試日志
- 登入到syslog
- 配置檔案測量機關
- 指令行參數
- 适用于Windows的nginx
- nginx如何處理請求
- 伺服器名稱
- 使用nginx作為HTTP負載均衡器
- 配置HTTPS伺服器
- nginx如何處理TCP / UDP會話
- 使用njs編寫腳本
- “開源應用程式體系結構”中的“nginx”一章
如何
- 使用Visual C在Win32平台上建構nginx
- 在Amazon EC2上設定NGINX Plus環境
- 使用DTrace pid提供程式調試nginx
- 轉換重寫規則
- WebSocket代理
發展
- 貢獻變化
- 開發指南
子產品參考
- 按字母順序排列的指令索引
- 按字母順序排列的變量索引
- 核心功能
- ngx_http_core_module
- ngx_http_access_module
- ngx_http_addition_module
- ngx_http_api_module
- ngx_http_auth_basic_module
- ngx_http_auth_jwt_module
- ngx_http_auth_request_module
- ngx_http_autoindex_module
- ngx_http_browser_module
- ngx_http_charset_module
- ngx_http_dav_module
- ngx_http_empty_gif_module
- ngx_http_f4f_module
- ngx_http_fastcgi_module
- ngx_http_flv_module
- ngx_http_geo_module
- ngx_http_geoip_module
- ngx_http_grpc_module
- ngx_http_gunzip_module
- ngx_http_gzip_module
- ngx_http_gzip_static_module
- ngx_http_headers_module
- ngx_http_hls_module
- ngx_http_image_filter_module
- ngx_http_index_module
- ngx_http_js_module
- ngx_http_keyval_module
- ngx_http_limit_conn_module
- ngx_http_limit_req_module
- ngx_http_log_module
- ngx_http_map_module
- ngx_http_memcached_module
- ngx_http_mirror_module
- ngx_http_mp4_module
- ngx_http_perl_module
- ngx_http_proxy_module
- ngx_http_random_index_module
- ngx_http_realip_module
- ngx_http_referer_module
- ngx_http_rewrite_module
- ngx_http_scgi_module
- ngx_http_secure_link_module
- ngx_http_session_log_module
- ngx_http_slice_module
- ngx_http_spdy_module
- ngx_http_split_clients_module
- ngx_http_ssi_module
- ngx_http_ssl_module
- ngx_http_status_module
- ngx_http_stub_status_module
- ngx_http_sub_module
- ngx_http_upstream_module
- ngx_http_upstream_conf_module
- ngx_http_upstream_hc_module
- ngx_http_userid_module
- ngx_http_uwsgi_module
- ngx_http_v2_module
- ngx_http_xslt_module
- ngx_mail_core_module
- ngx_mail_auth_http_module
- ngx_mail_proxy_module
- ngx_mail_ssl_module
- ngx_mail_imap_module
- ngx_mail_pop3_module
- ngx_mail_smtp_module
- ngx_stream_core_module
- ngx_stream_access_module
- ngx_stream_geo_module
- ngx_stream_geoip_module
- ngx_stream_js_module
- ngx_stream_keyval_module
- ngx_stream_limit_conn_module
- ngx_stream_log_module
- ngx_stream_map_module
- ngx_stream_proxy_module
- ngx_stream_realip_module
- ngx_stream_return_module
- ngx_stream_split_clients_module
- ngx_stream_ssl_module
- ngx_stream_ssl_preread_module
- ngx_stream_upstream_module
- ngx_stream_upstream_hc_module
- ngx_stream_zone_sync_module
- ngx_google_perftools_module