Nginx-tomcat負載均衡配置

  1. 版本:Nginx 1.12.2窄赋,tomcat 8.5.24
    分別下載解壓,tomcat解壓兩份
  2. 配置tomcat端口
    slave1:8005 => 8015,8080 => 8087,8009 => 8019
    slave2:8005 => 8025,8080 => 8088,8009 => 8029
  3. 配置nginx.conf
    • http添加upstream


      image.png
    • server添加proxy_pass


      image.png
  4. 啟動Nginx
    命令行:start nginx
    訪問:localhost
    可以修改負載的策略,參考:Nginx負載均衡策略
  5. nginx.xonf
#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 {

    upstream balances {
        server localhost:8088;
        server localhost:8087;
    }

    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;

    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://balances;
        }

        #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;
    #    }
    #}

}
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末审姓,一起剝皮案震驚了整個濱河市滞乙,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌肠鲫,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,490評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件或粮,死亡現(xiàn)場離奇詭異导饲,居然都是意外死亡,警方通過查閱死者的電腦和手機氯材,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評論 3 395
  • 文/潘曉璐 我一進店門渣锦,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人氢哮,你說我怎么就攤上這事袋毙。” “怎么了冗尤?”我有些...
    開封第一講書人閱讀 165,830評論 0 356
  • 文/不壞的土叔 我叫張陵听盖,是天一觀的道長。 經(jīng)常有香客問我裂七,道長皆看,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,957評論 1 295
  • 正文 為了忘掉前任背零,我火速辦了婚禮腰吟,結果婚禮上,老公的妹妹穿的比我還像新娘徙瓶。我一直安慰自己毛雇,他們只是感情好嫉称,可當我...
    茶點故事閱讀 67,974評論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著灵疮,像睡著了一般织阅。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上始藕,一...
    開封第一講書人閱讀 51,754評論 1 307
  • 那天蒲稳,我揣著相機與錄音,去河邊找鬼伍派。 笑死江耀,一個胖子當著我的面吹牛,可吹牛的內容都是我干的诉植。 我是一名探鬼主播祥国,決...
    沈念sama閱讀 40,464評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼晾腔!你這毒婦竟也來了舌稀?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤灼擂,失蹤者是張志新(化名)和其女友劉穎壁查,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體剔应,經(jīng)...
    沈念sama閱讀 45,847評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡睡腿,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,995評論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了峻贮。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片席怪。...
    茶點故事閱讀 40,137評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖纤控,靈堂內的尸體忽然破棺而出挂捻,到底是詐尸還是另有隱情,我是刑警寧澤船万,帶...
    沈念sama閱讀 35,819評論 5 346
  • 正文 年R本政府宣布刻撒,位于F島的核電站,受9級特大地震影響耿导,放射性物質發(fā)生泄漏声怔。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,482評論 3 331
  • 文/蒙蒙 一碎节、第九天 我趴在偏房一處隱蔽的房頂上張望捧搞。 院中可真熱鬧抵卫,春花似錦狮荔、人聲如沸胎撇。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,023評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽晚树。三九已至,卻和暖如春雅采,著一層夾襖步出監(jiān)牢的瞬間爵憎,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,149評論 1 272
  • 我被黑心中介騙來泰國打工婚瓜, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留宝鼓,地道東北人。 一個月前我還...
    沈念sama閱讀 48,409評論 3 373
  • 正文 我出身青樓巴刻,卻偏偏與公主長得像愚铡,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子胡陪,可洞房花燭夜當晚...
    茶點故事閱讀 45,086評論 2 355

推薦閱讀更多精彩內容