nginx reverse proxy auf SSL-Host - falsches Zertifikat

Debian macht sich hervorragend als Web- und Mailserver. Schau auch in den " Tipps und Tricks"-Bereich.
Antworten
simonszu
Beiträge: 52
Registriert: 29.02.2012 09:20:06

nginx reverse proxy auf SSL-Host - falsches Zertifikat

Beitrag von simonszu » 08.04.2018 10:16:50

Hi,

folgende Situation: Ich habe in meinem Netzwerk ein Gerät mit einem Webfrontend (ein Unifi Cloud Key). Dieses Webfrontend macht zwar HTTPS, aber mit einem self-signed Zertifikat. Zusätzlich kann es kein Letsencrypt. Aus diesem Grund möchte ich die Verbindung dazu gerne über einen nginx, der auf einem Raspberry Pi läuft, und der bereits auf Letsencrypt konfiguriert ist, reverse proxyen. Dieser Nginx läuft auch schon mit 2-3 anderen reverse proxys, die aber auf einen Host verweisen, der kein SSL spricht. Hier läuft das wunderbar, nginx präsentiert sein LE-Zertifikat, und die Daten des anderen Hosts.
Problematisch ist allerdings die Verbindung zu dem Cloud Key, der von sich aus auch (und nur) HTTPS spricht. Ich habe initial einfach nur die proxy_pass Direktive auf HTTPS angepasst, aber das Resultat ist, dass der nginx tatsächlich irgendwie alles proxied, und im Endeffekt dem Client das selbstsignierte Zertifikat des eigentlich zu proxyenden Hosts präsentiert, was natürlich nicht im mindesten so elegant ist wie ein tolles LE-Zertifikat.

Für das LE-Zertifikat habe ich mit acme.sh ein Wildcard-Zertifikat für meine Domain geholt, und die URL mit dem der reverse proxy aufgerufen werden soll, ist eine subdomain dieser Wildcard-URL.

Meine vhost config sieht entsprechend so aus:

Code: Alles auswählen

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name host.XXXXX;

    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
    ssl_certificate /etc/ssl/acme/XXXXX_fullchain.pem;
    ssl_certificate_key /etc/ssl/acme/XXXXX_key.pem;
    # Full trusted chain for ocsp
    ssl_trusted_certificate /etc/ssl/acme/XXXXX_fullchain.pem;

    # OCSP Stapling
    # fetch OCSP records from URL in ssl_certificate and cache them
    # disabled for now due to long restart times of nginx
    ssl_stapling on;
    ssl_stapling_verify on;

  # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;

    access_log  /var/log/nginx/host.XXXXX_access.log;
    error_log  /var/log/nginx/host.XXXXX_error.log;

    if ($http_host != "host.XXXXX") {
      rewrite ^ http://host.XXXXX$request_uri permanent;
    }

    # CUSTOM TARGET CODE HERE

        ##################
    ## PROXY TARGET ##
    ##################
      location / {
                proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_buffering off; #This will prevent nginx from hanging when updating states and allow websockets to work
        proxy_pass https://192.168.1.244:8443;
        proxy_http_version 1.1;
        proxy_connect_timeout     240;
        proxy_send_timeout       240;
        proxy_read_timeout       240;
        proxy_max_temp_file_size 0;
                proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

      }
      location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff)$ {
        access_log off;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
        proxy_pass https://192.168.1.244:8443;
      }
        # END CUSTOM TARGET CODE

    location = /robots.txt  { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }
    #location ~ /\.          { access_log off; log_not_found off; deny all; }
    location ~ ~$           { access_log off; log_not_found off; deny all; }

    location ~ /\.ht {
        deny  all;
    }
}
Hat da jemand eine Idee?

Antworten