国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > Nginx > 正文

nginx+tomcat實現(xiàn)Windows系統(tǒng)下的負載均衡搭建教程

2024-08-30 12:23:18
字體:
供稿:網(wǎng)友
下面小編就為大家分享一篇nginx+tomcat實現(xiàn)Windows系統(tǒng)下的負載均衡搭建教程,具有很好的參考價值,希望對大家有所幫助

剛?cè)胄袥]多久就聽過‘負載均衡'的大名,到現(xiàn)在因為工作接觸的少,所以沒什么太多的認識。但自己又對其非常的好奇,所以前兩天通過查資料,在自己的筆記本上就搭建了一個超簡單的案例(工作中沒有時間,晚上到家了條件又不夠,只能用自己的筆記本將就一下了,重在理解思想。。)

通俗點將,負載均衡就是因為訪問流量太大,導致項目訪問不流暢、甚至宕掉,所以通過一種分流的方式來緩解這種情況。

首先,安裝兩個tomcat,可以是同一個復制成兩個,也可以下載兩個不同版本的tomcat,我就是下載了兩個不同版本的。下載地址:https://tomcat.apache.org/download-80.cgi

(這是8.0版本的,隨便找兩個不是特別老的版本的就行)。

然后啟動兩個tomcat,在啟動前,先更改其中一個的端口號,使得兩個tomcat啟動時不會端口沖突,一個是本身的8080端口,一個是改成了9080端口。配好以后,打開cmd命令窗口,我的tomcat一個放在D:/software/apache-tomcat-8.5.24目錄下,按照如下命令即可啟動,啟動成功會彈出另一個窗口,顯示如下:

打開瀏覽器,輸入http://localhost:9080/,出現(xiàn)如下界面即tomcat啟動成功。另一個采用同樣的步驟即可。

圖1:tomcat8     圖2:tomcat7

再之后,安裝一個nginx,我裝的是穩(wěn)定版的nginx,下載地址:http://nginx.org/download/nginx-1.12.2.zip,解壓即可使用

在啟動前,必須要對nginx進行一下配置才可實現(xiàn)負載均衡的功能,打開conf文件夾,下面有一個nginx.conf文件,配置如下:

#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/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;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;gzip on;

#以下四行是新添加的,兩個IP是兩個tomcat的訪問地址,weight表示分給該服務(wù)器的請求比重,兩個都是1,則按照1:1來分配,

upstream netitcast.com{server 127.0.0.1:8080 weight=1;server 127.0.0.1:9080 weight=2;}server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;

#一下兩行是進行修改的,http://netitcast.com和上面添加的要保持一致

location / {proxy_pass http://netitcast.com; proxy_redirect default; }#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;# }#}}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 河池市| 蛟河市| 米泉市| 唐海县| 黄大仙区| 二连浩特市| 彰武县| 福建省| 施甸县| 手游| 滨州市| 左云县| 高清| 吉林省| 明溪县| 临潭县| 志丹县| 柏乡县| 北碚区| 扶沟县| 江源县| 新余市| 商洛市| 方正县| 昌乐县| 班戈县| 清丰县| 桐梓县| 平凉市| 云林县| 深水埗区| 仪陇县| 柳州市| 韶山市| 佳木斯市| 全椒县| 安仁县| 中方县| 古蔺县| 泾阳县| 闻喜县|