##界說nginx運行的用戶各用戶組
user nginx nginx;
##nginx歷程數(shù),發(fā)起配置與cpu焦點數(shù)一致
worker_processes 1;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
##全局錯誤日志界說范例[ debug | info | notice | warn | error | crit ]
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
##一個nginx歷程打開的最多文件描寫符數(shù)目,理論值應(yīng)該是最多打開文件數(shù)(系統(tǒng)的值ulimit -n)與nginx歷程數(shù)相除,可是nginx分派請求并不勻稱,所以發(fā)起與ulimit -n的值保持一致。
worker_rlimit_nofile 65535;
##歷程文件
#pid logs/nginx.pid;
##事情模式與毗連數(shù)上限
events {
##參考事件模子,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模子是Linux 2.6以上版本內(nèi)核中的高機能網(wǎng)絡(luò)I/O模子,假如跑在FreeBSD上面,就用kqueue模子。
use epoll;
##單個歷程的最大毗連數(shù)
worker_connections 65535;
}
##配置http處事器
http {
##引入外置設(shè)置文件
include /etc/nginx/conf.d/*.conf;
##文件擴展名與文件范例映射表
include mime.types;
##默認(rèn)文件范例
default_type application/octet-stream;
##默認(rèn)編碼
#charset utf-8;
##處事器名字的hash表巨細
#server_name_hash_bucket_size 128;
##上傳文件巨細限制 發(fā)起打開
client_header_buffer_size 32K;
##設(shè)定請求緩存 發(fā)起打開
large_client_header_buffers 4 64K;
##最大緩存
client_max_body_size 20M;
client_header_timeout 20;
##日志名目設(shè)定
#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函數(shù)來輸出文件,對付普通應(yīng)用設(shè)為 on,假如用來舉辦下載等應(yīng)用磁盤IO重負載應(yīng)用,可配置為off,以均衡磁盤與網(wǎng)絡(luò)I/O處理懲罰速度,低落系統(tǒng)的負載。留意:如 果圖片顯示不正常把這個改成off。
sendfile on;
##開啟目次列表會見,符合下載處事器,默認(rèn)封鎖
#autoindex on;
##防備網(wǎng)絡(luò)阻塞 發(fā)起打開
tcp_nopush on;
##防備網(wǎng)絡(luò)阻塞 發(fā)起打開
tcp_nodelay on;
##長鏈接超時時間,單元是秒,為0,無超時
keepalive_timeout 65;
##gzip模塊配置
##開啟gzip壓縮輸出 發(fā)起打開
gzip on;
##最小壓縮文件巨細 發(fā)起打開
gzip_min_length 1k;
##壓縮緩沖區(qū) 發(fā)起打開
gzip_buffers 4 16k;
##壓縮版本(默認(rèn)1.1,前端假如squid2.5請利用1.0) 發(fā)起打開
gzip_http_version 1.0;
##壓縮品級
gzip_comp_level 2; 發(fā)起打開
##壓縮范例,默認(rèn)就已經(jīng)包括了textxml,默認(rèn)不消寫,寫上去也沒有問題,會有一個warn 發(fā)起打開
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
##開啟毗連限制ip毗連數(shù)利用
#limit_zone crawler $binary_remote_addr 10m;
##反向署理緩存Proxy Cache設(shè)置
proxy_temp_path /opt/cache/nginx/temp;
proxy_cache_path /opt/cache/nginx/cache levels=1:2 keys_zone=infcache:600m inactive=1d max_size=2g;
proxy_cache_path /opt/cache/nginx/proxy_cache_image levels=1:2 keys_zone=cache_image:3000m inactive=1d max_size=10g;
proxy_connect_timeout 30;
proxy_read_timeout 60;
proxy_send_timeout 20;
proxy_buffer_size 96k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
#proxy_cache_path設(shè)置
#keys_zone=infcache:600m 暗示這個zone名稱為infcache,,分派的內(nèi)存巨細為600MB
#/opt/cache/nginx/cache 暗示cache這個zone的文件要存放的目次
#levels=1:2 暗示緩存目次的第一級目次是1個字符,第二級目次是2個字符,即/data/ngx_cache/cache1/a/1b這種形式
#inactive=1d 暗示這個zone中的緩存文件假如在1天內(nèi)都沒有被會見,那么文件會被cache manager歷程刪除去
#max_size=10g 暗示這個zone的硬盤容量為10GB
##FastCGI相關(guān)參數(shù)是為了改進網(wǎng)站的機能:淘汰資源占用,提高會見速度。
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
##負載平衡,weight權(quán)重,權(quán)值越高被分派到的幾率越大
upstream myserver{
server 192.168.1.10:8080 weight=3;
server 192.168.1.11:8080 weight=4;
server 192.168.1.12:8080 weight=1;
}
##虛擬主機設(shè)置
server {
##監(jiān)聽端口
listen 80;
##域名可以有多個,用空格離隔
server_name localhost;
#charset koi8-r;
##界說本虛擬主機的會見日志
#access_log logs/host.access.log main;