目錄
概述
實作效果
實作
1. 多geoserver部署
2. nginx配置
3. 前端呼叫
首頁 運維 Nginx nginx怎麼實現多geoserver服務的負載平衡

nginx怎麼實現多geoserver服務的負載平衡

May 17, 2023 am 11:04 AM
nginx geoserver

概述

為了提高服務的存取速度,減輕geoserver服務的壓力,同時避免服務節點出現問題而影響服務存取的穩定性,我們通常會透過部署多個geoserver來解決,但部署了多個geoserver後,我們需要一個統一的介面提供出來供使用,nginx很好地可以這樣的需求,本文講講如何透過nginx實現多geoserver服務的負載平衡。

實作效果

nginx怎麼實現多geoserver服務的負載平衡

實作

1. 多geoserver部署

為了保持geoserver的服務一致,我們先配置一個geoserver服務,配置好之後將部署的Tomcat複製,克隆多個出來,本文為演示複製了兩個(共三個geoserver),修改Tomcat的端口,使三個端口不衝突,複製好之後分別啟動三個Tomcat。

2. nginx配置

修改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;
    
    # 反向代理配置
    upstream server_list{
       # 这个是tomcat的访问路径
       server localhost:8081;
       server localhost:8082;
       server localhost:8083;
    }
    server {
        listen       80;
        server_name  localhost;
     
        location / {
            add_header 'Access-Control-Allow-Origin' $http_origin;
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain; charset=utf-8';
                add_header 'Content-Length' 0;
                return 204;
            }
            root   html;
            proxy_pass http://server_list;
            index  index.html index.htm;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
登入後複製

設定好nginx後,啟動nginx。

3. 前端呼叫

根據上述的配置,nginx的連接埠為80,因此geoserver的位址為http://localhost/geoserver,在ol中的呼叫程式碼如下:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>OpenLayers map preview</title>
  <link rel="stylesheet" href="lib/ol/ol.css" rel="external nofollow"  type="text/css">
  <link rel="stylesheet" href="css/common.css" rel="external nofollow" >
  <script src="../ol5/ol.js" type="text/javascript"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
  const options = {
    center: [52102781.07568731, 4456849.777083951],
    zoom: 3,
    minZoom: 0,
    maxZoom: 18
  }

  const base = new ol.layer.Tile({
    visible: true,
    source: new ol.source.OSM()
  });
  const wms = new ol.layer.Tile({
    source: new ol.source.TileWMS({
      url: &#39;http://localhost/geoserver/mapbox/wms&#39;,
      params: {&#39;LAYERS&#39;: &#39;mapbox:city&#39;, &#39;TILED&#39;: true},
      serverType: &#39;geoserver&#39;,
      transition: 0
    })
  })

  window.map = new ol.Map({
    controls: ol.control.defaults({
      attribution: false
    }).extend([new ol.control.ScaleLine()]),
    target: &#39;map&#39;,
    layers: [base, wms],
    view: new ol.View({
      center: options.center,
      zoom: options.zoom,
      minZoom: options.minZoom,
      maxZoom: options.maxZoom
    })
  });
</script>
</body>
</html>
登入後複製

以上是nginx怎麼實現多geoserver服務的負載平衡的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

tomcat伺服器怎麼能讓外網訪問 tomcat伺服器怎麼能讓外網訪問 Apr 21, 2024 am 07:22 AM

tomcat伺服器怎麼能讓外網訪問

nginx啟動指令和停止指令是什麼 nginx啟動指令和停止指令是什麼 Apr 02, 2024 pm 08:45 PM

nginx啟動指令和停止指令是什麼

thinkphp怎麼運行 thinkphp怎麼運行 Apr 09, 2024 pm 05:39 PM

thinkphp怎麼運行

Welcome to nginx!怎麼解決? Welcome to nginx!怎麼解決? Apr 17, 2024 am 05:12 AM

Welcome to nginx!怎麼解決?

nodejs專案怎麼部署到伺服器 nodejs專案怎麼部署到伺服器 Apr 21, 2024 am 04:40 AM

nodejs專案怎麼部署到伺服器

phpmyadmin怎麼註冊 phpmyadmin怎麼註冊 Apr 07, 2024 pm 02:45 PM

phpmyadmin怎麼註冊

造訪網站出現nginx怎麼解決 造訪網站出現nginx怎麼解決 Apr 02, 2024 pm 08:39 PM

造訪網站出現nginx怎麼解決

docker容器之間如何通信 docker容器之間如何通信 Apr 07, 2024 pm 06:24 PM

docker容器之間如何通信

See all articles