beatone
Goto Top

Reverse Proxy Subdomain

Hallo,

ich habe einen Server Zuhause stehen und eine Domain bei Strato gekauft.

Auf dem Server laufen mehrer virtuelle Server. Unter anderem Nextcloud etc.

Meine Frage ist jetzt wie ich verschiedene Server durch verschiedene Subdomains erreichen kann.

z.B. soll nextcoud.domain.de auf 192.168.178.222 intern und server.domain.de auf 192.168.178.223 intern.

Die secondlevel Domain bekommt ihre IP über dyndns von meiner Fritzbox.
Wie muss ich das bei den Subdomains einstellen? Ich kann bei der Fritzbox ja nur eine Domain durch dyndns updaten...

Habe mir schon Videos auf YouTube angesehen z.B. "Reverse Proxy konfigurieren" von Apfelcast. Das bekomme ich alles hin was er da tut. Aber wie mach ich das mit den Subdomains? Wie kann ich denen auch meine IP geben? Statisch geht das leider nicht da ich ja eine Dynamisch IP vom Provider bekomme.

Danke schon mal für Hilfe face-smile

Content-Key: 560852

Url: https://administrator.de/contentid/560852

Printed on: April 18, 2024 at 16:04 o'clock

Mitglied: 143127
143127 Mar 26, 2020 updated at 07:33:01 (UTC)
Goto Top
Jeweils statt einem A-Record einen CNAME Eintrag für die Sudomain im DNS anlegen der auf den FQDN zeigt welchen du per DynDns aktualisierst.
Intern dann einfach per Reverse-Proxy die Subdomains verteilen.
Member: maddig
maddig Mar 26, 2020 at 07:15:23 (UTC)
Goto Top
Gude,

am einfachsten ein Debian mit NGINX aufsetzen und den NGINX Reverse Proxy spielen lassen.
Damit gehen natürlich nur HTTP Inhalte. Mit entsprechenden Modulen kannst du als schöner Nebeneffekt z.B. auch OpenVPN umleiten.

Praktisch erstellst du für jede Anwendung einen neuen Virtual Host.
Hier z.B. mal meine Nextcloud Config für NGINX:

upstream php-handler {
    #server 127.0.0.1:9000;
    server unix:/var/run/php/php7.2-fpm.sock;
}

server {
    listen 80;
    server_name asdfasdf.de;
    # enforce https
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name adsfsdfg.de;

	ssl_certificate /etc/letsencrypt/live/.de-0001/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/.de-0001/privkey.pem;

    # Add headers to serve security related headers
    # Before enabling Strict-Transport-Security headers please read into this
    # topic first.
    # add_header Strict-Transport-Security "max-age=15768000; 
    # includeSubDomains; preload;"; 
    #
    # WARNING: Only add the preload option once you read about
    # the consequences in https://hstspreload.org/. This option
    # will add the domain to a hardcoded list that is shipped
    # in all major browsers and getting removed from this list
    # could take several months.
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";  
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;

    # Path to the root of your installation
    root /var/www/cloud/nextcloud/;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you're planning to use this app.  
    #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
    # last;

    location = /.well-known/carddav {
      return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
      return 301 $scheme://$host/remote.php/dav;
    }

    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    # Enable gzip but do not remove ETag headers
    gzip on;
    gzip_vary on;
    gzip_comp_level 4;
    gzip_min_length 256;
    gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
    gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;

    location / {
        rewrite ^ /index.php$uri;
    }

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        deny all;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        #Avoid sending the security headers twice
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
    }

    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri/ =404;
        index index.php;
    }

    # Adding the cache control header for js and css files
    # Make sure it is BELOW the PHP block
    location ~ \.(?:css|js|woff|svg|gif)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=15778463";  
        # Add headers to serve security related headers (It is intended to
        # have those duplicated to the ones above)
        # Before enabling Strict-Transport-Security headers please read into
        # this topic first.
        # add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";  
        #
        # WARNING: Only add the preload option once you read about
        # the consequences in https://hstspreload.org/. This option
        # will add the domain to a hardcoded list that is shipped
        # in all major browsers and getting removed from this list
        # could take several months.
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";  
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        # Optional: Don't log access to assets  
        access_log off;
    }

    location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        # Optional: Don't log access to other assets  
        access_log off;
    }
}

