如何建立一個可以傳遞所有網域的所有流量的 nginx 反向代理?

如何建立一個可以傳遞所有網域的所有流量的 nginx 反向代理?

我想讓它能夠通過全部無論主機名稱或網域如何,流量都會通過 nginx 伺服器。

我要么希望能夠做這樣的事情:http://mynginx/domain.I.want.somehost/url/params/this/host。然後讓nginx將請求轉送到http://domain.I.want.somehost/url/params/this/host.

或者可以存取伺服器並指定主機標頭。因此,http://mynginx/url/params/this/host將 HOST 標頭設為 的請求domain.I.want.somehost會將流量轉送至http://domain.I.want.somehost/url/params/this/host

我很難找到如何做到這一點的例子。

在進行任何 URL 重寫之前,我嘗試像這樣傳遞所有流量:

server {
     listen  80 default_server;
     listen  443 default_server;

        location / {
           proxy_pass https://$http_host;
           proxy_set_header Host $http_host;
        }

}

當我運行時,curl --header 'Host: api.ipify.org' 127.0.0.1我收到 502 bad gateway 錯誤。

但是可以存取此端點:curl 'https://api.ipify.org?format=json'

相關內容