如何使控制台只能從子網域和連接埠存取?

如何使控制台只能從子網域和連接埠存取?

目前,在我的配置中,我已經設定了一個網域example.com來連接到網站。然後control.example.com透過 2054 連接埠連接到控制面板。因此,要存取控制面板,請執行以下操作https://control.example.com:2054:但是,由於某種原因,我也可以透過https://example.com:2054不使用子網域來存取控制面板。

有沒有辦法防止這種情況發生,只能做https://control.example.com:2054/在預防的同時https://example.com:2054/從訪問?

答案1

有沒有辦法防止這種情況發生,只能做https://control.example.com:2054/在預防的同時https://example.com:2054/從訪問?

是的。最簡單的方法可能是使用 Nginx 作為反向代理。可以找到以這種方式使用 Nginx 的基本概述這裡

簡而言之,您需要設定兩個類似於以下內容的伺服器區塊:

# Block access to example.com:2054, assuming Nginx is servicing that port.
#
server {
    listen       2054;
    server_name  example.com;

    # 404 - Not Found is returned, but 403 - Forbidden is another option
    location / {
        return 404;
    }
}

# another (unblocked) virtual host on the same port e.g. control.example.com:2054
#
server {
    listen       2054;
    server_name  control.example.com;

    # Proxy our web data
    location / {
    proxy_pass      http://10.0.0.10:3005;
    }
}

此範例假設正在使用兩個不同的端口,因為此設定很容易處理。應轉發您想要公開存取服務的端口,而不應轉發內部(實際)服務端口。 IP proxy_pass(顯然)應該是運行您想要存取的服務的 PC 的 IP。

如果上述解決方案不適合您,請注意,您可以使用以下方法執行某些操作iptables或類似的。

相關內容