Eine "normale einfache" Reverse Proxy Config findest du zu genüge im Internet.

Zusätzlich würde ich noch ddclient auf dem Server aufsetzen, mit dem du dann alle deine Subdomains und die Domain mit DynDNS aktuell hällst.
Bei "server_name" kommt dann quasi immer deine Domain rein, mit der du den Server anspricht. NGINX checkt das dann und holt dir deinen Inhalt den du konfiguriert hast auf deinem LAN.

mfg
maddig
Member: BeatOne
BeatOne Mar 26, 2020 at 07:39:19 (UTC)
Goto Top
Funktioniert so etwas dann nur für http und https oder kann ich dahinter z.B. auch einen TeamSpeak-Server setzten?
Ein TS-Server will ja ein paar mehr Ports freigegeben haben...
Member: maddig
maddig Mar 26, 2020 at 07:44:26 (UTC)
Goto Top
Nur HTTP Traffic und wie gesagt, du kannst auch OpenVPN separieren.

Für TS brächtest du nen SRV-Record und TSDNS. Sollte auch funktionieren. Den TS könntest du zb auch NATen.

Aber über alle weiteren Anforderungen kommst du um statische IP´s nicht herum. Was zurzeit ziemlich schwierig sein wird, weil jeder Provider energisch die Verwendung der Adressen wissen will. Als Privatperson sowie relativ schwierig.

mfg maddig
Mitglied: 142962
142962 Mar 26, 2020 updated at 10:59:17 (UTC)
Goto Top
Ich setze dafür nginx-proxy-manager

https://nginxproxymanager.com/screenshots/
https://github.com/jc21/nginx-proxy-manager

einfach zu verwalten und auch gleich die möglichtkeit ein LetsEntryp Certifikat für die Domain zu generierendie Verwaltung läuft über WebInterface gut zu bedienenund selbsterklärend läuft bei mir auf einem Raspberry mit Docker

Subdomain kann man es so lösen

server1.domain.de --- > CNAME auf dyndns Domain von der Fritzbox
server2.domain.de --- > CNAME auf dyndns Domain von der Fritzbox usw.

die domains dann im NGINX eintragen und Fertig ist die Suppe

ich setze es so um *.wildcard domain per CNAME auf die domain bei Strato wegen dyndns und trage dann blos die domains bei NGINX ein mit dem ziel. Die nicht vorhanden subdomains leite ich im Proxy um auf eine fehlerseite um.
Member: Spirit-of-Eli
Spirit-of-Eli Mar 26, 2020 at 09:22:46 (UTC)
Goto Top
Zitat von @BeatOne:

Funktioniert so etwas dann nur für http und https oder kann ich dahinter z.B. auch einen TeamSpeak-Server setzten?
Ein TS-Server will ja ein paar mehr Ports freigegeben haben...

Teamspeak macht das ganze noch simpler und kann über die Domäne den Port gleich mit abfragen. Dafür brauchst du keinen Reverse Proxy.
Stichwort "SRV-Record".
Member: Daniko
Daniko Jan 19, 2022 at 13:13:19 (UTC)
Goto Top
Zitat von @142962:


ich setze es so um *.wildcard domain per CNAME auf die domain bei Strato wegen dyndns und trage dann blos die domains bei NGINX ein mit dem ziel. Die nicht vorhanden subdomains leite ich im Proxy um auf eine fehlerseite um.

Das ist ja intressant. Ich hab leider nicht ganz nachvollzihen können.
kannst du bit nochmal erklären was du genau wo eingetragen hast.

welches die cmane Adresse ist und wo der A-record eingetragen ist.
Das wäre wirklich super.
Danke