我在Docker容器中有两项服务(WMS和WFS)。 我想将nginx用作网关,并且具有如下所示的配置-现在无法正常工作。
我应该使用set $upstream backend_server
还是proxy_pass baskend_server
?
如何为以下情况进行工作配置?
第一种情况
网关URL
http://project_test.local/wms?
SERVICE=WMS&
REQUEST=GetCapabilities&
VERSION=1.3.0
URL代理
http://wms_server:8080/project_test/service?
SERVICE=WMS&
REQUEST=GetCapabilities&
VERSION=1.3.0
第二种情况
网关URL
http://project_test.local/wfs?
SERVICE=WFS&
REQUEST=GetCapabilities&
VERSION=2.0.0
URL代理
http://wfs_server:8080/ows?
MAP=project_test&
SERVICE=WFS&
REQUEST=GetCapabilities&
VERSION=2.0.0
backends.conf
upstream server_wms {
server wms_server:8080;
}
upstream server_wfs {
server wfs_server:8080;
}
proxy.conf
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
project_test.conf
server {
listen 0.0.0.0:8080;
server_name project_test.local;
access_log /var/logs/nginx/project_test_access.log;
error_log /var/logs/nginx/project_test_error.log;
location /wms {
include proxy.conf
proxy_pass http://wms_server:8080;
proxy_redirect off;
rewrite ^/service$request_uri /wms$request_uri
}
location /wfs {
set $upstream server_wfs;
rewrite ^/ows/?MAP=project_test$request_uri /project_test/wfs last;
}
}