#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
#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;
# 啟用內(nèi)核復(fù)制模式,應(yīng)該保持開(kāi)啟到達(dá)最快IO效率
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
# HTTP1.1支持耐久毗連alive
# 低落每個(gè)毗連的alive時(shí)間可在必然水平上提高可響應(yīng)毗連數(shù)量,所以一般可適當(dāng)?shù)吐浯酥?br />
keepalive_timeout 65;
# 啟動(dòng)內(nèi)容壓縮,,有效低就逮絡(luò)流量
gzip on;
# 過(guò)短的內(nèi)容壓縮結(jié)果不佳,壓縮進(jìn)程還會(huì)揮霍系統(tǒng)資源
gzip_min_length 1000;
# 可選值1~9,壓縮級(jí)別越高壓縮率越高,但對(duì)系統(tǒng)機(jī)能要求越高
gzip_comp_level 4;
# 壓縮的內(nèi)容種別
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# 靜態(tài)文件緩存
# 最大緩存數(shù)量,文件未利用存活期
open_file_cache max=655350 inactive=20s;
# 驗(yàn)證緩存有效期時(shí)距離斷
open_file_cache_valid 30s;
# 有效期內(nèi)文件最少利用次數(shù)
open_file_cache_min_uses 2;
upstream web_app {
server 192.168.0.4:8080 weight=1;
server 192.168.0.4:8081 weight=2;
}
upstream web_test {
server 192.168.0.4:8081 ;
}
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm index.jsp index.do;;
# proxy_pass http://web_app;
#}
#設(shè)置Nginx消息疏散,界說(shuō)的靜態(tài)頁(yè)面直接從Nginx宣布目次讀取。
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root html;
#expires界說(shuō)用戶欣賞器緩存的時(shí)間為7天,假如靜態(tài)頁(yè)面不常更新,可以配置更長(zhǎng),這樣可以節(jié)減帶寬緩和解處事器的壓力
expires 7d;
}
location /test {
deny all;
}
location /web {
proxy_pass http://web_test;
}
#所有jsp、do的動(dòng)態(tài)請(qǐng)求都交給后頭的tomcat處理懲罰 location ~ (\.jsp)|(\.do)$
location /
{
#tomcat地點(diǎn)
proxy_pass http://web_app;
# 請(qǐng)求頭中Host信息
proxy_set_header HOST $host;
# 真實(shí)的客戶端IP
proxy_set_header X-Real-IP $remote_addr;
# 署理路由信息,此處取IP有安詳隱患
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 真實(shí)的用戶會(huì)見(jiàn)協(xié)議
proxy_set_header X-Forwarded-Proto $scheme;
# 默認(rèn)值default,
# 后端response 302時(shí) tomcat header中l(wèi)ocation的host是http://192.168.1.62:8080
# 因?yàn)閠omcat收到的請(qǐng)求是nginx發(fā)已往的, nginx提倡的請(qǐng)求url host是http://192.168.1.62:8080
# 配置為default后,nginx自動(dòng)把響應(yīng)頭中l(wèi)ocation host部門替換成當(dāng)前用戶請(qǐng)求的host部門
# 網(wǎng)上許多教程將此值配置成 off,禁用了替換,
# 這樣用戶欣賞器收到302后跳到http://192.168.1.62:8080,直接將后端處事器袒露給欣賞器
# 所以除非非凡需要,不要配置這種多此一舉的設(shè)置
proxy_redirect default;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#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;
# }
#}
}