nginx使用/etc/hosts重定向



我对做一些奇怪的事情感到困惑和问题。我有申请,我们在http://somehost:9000/endpoint/x上发送请求。在/etc/hosts中,我们的应用程序在哪里运行,我们得到了123.123.123.123:somehost映射。但在我们的生产环境中,我们不能接触主机文件。所以我们在nginx上创建了代理。那么,有没有可能请求到nginx(http://nginx:80/endpoint/x(中,他会在里面进行主机映射?额外的事情是,我们必须从应用程序发送的请求中添加.p12证书(它可以直接复制到nginx目录(和body+HTTP头。我认为主机映射的部分主要让我感到困惑——我不知道如何制作。

server {
listen              80;
location / {
proxy_pass http://somehost:9000;
}
}

这是一个关于示例代理的想法,但如何从给定的主机进行主机映射?谢谢

您不能在服务器上使用/etc/hosts,但可以使用nginx上游模块。像这个

upstream somehost {
server 123.123.123.123:9000;
}
server {
...
location / {
proxy_pass http://somehost;
}
}

最新更新