Cómo redirigir CUALQUIER sitio que no se encuentre en Hestia a otro servidor - Administrador de proxy Nginx

Cómo redirigir CUALQUIER sitio que no se encuentre en Hestia a otro servidor - Administrador de proxy Nginx

Quiero: si CUALQUIER sitio no se encuentra en (servidor Hestia 192.168.0.37), se redirige (administrador de proxy Nginx 192.168.0.36)

Dado:

  1. Servidor Hestia 192.168.0.37
  2. Administrador de proxy Nginx 192.168.0.36
  3. Sitio para pruebas testsite.com (creado en el administrador de proxy de Nginx) (Hestia no tiene ningún registro)
  4. hestia publicaciones:
#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  

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

Lo intento:

editar /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;
    }
}

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

lo intento

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/

y vea la página de (servidor Hestia 192.168.0.37) DocumentRoot /var/www/html/index.html de /etc/apache2/conf.d/192.168.0.37.conf

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>

¿Por qué, cómo solucionarlo?

Respuesta1

Esto debería ser un comentario, pero es un poco largo.

No sé qué estás preguntando aquí.

Si está terminando el SSL en el servidor nginx, entonces tiene un certificado SSL absolutamente monstruoso o tiene cada sitio configurado como un servidor separado{...} en nginx.

y ver la página de (servidor Hestia 192.168.0.37)

Sí, eso es exactamente lo que esperaría de esta configuración. Solicitaste http[s]://192.168.0.36 y obtuviste http[s]://192.168.0.36

Si desea preservar el comportamiento durantehttps://192.168.0.36(al que no se puede acceder fuera de la subred) al agregar un nuevo comportamiento para los vhosts desconocidos, necesita un registro DNS o una entrada de hosts en el proxy con un nuevo nombre y un host virtual correspondiente en Apache.

Alternativamente, dado que cualquier persona en su sano juicio no intentaría operar varios sitios con el mismo certificado, es simplemente devolver una redirección desde el servidor predeterminado en nginx.

información relacionada