Windows下Nginx+Tomcat整合的安裝與配置
阿新 • • 發佈:2019-01-04
#user nobody;
#工作程序:數目。根據硬體調整,通常等於CPU數量或者2倍於CPU。
worker_processes 1;
#錯誤日誌:存放路徑。
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid(程序識別符號):存放路徑。
#pid logs/nginx.pid;
#指定程序可以開啟的最大描述符:數目。
#這個指令是指當一個nginx程序開啟的最多檔案描述符數目,理論值應該是最多開啟檔案數(ulimit -n)與nginx程序數相除,但是nginx分配請求並不是#那麼均勻,所以最好與ulimit -n 的值保持一致。
#現在在linux 2.6核心下開啟檔案開啟數為65535,worker_rlimit_nofile就相應應該填寫65535。
#這是因為nginx排程時分配請求到程序並不是那麼的均衡,所以假如填寫10240,總併發量達到3-4萬時就有程序可能超過10240了,這時會返回502錯誤。
#worker_rlimit_nofile 204800;
events {
#使用epoll的I/O 模型。linux建議epoll,FreeBSD建議採用kqueue,window下不指定。
#補充說明:
#與apache相類,nginx針對不同的作業系統,有不同的事件模型
#A)標準事件模型
#Select、poll屬於標準事件模型,如果當前系統不存在更有效的方法,nginx會選擇select或poll
#B)高效事件模型
#Kqueue:使用於FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X.使用雙處理器的MacOS X系統使用kqueue可能會造成核心崩潰。
#Epoll:使用於Linux核心2.6版本及以後的系統。
#/dev/poll:使用於Solaris 7 11/99+,HP/UX 11.22+ (eventport),IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。
#Eventport:使用於Solaris 10。 為了防止出現核心崩潰的問題, 有必要安裝安全補丁。
#use epoll;
#沒個工作程序的最大連線數量。根據硬體調整,和前面工作程序配合起來用,儘量大,但是別把cpu跑到100%就行。每個程序允許的最多連線數,理論上每#臺nginx伺服器的最大連線數為。worker_processes*worker_connections
worker_connections 1024;
keepalive_timeout 60;
#keepalive超時時間。
client_header_buffer_size 4k;
#客戶端請求頭部的緩衝區大小。這個可以根據你的系統分頁大小來設定,一般一個請求頭的大小不會超過1k,不過由於一般系統分頁都要大於1k,所以這#裡設定為分頁大小。
#分頁大小可以用命令getconf PAGESIZE 取得。
#4096
#但也有client_header_buffer_size超過4k的情況,但是client_header_buffer_size該值必須設定為“系統分頁大小”的整倍數。
open_file_cache max=65535 inactive=60s;
#這個將為開啟檔案指定快取,預設是沒有啟用的,max指定快取數量,建議和開啟檔案數一致,inactive是指經過多長時間檔案沒被請求後刪除快取。
open_file_cache_valid 80s;
#這個是指多長時間檢查一次快取的有效資訊。
open_file_cache_min_uses 1;
#open_file_cache指令中的inactive引數時間內檔案的最少使用次數,如果超過這個數字,檔案描述符一直是在快取中開啟的,如上例,如果有一個檔案在#inactive時間內一次沒被使用,它將被移除。
}
http {
#設定mime型別,型別由mime.type檔案定義
include mime.types;
default_type application/octet-stream;
#日誌格式設定。
#通常web伺服器放在反向代理的後面,這樣就不能獲取到客戶的IP地址了,通過$remote_add拿到的IP地址是反向代理伺服器的iP地址。反向代理伺服器在#轉發請求的http頭資訊中,可以增加x_forwarded_for資訊,用以記錄原有客戶端的IP地址和原來客戶端的請求的伺服器地址。
#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 on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#nginx的upstream目前支援4種方式的分配
#1.輪詢(預設) 2.weight 3.ip_hash 每個請求按訪問ip的hash結果分配,這樣每個訪客固定訪問一個後端伺服器,可以解決#session的問題。
upstream localhost_server1 {
#ip_hash
server 127.0.0.1:8090 weight=3;
server 127.0.0.1:8070 weight=2;
}
server {
listen 8010;
#配置訪問域名
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#每個裝置的狀態設定為:
#1.down表示單前的server暫時不參與負載
#2.weight為weight越大,負載的權重就越大。
#3.max_fails:允許請求失敗的次數預設為1.當超過最大次數時,返回proxy_next_upstream模組定義的錯誤
#4.fail_timeout:max_fails次失敗後,暫停的時間。
#5.backup: 其它所有的非backup機器down或者忙的時候,請求backup機器。所以這臺機器壓力會最輕。
#nginx支援同時設定多組的負載均衡,用來給不用的server來使用。
#client_body_in_file_only設定為On 可以講client post過來的資料記錄到檔案中用來做debug
#client_body_temp_path設定記錄檔案的目錄 可以設定最多3層目錄
#location對URL進行匹配.可以進行重定向或者進行新的代理 負載均衡
proxy_pass http://localhost_server1;
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}