我有此配置来访问地理服务器:
location /geoserver {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/geoserver/;
proxy_pass_header Set-Cookie;
proxy_redirect off;
}
}
当我访问 geoserver 网页时,一切正常,但 nginx 无法处理如下请求:
http://localhost:8080/geoserver/ows?SERVICE=WMS&access_token=4r3irW5W3DboGs…7091932%2C-5009377.085697312%2C-10018754.17139462%2C-9.313225746154785e-10
控制台中出现此错误:
GET http://localhost:8080/geoserver/ows?SERVICE=WMS&access_token=4r3irW5W3DboGs…7091932%2C-5009377.085697312%2C-10018754.17139462%2C-9.313225746154785e-10 net::ERR_CONNECTION_REFUSED
我想用 nginxhttp://localhost:8080
替换IP
更新
我删除了斜线,但有些请求无法正常工作
OPTIONS http://localhost:8080/geoserver/wms?SERVICE=WMS&REQUEST=GetCapabilities&TILED=true&VERSION=1.1.1 net::ERR_CONNECTION_REFUSED
我复制了浏览器中的 URL 并将其替换localhost:8080
为 IP,它就可以正常工作了!!!
完整配置:
upstream django {
server unix:///tmp/uwsgi.sock; # for a file socket
}
server {
listen 80;
server_name XX.XX.XX.XX;
charset utf-8;
#Max upload size
client_max_body_size 1024M; # adjust to tast
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
location /geoserver {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/geoserver;
proxy_pass_header Set-Cookie;
proxy_redirect off;
}
}
答案1
在您的问题中,您有一个前缀位置和prox_pass
带有 URI 的语句。当您需要nginx
执行别名功能时,location
值和proxy_pass
URI 应该都以 结尾,/
或者都不以 结尾,/
否则映射的 URI 格式不正确。
location /geoserver {
...
proxy_pass http://localhost:8080/geoserver;
...
}
看这个文件了解更多信息。
但是,就您而言,映射/geoserver
到/geoserver
哪个是没有意义的,因此非 URI 版本proxy_pass
就足够了,而且效率更高:
proxy_pass http://localhost:8080;