nginx的設定檔最全版(使用最新穩定版NGINX1.8.0),nginxnginx1.8.0
# 使用的使用者和組
user nginx nginx;
# 指定工作繁衍的處理序數;一般幾核CPU就配置幾個。nginx進程數,建議設定為等於CPU總核心數。
worker_processes 1;
#全域錯誤記錄檔及PID檔案;全域錯誤記錄檔定義類型,[ debug | info | notice | warn | error | crit ]
error_log /var/log/nginx/error.log warn;
#進程檔案
pid /var/run/nginx.pid;
#一個nginx進程開啟的最多檔案描述符數目,理論值應該是最多開啟檔案數(系統的值ulimit -n)與nginx進程數相除,但是nginx分配請求並不均勻,所以建議與 ulimit -n的值保持一致。
#worker_rlimit_nofile 65535;
#工作模式與串連數上限
events {
#參考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型,
#是Linux 2.6以上版本核心中的高效能網路I/O模型,如果跑在FreeBSD上面,就用kqueue模型。
#具體內容查看 http://wiki.codemongers.com/事件模型
use epoll;
#單個進程最大串連數(最大串連數=串連數*進程數)connections 2000worker_connections 1024;
}
#設定http伺服器
http {
#副檔名與檔案類型映射表,設定mime類型,類型由mime.type檔案定義
include /etc/nginx/mime.types;
#預設檔案類型default_type application/octet-stream;#預設編碼#charset utf-8;#反向 Proxy配置,可以開啟proxy.conf看看#include /etc/nginx/proxy.conf;#fastcgi配置,可以開啟fastcgi.conf看看#include /etc/nginx/fastcgi.conf; #日誌的格式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 /var/log/nginx/access.log main;#sendfile 指令指定 nginx 是否調用 sendfile 函數(zero copy 方式)來輸出檔案,對於普通應用,#必須設為 on,如果用來進行下載等應用磁碟IO重負載應用,可設定為 off,以平衡磁碟與網路I/O處理速度,降低系統的uptime.sendfile on;#開啟目錄列表訪問,合適下載伺服器,預設關閉。#autoindex on;#防止網路阻塞#tcp_nopush on;#連線逾時時間,單位是秒keepalive_timeout 65;#防止網路阻塞tcp_nodelay on;#伺服器名字的hash表大小#server_names_hash_bucket_size 128;#上傳檔案大小限制#client_header_buffer_size 32k;#設定請求緩#large_client_header_buffers 4 64k;#設定請求緩衝#client_max_body_size 8m;#FastCGI相關參數是為了改善網站的效能:減少資源佔用,提高訪問速度。下面參數看字面意思都能理解。#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;#gzip模組設定#開啟gzip壓縮輸出#gzip on;#最小壓縮檔大小#gzip_min_length 1k;#壓縮緩衝區#gzip_buffers 4 16k;#壓縮版本(預設1.1,前端如果是squid2.5請使用1.0)#gzip_http_version 1.0;#壓縮等級#gzip_comp_level 2;#壓縮類型,預設就已經包含text/html,所以下面就不用再寫了,寫上去也不會有問題,但是會有一個warn。#gzip_types text/plain application/x-javascript text/css application/xml;#gzip_vary on;#開啟限制IP串連數的時候需要使用#limit_zone crawler $binary_remote_addr 10m;include /etc/nginx/conf.d/*.conf;#include /etc/nginx/sites-enabled/*;#設定負載平衡的伺服器列表#upstream ctrip_oa_tomcat {# #upstream的負載平衡,weight是權重,可以根據機器配置定義權重。weigth參數表示權值,權值越高被分配到的幾率越大。# server 127.0.0.1:8080 weight=1;# server 192.168.1.116:8081 weight=1;#}#設定負載平衡的伺服器列表,可以配置多個負載平衡的伺服器列表#upstream ctrip_oa_tomcat2 {# #upstream的負載平衡,weight是權重,可以根據機器配置定義權重。weigth參數表示權值,權值越高被分配到的幾率越大。 # server 127.0.0.1:8080 weight=1;# server 192.168.1.116:8081 weight=1;#}#虛擬機器主機的配置server { #監聽連接埠 listen 80; #網域名稱可以有多個,用空格隔開 server_name 192.168.1.116; #定義首頁 index index.html index.htm index.jsp; #檔案根目錄 root /home/oa/ctripoa-ui/usky-ctripoa-uui/public; #定義錯誤頁面 error_page 400 402 403 404 405 406 410 411 413 416 500 501 502 503 504 /error.html; error_page 505 /error.html; #日誌格式設定 #log_format access '$remote_addr - $remote_user [$time_local] "$request" ' #'$status $body_bytes_sent "$http_referer" ' #'"$http_user_agent" $http_x_forwarded_for'; #定義本虛擬機器主機的訪問日誌 #access_log /var/log/nginx/ctrip_oa_access.log access; #預設訪問地址
location / {
expires 2m;
add_header Cache-Control “public, must-revalidate, proxy-revalidate”;
add_header Cache-Control “public, must-revalidate, proxy-revalidate”;
}
#所有的rest請求都是以api開頭的
location ~ /sms/(api|images|files)/ {
proxy_pass http://localhost:8080;
proxy_next_upstream error timeout;
proxy_connect_timeout 8s;
proxy_intercept_errors on;
proxy_set_header X-Forwarded-Host httphost;proxysetheaderX−Forwarded−Serverhost;
proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
proxy_set_header X-Real-IPremote_addr;
proxy_set_header Host $http_host;
}
#預設請求
#對 “/” 啟用反向 Proxy
#location / {
#proxy_pass localhost;
#proxy_redirect off; #proxy_set_header X-Real-IP $remote_addr; #後端的Web伺服器可以通過X-Forwarded-For擷取使用者真實IP #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #以下是一些反向 Proxy的配置,可選。 #proxy_set_header Host $host; #允許用戶端請求的最大單檔案位元組數 #client_max_body_size 10m; #緩衝區代理緩衝使用者端請求的最大位元組數, #client_body_buffer_size 128; #nginx跟後端伺服器連線逾時時間(代理連線逾時) #proxy_connect_timeout 90; #後端伺服器資料回傳時間(代理髮送逾時) #proxy_send_timeout 90; #串連成功後,後端伺服器回應時間(代理接收逾時) #proxy_read_timeout 90; #設定Proxy 伺服器(nginx)儲存使用者頭資訊的緩衝區大小 #proxy_buffer_size 4k; #proxy_buffers緩衝區,網頁平均在32k以下的設定 #proxy_buffers 4 32k; #高負荷下緩衝大小(proxy_buffers*2) #proxy_busy_buffers_size 64k; #設定快取檔案夾大小,大於這個值,將從upstream伺服器傳 #proxy_temp_file_write_size 64k; #} #以下為靜態資源,nginx自己處理 #靜態檔案,nginx自己處理 #location ~ ^/(images|javascript|js|css|flash|media|static)/ { # root /home/oa/ctripoa-ui/usky-ctripoa-uui; # expires 30d; #到期30天,靜態檔案不怎麼更新,到期可以設大一點,如果頻繁更新,則可以設定得小一點。 #} #圖片緩衝時間設定 #location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ { # expires 30d; #} #JS和CSS緩衝時間設定 #location ~ .*.(js|css)?$ { # expires 30h; #} #所有jsp的頁面均交由tomcat或resin處理 #location ~ .(jsp|jspx|do)?$ { # proxy_set_header Host $host; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # proxy_pass http://127.0.0.1:8080; #} #所有靜態檔案由nginx直接讀取不經過tomcat或rest #location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { # expires 15d; #} #location ~ .*.(js|css)?$ { # expires 1h; #} #設定查看Nginx狀態的地址 #location /NginxStatus { #stub_status on; #access_log on; #auth_basic "NginxStatus"; #auth_basic_user_file conf/htpasswd; #htpasswd檔案的內容可以用apache提供的htpasswd工具來產生。 #}
}
}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。