【发布时间】:2019-07-28 08:58:26
【问题描述】:
我有两个需要相互通信的 docker 容器。一个是前端的 nginx 容器,它需要与另一个容器中的 Spring 后端通信。在 Docker 外部运行时通信工作正常,但是当我对项目进行 dockerize 时,尝试将任何请求从前端发送到后端时出现以下错误:
org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized.
来自 Spring 的 StrictHttpFirewall。
nginx.conf
load_module "modules/ngx_http_perl_module.so";
env HELIUM_LOCATION;
http {
perl_set $helium_location 'sub { return $ENV{"HELIUM_LOCATION"}; }';
server {
listen 8000;
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
client_max_body_size 10M;
location /api {
rewrite ^/api(.*) /$1 break;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Prefix /api;
proxy_pass http://$helium_location;
}
location /health {
default_type application/json;
return 200 '{"status": "UP"}';
}
location / {
try_files $uri $uri/ /index.html;
}
}
}
Spring boot 版本为 2.1,nginx 容器为 nginx:1.11.8-alpine。这在使用 Spring boot 1.5.7 时有效,那么 Spring 处理这些请求的方式是否发生了变化?
如果有任何其他信息有助于解决此问题,请告诉我,我会尽我所能为您获取。谢谢!
【问题讨论】:
标签: spring spring-boot docker nginx