Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    pfSense & HAProxy

    Scheduled Pinned Locked Moved Deutsch
    4 Posts 2 Posters 762 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      ThePocky
      last edited by ThePocky

      Guten Abend,

      seit einigen Tagen beschäftige ich mich mit dem Thema pfSense und HAProxy. Auf meinem dedizierten Server läuft Proxmox 6. Aus Kostengründen habe ich nur eine zusätzliche IP bei meinem Hoster bestellt. Um dennoch hinter einer einzelnen IP mehrere Dienste betreiben zu können nutze ich pfSense. Um verschiedene Dienste wie beispielsweise Plesk hinter pfSense zu betreiben mit diversen Domains bin ich auf HAProxy gestoßen. Soweit habe ich alles konfiguriert, dass das Plesk-Interface ("https://plesk.MEINE-DOMAIN.de") (via Port 8443, SSL, mit einem Wildcard-Zertifikat von Let's Encrypt geschützt) erreichen kann. Desweiteren habe ich es geschafft ebenfalls meine allgemeine Domain ("https://www.MEINE-DOMAIN.de") erreichbar zu machen via "HTTPS". Auch eine redirect von "HTTP" auf "HTTPS" funktioniert, mit einem ABER ...

      Wenn ich die Domain "http://www.MEINE-DOMAIN.de" aufrufe werde ich automatisch auf "https://www.MEINE-DOMAIN.de" weitergeleitet. Da ich nicht ausschließen kann, dass jemand die Domain "http://MEINE-DOMAIN.de" aufruft (also ohne WWW) sollte diese natürlich auch weitergeleitet werden auf HTTPS, dies tut es auch, allerdings erhalte ich die Meldung "503 Service Unavailable", des Weiteren wird das Zertifikat auch nicht erkannt.

      Ich hoffe, dass ich euch mein Problem einigermaßen näher bringen konnte. Leider habe ich es nicht geschafft die Konfigurationen auszulesen.

      Würde mich über einen denkanstoß freuen.

      Gruß
      Björn

      P 1 Reply Last reply Reply Quote 0
      • P
        PiBa @ThePocky
        last edited by

        @ThePocky said in pfSense & HAProxy:

        Konfigurationen auszulesen.

        The config file can be seen the bottom of the 'settings' tab.

        1 Reply Last reply Reply Quote 0
        • T
          ThePocky
          last edited by ThePocky

          Danke für den Tipp!

          Es funktioniert soweit, aber wenn anfragen an: http://www.MEINE-ERSTE-DOMAIN.de kommen, findet keine weiterleitung zu HTTPS statt. Aber bei Anfragen an http://MEINE-ERSTE-DOMAIN.de funktioniert die weiterleitung. Hat Jemand eine Idee wie man dies elegant lösen kann? Eventuell verbesserungsvorschläge für meine Konfiguration. Es sollen später noch weitere Domains folgen.

          Hier einmal meine Konfiguration.:

          # Automaticaly generated, dont edit manually.
          # Generated on: 2019-10-19 14:38
          global
          	maxconn			1000
          	stats socket /tmp/haproxy.socket level admin 
          	gid			80
          	nbproc			1
          	hard-stop-after		15m
          	chroot				/tmp/haproxy_chroot
          	daemon
          	tune.ssl.default-dh-param	2048
          	server-state-file /tmp/haproxy_server_state
          
          frontend Plesk
          	bind			XXX.XXX.XX.XX:8443 name XXX.XXX.XX.XX:8443   ssl crt-list /var/etc/haproxy/Plesk.crt_list  
          	mode			http
          	log			global
          	option			http-keep-alive
          	timeout client		30000
          	acl			plesk.MEINE-ERSTE-DOMAIN.de	var(txn.txnhost) -m str -i plesk.MEINE-ERSTE-DOMAIN.de
          	acl			aclcrt_Plesk	var(txn.txnhost) -m reg -i ^([^\.]*)\.MEINE-ERSTE-DOMAIN\.de(:([0-9]){1,5})?$
          	acl			aclcrt_Plesk	var(txn.txnhost) -m reg -i ^MEINE-ERSTE-DOMAIN\.de(:([0-9]){1,5})?$
          	http-request set-var(txn.txnhost) hdr(host)
          	use_backend plesk.MEINE-ERSTE_DOMAIN.de_ipv4  if  plesk.MEINE-ERSTE-DOMAIN.de aclcrt_Plesk
          	use_backend plesk.MEINE-ERSTE_DOMAIN.de_ipv4  if   aclcrt_Plesk
          
          frontend http-to-https
          	bind			XXX.XXX.XX.XX:80 name XXX.XXX.XX.XX:80   
          	mode			http
          	log			global
          	option			http-keep-alive
          	timeout client		30000
          	http-request redirect scheme https 
          
          frontend SharedFrontend-merged
          	bind			XXX.XXX.XX.XX:443 name XXX.XXX.XX.XX:443   ssl crt-list /var/etc/haproxy/SharedFrontend.crt_list  
          	mode			http
          	log			global
          	option			http-keep-alive
          	timeout client		30000
          	acl			aclcrt_SharedFrontend	var(txn.txnhost) -m reg -i ^([^\.]*)\.MEINE-ERSTE-DOMAIN\.de(:([0-9]){1,5})?$
          	acl			aclcrt_SharedFrontend	var(txn.txnhost) -m reg -i ^MEINE-ERSTE-DOMAIN\.de(:([0-9]){1,5})?$
          	acl			MEINE-ERSTE-DOMAIN.de	var(txn.txnpath) -m str -i MEINE-ERSTE-DOMAIN.de
          	acl			www.MEINE-ERSTE-DOMAIN.de	var(txn.txnpath) -m str -i www.MEINE-ERSTE-DOMAIN.de
          	acl			aclcrt_MEINE-ERSTE-DOMAIN.de	var(txn.txnhost) -m reg -i ^([^\.]*)\.MEINE-ERSTE-DOMAIN\.de(:([0-9]){1,5})?$
          	acl			aclcrt_MEINE-ERSTE-DOMAIN.de	var(txn.txnhost) -m reg -i ^MEINE-ERSTE-DOMAIN\.de(:([0-9]){1,5})?$
          	acl			MEINE-ZWEITE-DOMAIN.de	var(txn.txnpath) -m str -i MEINE-ZWEITE-DOMAIN.de
          	acl			www.MEINE-ZWEITE-DOMAIN.de	var(txn.txnpath) -m str -i www.MEINE-ZWEITE-DOMAIN.de
          	acl			aclcrt_MEINE-ZWEITE-DOMAIN.de	var(txn.txnhost) -m reg -i ^([^\.]*)\.MEINE-ZWEITE-DOMAIN\.de(:([0-9]){1,5})?$
          	acl			aclcrt_MEINE-ZWEITE-DOMAIN.de	var(txn.txnhost) -m reg -i ^MEINE-ZWEITE-DOMAIN\.de(:([0-9]){1,5})?$
          	http-request set-var(txn.txnhost) hdr(host)
          	http-request set-var(txn.txnpath) path
          	use_backend www.MEINE-ERSTE_DOMAIN.de_ipv4  if   aclcrt_MEINE-ERSTE-DOMAIN.de
          	use_backend www.MEINE-ZWEITE-DOMAIN.de_ipv4  if   aclcrt_MEINE-ZWEITE-DOMAIN.de
          
          backend plesk.MEINE-ERSTE_DOMAIN.de_ipv4
          	mode			http
          	id			10100
          	log			global
          	timeout connect		30000
          	timeout server		30000
          	retries			3
          	source ipv4@ usesrc clientip
          	server			plesk.MEINE-ERSTE-DOMAIN.de 192.168.1.11:8443 id 10101 ssl check inter 1000  verify none 
          
          backend www.MEINE-ERSTE_DOMAIN.de_ipv4
          	mode			http
          	id			10102
          	log			global
          	timeout connect		30000
          	timeout server		30000
          	retries			3
          	source ipv4@ usesrc clientip
          	server			www.MEINE-ERSTE-DOMAIN.de 192.168.1.11:80 id 10101 check inter 1000  
          
          backend www.MEINE-ZWEITE-DOMAIN.de_ipv4
          	mode			http
          	id			10103
          	log			global
          	timeout connect		30000
          	timeout server		30000
          	retries			3
          

          Danke im vorraus!

          Gruß
          Björn

          P 1 Reply Last reply Reply Quote 0
          • P
            PiBa @ThePocky
            last edited by

            @ThePocky said in pfSense & HAProxy:

            wenn anfragen an: http://www.MEINE-ERSTE-DOMAIN.de kommen, findet keine weiterleitung zu HTTPS statt

            This cannot be, if it is handled by the "frontend http-to-https" then everything gets a redirect back with the configuration above.
            Are you sure the domain-name is resolving to the same IP that haproxy is handling the traffic for? Or perhaps a browser-cache doing something strange.?

            p.s.
            Also i see you have defined some acl's manually, but don't really use them in a 'action' that would tell what backend to use.. Only the automatic certificate-acl's are currently performing that functionality. This is not a problem as long as both domains are using different certificates. But if you one day decide to switch to a single certificate that handles both domains, the traffic would end up on the same backend..

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.