nginx代理ArcGIS服務
阿新 • • 發佈:2021-01-28
技術標籤:Nginx
nginx代理服務
需求分析:
1)微信小程式,使用arcgis api 地圖。釋出正式版有安全證書的問題,需要採用安全域名訪問,http請求和ip訪問方式,以及沒有安全證書的https將會攔截,正式版無法訪問;
2)arcgis server 服務請求,不能跳轉到域名上進行訪問
1、安全證書籤發
https:安全證書(微信小程式證書請自行申請)
pfx證書轉nginx識別證書:
生成crt證書:(證書公鑰)
openssl pkcs12 -in 4395521_www.wmgis.com.pfx -clcerts -nokeys -out ./arcserver.crt -password pass:jP06I383
rsa演算法生成金鑰 (證書私鑰)
openssl pkcs12 -in 4395521_www.wmgis.com.pfx -nocerts -nodes -out ./arcserver.rsa -password pass:jP06I383
2、http轉https
微信小程式需採用https方式進行訪問:
# 定位地址 http轉https
location / {
proxy_pass http://192.168.1.128:6080/;
}
3、ip跳轉域名訪問(重定向)
服務地址已配置成域名訪問的方式,在實際進行地圖服務訪問的時候ArcGIS Server依舊採用IP進行訪問地圖, 如下圖:
https://10.68.11.80:8081/arcgis/rest/services/XXX/MapServer/export?bbox=…
問題
:1)微信小程式:不能使用ip進行訪問,(
該地址為IP地址,請使用域名進行訪問
)解決方法
:
#arcgis服務 重定向 (IP訪問轉域名訪問)
location /arcgis/rest/services/ {
if ( $host != 'www.wmgis.com' ){
rewrite ^/(.*) https://www.wmgis.com:8081/$1 permanent;
}
proxy_pass http://192.168.1.128:6080/arcgis/rest/services/;
}
2)nginx 重定向次數過多
原因解析
:
rewrite地址:www.wmgis.com和 server_name設定的域名重複,會出現多次迴圈重複的現象;
解決方案
:
- 更該域名
- 新增if判斷(域名有限是使用,效率略低,本文采用次方法)
if ( $host != 'www.wmgis.com' ){
rewrite ^/(.*) https://www.wmgis.com:8081/$1 permanent;
}
引數解釋
:
$host
:請求資訊中的"Host",如果請求中沒有Host行,則等於設定的伺服器名;
第一次host地址為:10.68.11.80 ,經過重定向之後 host為:www.wmgis.com
4、最終配置
server {
# 監聽埠
listen 8081 ssl;
# 服務名稱
server_name www.wmgis.com 10.68.11.80;
# 安全證書
ssl_certificate ../ssl/arcserver.crt;
ssl_certificate_key ../ssl/arcserver.rsa;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 定位地址 http轉https
location / {
proxy_pass http://192.168.1.128:6080/;
}
# arcgis api 實際訪問地址
location /arcgis_api/ {
proxy_pass http://192.168.1.72:9006/;
}
# arcgis服務 重定向 (IP訪問轉域名訪問)
location /arcgis/rest/services/ {
if ( $host != 'www.wmgis.com' ){
rewrite ^/(.*) https://www.wmgis.com:8081/$1 permanent;
}
proxy_pass http://192.168.1.128:6080/arcgis/rest/services/;
}
}
宣告
1)文章來源專案實踐,存在任何疑問或問題請留言,感謝您的閱讀!
2)轉載請標明來源!