【发布时间】:2019-10-16 10:48:15
【问题描述】:
我有一个由前端和后端 Docker 容器以及另一个用于 nginx 反向代理的容器组成的场景。
目前,nginx配置将urlhttp://example.com指向前端容器,http://example.com/backend指向后端容器。
现在我需要配置 nginx,以便它也可以理解对 http://backend.example.com 的调用并将它们重定向到后端容器。
如果在 nginx 配置中使用的服务器名称是 localhost,我该如何实现?
server {
listen 80 default_server;
server_name localhost;
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
location /backend/ {
proxy_pass http://backend:3000/;
}
location / {
proxy_pass http://frontend:3000/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
我也尝试添加这个块,但它不起作用(实际上它使一切停止工作):
server {
listen 80 default_server;
server_name backend.localhost;
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
location / {
proxy_pass http://backend:3000/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
【问题讨论】:
-
试试 server_name backend.example.com
-
也没有用。
标签: nginx amazon-elastic-beanstalk