我在本機(jī)裝了3個(gè)虛擬機(jī),
3個(gè)虛擬機(jī)都陳設(shè)了溝通的項(xiàng)目
地點(diǎn)別離為
192.168.20.133:8080
192.168.20.135:8080
192.168.20.136:8080
ngxin安裝在133上,directadmin安裝 directadmin漢化, 集群設(shè)置如下:
因?yàn)槲?35 136 的權(quán)重為2, 133的權(quán)重為1 ,
我開(kāi)著3個(gè)日志, 每次會(huì)見(jiàn)到哪個(gè)呆板,日志會(huì)有轉(zhuǎn)動(dòng)來(lái)確定會(huì)見(jiàn)到哪臺(tái)虛擬機(jī)了
一般順序?yàn)?135 136 135 136 133 135 136 135 136 133 135 136 135 136 133 但也不停對(duì)
我把136的tomcat遏制之后, 133 和135可以或許繼承提供處事,擔(dān)保一臺(tái)處事器掛掉之后其他處事器繼承事情。
/usr/nginxStaticFile 目次下 的靜態(tài)文件, 等同于 tomcat/webapps/projectname 里的靜態(tài)文件
location ~.(gif|jpg|jpeg|png|css|js)$ {
root /usr/nginxStaticFile;
expires 2h;
}
所有設(shè)置:
#user nobody;
worker_processes 1;
error_log /usr/nginxLog/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid /usr/nginxLog/nginx.pid;
events {
worker_connections 1024;
}
http {
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;
access_log /usr/nginxLog/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#upstream作負(fù)載平衡,在此設(shè)置需要輪詢(xún)的處事器地點(diǎn)和端標(biāo)語(yǔ),max_fails為答允請(qǐng)求失敗的次數(shù),默認(rèn)為1.
#weight為輪詢(xún)權(quán)重,按照差異的權(quán)重分派可以用來(lái)均衡處事器的會(huì)見(jiàn)率。
upstream hostname {
server 192.168.20.133:8080 max_fails=0 weight=1;
server 192.168.20.135:8080 max_fails=0 weight=2;
server 192.168.20.136:8080 max_fails=0 weight=2;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
proxy_pass http://hostname;
proxy_set_header X-Real-IP $remote_addr;
}
location ~.(gif|jpg|jpeg|png|css|js)$ {
root /usr/nginxStaticFile;
expires 2h;
}
#啟用nginx status 監(jiān)聽(tīng)頁(yè)面
location /nginxstatus {
stub_status on;
access_log on;
}
#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;
# }
#}
}