如何將 Hestia 中找不到的任何網站重新導向到另一台伺服器 - Nginx 代理程式管理員

如何將 Hestia 中找不到的任何網站重新導向到另一台伺服器 - Nginx 代理程式管理員

我想要:如果在(Hestia 192.168.0.37 伺服器)中找不到任何站點,則重定向(Nginx 代理管理器 192.168.0.36)

鑑於:

  1. 赫斯提亞伺服器192.168.0.37
  2. Nginx代理管理器192.168.0.36
  3. 測試網站 testsite.com (在 Nginx 代理程式管理員中建立)(Hestia 沒有任何記錄)
  4. 赫斯提亞貼文:
#netstat -nt4ulp | grep nginx
tcp        0      0 0.0.0.0:80 LISTEN /nginx: mast 
tcp        0      0 0.0.0.0:443 LISTEN /nginx: mast 
tcp        0      0 0.0.0.0:8083 LISTEN/nginx: master  
tcp        0      0 127.0.0.1:8084 LISTEN /nginx: mast 
#netstat -nt4ulp | grep apache
tcp        0      0 192.168.0.37:8443 LISTEN /apache2     
tcp        0      0 192.168.0.37:8080 LISTEN /apache2     
tcp        0      0 127.0.0.1:8081 LISTEN /apache2  

==================================================== = =====================

我嘗試:

編輯/etc/nginx/conf.d/192.168.0.37.conf

server {
    listen 80 default_server;
    server_name _;
    
    location / {
        proxy_pass http://192.168.0.36:80;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

server {
    listen 443 ssl default_server;
    server_name _;
    
        ssl_certificate     /usr/local/hestia/ssl/certificate.crt;
        ssl_certificate_key /usr/local/hestia/ssl/certificate.key;

    
    location / {
        proxy_pass https://192.168.0.36:443;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

==================================================== = =====================

我嘗試

HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 15 Sep 2023 17:54:48 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Location: https://testsite.com/

並查看 /etc/apache2/conf.d/192.168.0.37.conf 中的(Hestia 伺服器 192.168.0.37)DocumentRoot /var/www/html/index.html 頁面

Listen 192.168.0.37:8443
Listen 192.168.0.37:8080
<VirtualHost 192.168.0.37:8080>
    ServerName 192.168.0.37
    DocumentRoot /var/www/html2/
    Alias /error/ /var/www/document_errors/

</VirtualHost>

<VirtualHost 192.168.0.37:8443>
    ServerName 192.168.0.37
    DocumentRoot /var/www/html/
    Alias /error/ /var/www/document_errors/

    SSLEngine on
    SSLVerifyClient none
    SSLCertificateFile         /usr/local/hestia/ssl/certificate.crt
    SSLCertificateKeyFile      /usr/local/hestia/ssl/certificate.key

</VirtualHost>

為什麼,怎麼解決?

答案1

這應該是一個評論,但有點長。

我不知道你在這裡問什麼。

如果您要終止 nginx 伺服器上的 SSL,那麼要么您擁有絕對巨大的 SSL 證書,要么您將每個站點配置為 nginx 中的單獨伺服器{...}。

並查看頁面(Hestia 伺服器 192.168.0.37)

是的,這正是我對這個配置的期望。您請求 http[s]://192.168.0.36 您得到 http[s]://192.168.0.36

如果您想保留該行為https://192.168.0.36(子網路以外無法存取)在為未知虛擬主機新增行為時,您需要在代理程式上使用新名稱的 DNS 記錄或主機項目,以及 apache 中對應的虛擬主機。

或者,由於任何理智的人都不會嘗試使用同一個憑證操作多個站點,因此只需從 nginx 中的預設伺服器返回重定向即可。

相關內容