欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

nginx實現(xiàn)多geoserver服務的負載均衡的示例代碼

 更新時間:2022年05月13日 14:23:07   作者:牛老師講GIS  
本文主要介紹了nginx實現(xiàn)多geoserver服務的負載均衡的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

概述

為了提高服務的訪問速度,減輕geoserver服務的壓力,同時避免服務節(jié)點出現(xiàn)問題而影響服務訪問的穩(wěn)定性,我們通常會通過部署多個geoserver來解決,但是部署了多個geoserver后,我們需要一個統(tǒng)一的接口提供出來供使用,nginx很好地可以這樣的需求,本文講講如何通過nginx實現(xiàn)多geoserver服務的負載均衡。

實現(xiàn)效果

實現(xiàn)

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. 前端調(diào)用

根據(jù)上述的配置,nginx的端口為80,因此geoserver的地址為http://localhost/geoserver,在ol中的調(diào)用代碼如下:

<!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: 'http://localhost/geoserver/mapbox/wms',
? ? ? params: {'LAYERS': 'mapbox:city', 'TILED': true},
? ? ? serverType: 'geoserver',
? ? ? transition: 0
? ? })
? })

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

到此這篇關于nginx實現(xiàn)多geoserver服務的負載均衡的示例代碼的文章就介紹到這了,更多相關nginx 多geoserver負載均衡內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • nginx實現(xiàn)動靜分離的示例代碼

    nginx實現(xiàn)動靜分離的示例代碼

    這篇文章主要介紹了nginx實現(xiàn)動靜分離的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-12-12
  • Nginx listen 監(jiān)聽端口的實現(xiàn)配置

    Nginx listen 監(jiān)聽端口的實現(xiàn)配置

    本文將介紹Nginx的listen指令及其在配置文件中的應用,通過了解listen指令,我們可以知道Nginx如何監(jiān)聽端口,并配置相應的服務器塊來處理進入的請求
    2023-12-12
  • Nginx服務器作反向代理實現(xiàn)內(nèi)部局域網(wǎng)的url轉(zhuǎn)發(fā)配置

    Nginx服務器作反向代理實現(xiàn)內(nèi)部局域網(wǎng)的url轉(zhuǎn)發(fā)配置

    這篇文章主要介紹了Nginx服務器作反向代理實現(xiàn)內(nèi)部局域網(wǎng)的url轉(zhuǎn)發(fā)實例,文中提到需要注意proxy_read_timeout參數(shù)的相關調(diào)整,需要的朋友可以參考下
    2016-01-01
  • centos7系統(tǒng)下nginx安裝并配置開機自啟動操作

    centos7系統(tǒng)下nginx安裝并配置開機自啟動操作

    這篇文章主要介紹了centos7系統(tǒng)下nginx安裝并配置開機自啟動操作方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • nginx代理返回代碼499問題分析與處理

    nginx代理返回代碼499問題分析與處理

    我們通過nginx作為互聯(lián)網(wǎng)代理服務器,通過它實現(xiàn)我行內(nèi)部系統(tǒng)向互聯(lián)網(wǎng)系統(tǒng)的接口訪問及調(diào)用,但是在使用過程中,不時的會出現(xiàn)大量返回代碼為499的問題,所以本文我們對為什么nginx會返回499錯誤代碼展開分析和研究
    2023-06-06
  • Nginx報錯104:Connection?reset?by?peer問題的解決及分析

    Nginx報錯104:Connection?reset?by?peer問題的解決及分析

    最近恰好又遇到這了個錯誤,為了加深記憶,所以記錄下我遇到這個錯誤的主要原因,下面這篇文章主要給大家介紹了關于Nginx報錯104:Connection?reset?by?peer問題的解決及分析的相關資料,需要的朋友可以參考下
    2022-07-07
  • nginx全局變量整理小結

    nginx全局變量整理小結

    nginx全局變量整理小結,方便需要的朋友
    2012-11-11
  • Nginx的安裝和多域名配置的實現(xiàn)方法

    Nginx的安裝和多域名配置的實現(xiàn)方法

    這篇文章主要介紹了Nginx的安裝和多域名配置的實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • nginx出現(xiàn)權限問題解決(13: Permission denied)

    nginx出現(xiàn)權限問題解決(13: Permission denied)

    本文主要介紹了nginx出現(xiàn)權限問題解決(13: Permission denied),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-06-06
  • Nginx安裝及具體應用小結

    Nginx安裝及具體應用小結

    Nginx 動靜分離簡單來說就是把動態(tài)請求跟靜態(tài)請求分開,Nginx 處理靜態(tài)請求,Tomcat處理動態(tài)請求,這篇文章主要介紹了Nginx安裝及具體應用小結,需要的朋友可以參考下
    2024-02-02

最新評論